Page 1 of 1

Achieving real time grayscale image data

Posted: Thu Jul 10, 2014 9:11 am
by alok9871
Hi Friends

I have just started to work with the Raspberry Pi and the Pi Camera Module. I can operate the camera module using the Python based RaspiCam and Picamera APIs.

My Motive is to find a way to record the 8 bit grayscale intensity levels of the image in a buffer. I need this data in real-time for further processing. I tried using the above two APIs, but I couldnt find a way to do this.

Can you please suggest any suitable way to achieve this. Many Thanks.

Regards
Alok

Re: Achieving real time grayscale image data

Posted: Thu Jul 10, 2014 9:40 am
by jamesh
Checkout out the C demo code raspistillYUV. This outputs a YUV image to file, and the Y of the YUV is greyscale.

But do you want video? You could make the same changes to produce video frames of YUV, but performance will be much slower due to the larger amount sof data being transferred from GPU to the ARM.

Re: Achieving real time grayscale image data

Posted: Thu Jul 10, 2014 10:02 am
by 6by9
Adding to James' post, for the I420 format which RaspiStillYUV uses, Y (luma) always comes first as width x height 8 bit values.
You then get the two chroma planes as width/2 x height/2 8 bit values.

So on a VGA capture, you'll get a 460800 byte buffer, where the first 307200 bytes are the luma as a 640x480 8bit/pixel greyscale image. Just ignore everything after that.

Re: Achieving real time grayscale image data

Posted: Thu Jul 10, 2014 10:15 am
by mikerr
PIython PiCamera can just get the Y:

Code: Select all

camera.capture(stream, 'yuv')
# Rewind the stream for reading
stream.seek(0)
# Calculate the actual image size in the stream 
fwidth = (width + 31) // 32 * 32
fheight = (height + 15) // 16 * 16
# Load the Y (luminance) data from the stream
Y = np.fromfile(stream, dtype=np.uint8, count=fwidth*fheight).\
        reshape((fheight, fwidth))
http://picamera.readthedocs.org/en/latest/recipes2.html

Re: Achieving real time grayscale image data

Posted: Wed Aug 06, 2014 3:36 am
by alok9871
Thanks James, 6by9 and mikerr for the solution. It worked. Although I don't get the desired speed, but I'm very close.

I am having an issue in using the stream, as I am not very good with python. However I will post it as a separate question, so that a beginner like me can find the answer quickly.

@James : Thanks ..No I do not need video, I just need very rapid capture of image data in numerical format.

Re: Achieving real time grayscale image data

Posted: Wed Aug 06, 2014 8:41 am
by gagle
You can try my lib omxcam: https://github.com/gagle/raspberrypi-om ... /yuv/yuv.c

PD: it's unstable, api changes can occur.

Re: Achieving real time grayscale image data

Posted: Wed Aug 06, 2014 8:59 am
by 6by9
alok9871 wrote:Thanks James, 6by9 and mikerr for the solution. It worked. Although I don't get the desired speed, but I'm very close.

I am having an issue in using the stream, as I am not very good with python. However I will post it as a separate question, so that a beginner like me can find the answer quickly.

@James : Thanks ..No I do not need video, I just need very rapid capture of image data in numerical format.
What speed do you require? If you've requested a particular framerate then the GPU will be attempting to deliver that rate. Whether your application can keep up is another matter.