打开cv关闭相机

时间:2017-10-19 02:17:20

标签: python opencv camera

我正在使用OpenCv从网络摄像头捕获图像。

它工作正常我只是不知道如何关闭相机。

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("cam-test",CV_WINDOW_AUTOSIZE)
    imshow("cam-test",img)`
    waitKey(0)
    destroyWindow("cam-test")
    imwrite("testfilename.jpg",img) #save image
    cam.release

2 个答案:

答案 0 :(得分:5)

我认为您在()

结尾处错过了cam.release

答案 1 :(得分:-1)

CV_WINDOW_AUTOSIZE更改为WINDOW_AUTOSIZE

相关问题