2017-10-19 185 views
-1

我使用OpenCv从网络摄像头捕捉图像。打开cv关闭相机

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

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 
+0

你的代码工作正常。一旦您按任意键,相机会自动关闭,因为您使用了waitKey(0)。你能详细说明你的问题吗? – Jazz

+0

谢谢,即使在写入文件后,相机指示灯仍然闪烁。它只会在python会话关闭时关闭。 – akshay

回答

-1

变化CV_WINDOW_AUTOSIZEWINDOW_AUTOSIZE失踪()