2017-02-10 146 views
0

,我使用的代碼給出了輸出,但圖像隨機裁剪和不適合TOT的窗口的大小。當我使用namedWindow("Image", WINDOW_NORMAL);它給出了錯誤的 :NameError: name 'CV_WINDOW_AUTOSIZE'沒有定義如何在python2中從網絡攝像頭捕捉圖像?

代碼:

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

回答

0

嘗試改變:

namedWindow("Image", WINDOW_NORMAL); 

到:

namedWindow("Image");