码迷,mamicode.com
首页 > 编程语言 > 详细

RPi 2B python opencv camera demo example

时间:2016-02-27 23:28:06      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

/**************************************************************************************
 *                     RPi 2B python opencv camera demo example
 * 声明:
 *     本文主要记录RPi 2B 使用python opencv来获取图片的方式。
 *
 *                                                   2016-2-24 深圳 南山平山村 曾剑锋
 ************************************************************************************/

一、参考文档:
    1. OpenCV with Raspberry Pi Camera Face Detection Tutorial - Robotics with Python Raspberry Pi and GoPiGo p.7
        https://pythonprogramming.net/raspberry-pi-camera-opencv-face-detection-tutorial/
    2. Raspberry Pi OpenCV,在树莓派下使用opencv
        http://www.educity.cn/wenda/565761.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 doesnt 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
    image = cv.imdecode(buff, 1)
    
    # Save the result image
    cv.imwrite(result.jpg, image)

 

RPi 2B python opencv camera demo example

标签:

原文地址:http://www.cnblogs.com/zengjfgit/p/5223747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!