如何在python2中从网络摄像头捕获图像?

时间:2017-02-10 07:50:57

标签: python-2.7 webcam raspberry-pi3

我使用的代码给出了输出但是图像是随机裁剪的,并且不适合窗口的大小。当我使用namedWindow("Image", WINDOW_NORMAL);时,它会给出错误 :NameError: name 'CV_WINDOW_AUTOSIZE'未定义

代码:

from cv2 import *
# initialize the camera
cam = VideoCapture(0)   # 0 -> index of camera
s, img = cam.read()
if s:    # frame captured without any errors
    namedWindow("Image", WINDOW_NORMAL);
    imshow("cam-test",img)
    waitKey(500)
    destroyWindow("cam-test")
    imwrite("filename.jpg",img) #save image

我该怎么办?enter image description here

1 个答案:

答案 0 :(得分:0)

尝试更改:

namedWindow("Image", WINDOW_NORMAL);

为:

namedWindow("Image");