巫山雨_fz
2021-06-05 15:21
采纳率: 74.1%
浏览 112

python+opencv调用摄像头,本站原封不动拷贝的例程,报错未定义变量,究竟是为什么?

import cv2
import numpy as np
def video_demo():  
    cap = cv2.VideoCapture(0,cv2.CAP_DSHOW)    
while(True):
    ret,frame = cap.read()
    frame = cv2.flip(frame, 1)
    cv2.imshow("capture", frame)
    cv2.imshow("video", frame)
    c = cv2.waitKey(50)
    if c == 27:
        break
video_demo()
cv2.destroyAllWindows()

runfile('C:/Users/Administrator/.spyder-py3/temp.py', wdir='C:/Users/Administrator/.spyder-py3')
Traceback (most recent call last):

  File "C:\Users\Administrator\.spyder-py3\temp.py", line 10, in <module>
    ret,frame = cap.read()

NameError: name 'cap' is not defined

3条回答 默认 最新

相关推荐 更多相似问题