[英]Python - cv2 package is not showing any function while typing in pycharm
[英]cv2 not showing any thing
我正在尝试使用笔记本电脑相机拍照和显示图片,并且我正在使用python 3.6.3和Windows,我已经尝试使用cv2模块,并且我已经使用了这个简单的代码
import cv2
video=cv2.VideoCapture(0)
print ( video.read())
video.release()
而且它只接收黑色图片,这就是我从打印得到的内容(video.read()):
(True, array([[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
...,
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
...,
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
...,
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],
...,
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
...,
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
...,
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
...,
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]], dtype=uint8))
我尝试了不同的代码,并且尝试将video=cv2.VideoCapture(0)
更改为video=cv2.VideoCapture(1)
或video=cv2.VideoCapture(-1)
,但当我将其更改为1或-1打印(错误,无),我也确定我的所有驱动程序都不需要任何更新
还有其他方法可以从笔记本电脑相机拍摄照片吗? 除了cv2和pygame以外? 只要pygame相机仅适用于linux
这是我这样做的方式,并且可以正常工作:
video_capture = cv2.VideoCapture(0)
while True:
if not video_capture.isOpened():
print('Unable to load camera.')
sleep(5)
pass
# Capture frame-by-frame
ret, frame = video_capture.read()
您在frame变量上拥有的是图片,因此您可以使用以下方式将其保存到磁盘:
cv2.imwrite("mypic.jpg",frame)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.