Fast capture and 2D image stacking as 3D numpy array with Python and Raspberry Pi

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Jul 7 08:49:25 CEST 2015


On 07/07/2015 00:16, Agustin Cruz wrote:
> On Monday, July 6, 2015 at 6:00:42 PM UTC-4, Mark Lawrence wrote:
>> On 06/07/2015 22:31, Agustin Cruz wrote:
>>> I'm working on a Python - Raspberry Pi project in which I need to take about 30 images per second (no movie) and stack each 2D image to a 3D array using numpy array, without saving each 2D capture as a file (because is slow).
>>>
>>> I found this Python code to take images as fast as possible, but i don't know how to stack all images fast to a 3D stack of images.
>>>
>>> import io
>>> import time
>>> import picamera
>>> #from PIL import Image
>>>
>>> def outputs():
>>>       stream = io.BytesIO()
>>>       for i in range(40):
>>>           # This returns the stream for the camera to capture to
>>>           yield stream
>>>           # Once the capture is complete, the loop continues here
>>>           # (read up on generator functions in Python to understand
>>>           # the yield statement). Here you could do some processing
>>>           # on the image...
>>>           #stream.seek(0)
>>>           #img = Image.open(stream)
>>>           # Finally, reset the stream for the next capture
>>>           stream.seek(0)
>>>           stream.truncate()
>>>
>>> with picamera.PiCamera() as camera:
>>>       camera.resolution = (640, 480)
>>>       camera.framerate = 80
>>>       time.sleep(2)
>>>       start = time.time()
>>>       camera.capture_sequence(outputs(), 'jpeg', use_video_port=True)
>>>       finish = time.time()
>>>       print('Captured 40 images at %.2ffps' % (40 / (finish - start)))
>>>
>>> Does anyone of you know how to stack the 2D images taken in this code to a 3D numpy array using Python and the Raspberry Pi camera module? Without saving each 2D capture as a file
>>>
>>> Best regards, Agustín
>>>
>>
>> http://docs.scipy.org/doc/numpy/reference/generated/numpy.dstack.html is
>> the first hit on google for "numpy 3d array stack".
>>
>> --
>> My fellow Pythonistas, ask not what our language can do for you, ask
>> what you can do for our language.
>>
>> Mark Lawrence
>
> Hi Mark,
> I know the dstack function can do the job, but i don't know how to implement it in this case.
>

Sadly I don't know how either, but if I can find the above link in 
seconds, I'm fairly certain that with a little searching you could find 
something.  Specific sites like nullege or koders might offer solutions.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Python-list mailing list