2017-10-19 173 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失蹤()