Skip to content

Instantly share code, notes, and snippets.

@sankarcheppali
Last active June 16, 2017 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sankarcheppali/a3c735f2742788fa6fb6a6666dabdc08 to your computer and use it in GitHub Desktop.
Save sankarcheppali/a3c735f2742788fa6fb6a6666dabdc08 to your computer and use it in GitHub Desktop.
import io
import picamera
import cv2
import numpy
#Create a memory stream so photos doesn't need to be saved in a file
stream = io.BytesIO()
#Get the picture (low resolution, so it should be quite fast)
#Here you can also specify other parameters (e.g.:rotate the image)
with picamera.PiCamera() as camera:
camera.resolution = (320, 240)
camera.capture(stream, format='jpeg')
#Convert the picture into a numpy array
buff = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8)
#Now creates an OpenCV image
img = cv2.imdecode(buff, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment