亲宝软件园·资讯

展开

树莓派用python中的OpenCV输出USB摄像头画面

人气:0

确认Python版本

$ python
Python 2.7.13 (default, Jan 19 2019, 14:48:08) 
[GCC 6.3.0 20170124] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()

确认OS版本

$ uname -a
Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.1 (stretch)
Release: 9.1

安装OpenCV和Python版的OpenCV安装包

$ sudo apt-get install libopencv-dev
$ sudo apt-get install python-opencv

Python的例程

import cv2
#初期化USB摄像头
cap = cv2.VideoCapture(0)
while( cap.isOpened() ):
 #USB摄像头工作时,读取一帧图像
 ret, frame = cap.read()
 #显示图像窗口在树莓派的屏幕上
 cv2.imshow('Capture',frame)
 #按下q键退出
 key = cv2.waitKey(1)
 #print( '%08X' % (key&0xFFFFFFFF) )
 if key & 0x00FF == ord('q'):
 break
# 释放资源和关闭窗口
cap.release()
cv2.destroyAllWindows()

图像输出的树莓派截屏

您可能感兴趣的文章:

加载全部内容

相关教程
猜你喜欢
用户评论