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

Agustin Cruz agustin.cruz at gmail.com
Tue Jul 7 01:16:05 CEST 2015


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.


More information about the Python-list mailing list