RPi 2B python opencv camera demo example

时间:2021-07-14 09:29:00
/**************************************************************************************
* RPi 2B python opencv camera demo example
* 声明:
* 本文主要记录RPi 2B 使用python opencv来获取图片的方式。
*
* 2016-2-24 深圳 南山平山村 曾剑锋
************************************************************************************/ 一、参考文档:
. OpenCV with Raspberry Pi Camera Face Detection Tutorial - Robotics with Python Raspberry Pi and GoPiGo p.
https://pythonprogramming.net/raspberry-pi-camera-opencv-face-detection-tutorial/
. Raspberry Pi OpenCV,在树莓派下使用opencv
http://www.educity.cn/wenda/565761.html
3. 如何安装树莓派摄像头模块
https://linux.cn/article-3650-1.html 二、opencv install:
  sudo apt-get update && sudo apt-get install libopencv-dev
  sudo apt-get install python-opencv 三、example code
#!/usr/bin/python import cv2 as cv
import numpy
import io
import picamera # 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 = (, )
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
image = cv.imdecode(buff, ) # Save the result image
cv.imwrite('result.jpg', image)