本文实例为大家分享了python opencv来表示usb摄像头画面的具体代码,供大家参考,具体内容如下
确认python版本
1
2
3
4
5
|
$ 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版本
1
2
3
4
5
6
7
|
$ 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安装包
1
2
|
$ sudo apt - get install libopencv - dev $ sudo apt - get install python - opencv |
python的例程
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
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() |
图像输出的树莓派截屏
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/weixin_43263947/article/details/86767409