vs2019+opencv4.1.0+python3.7捕获显示摄像头图像简单例程出现错误[WARN:0] 、[WARN:1] 、Error: -1072861855、v2. error

vs2019+opencv4.1.0+python3.7简单例程(捕获显示摄像头图像)出现如下错误:

使用例程:

import cv2

cap = cv2.VideoCapture(1)
while(1):
    # get a frame
    ret, frame = cap.read()
    # show a frame
    cv2.imshow("capture", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows() 

出现错误:

WARN: 1」global C: pro jects \opencv- py thon \opencv modules videoio\src cap msmf. cpp (1113) SourceReaderCB: :OnReadSample 
i deoio (MSMF) : OnReadSample() is called with error status: 一1072861855 
WARN:1] global C: \projects \opencv py thon \opencv \modules \videoio\src cap_ msmf. cpp (1125) SourceReaderCB: :OnReadSample V
i deoio (MSMF) : async ReadSample() call is failed with error status: 一1072861855
[ WARN:O] global C: \pro jects \opencv-py thon \opencv \modules \videoio src\cap_ msmf. cpp (1159) CvCapture_ MSME: : grabFrame vide
oio (MSMF): can t grab frame.
Error: -1072861855
Traceback (most recent call last) :
File" C: Users DELL Desktop \Py thonApplicat ion1 \Py thonApplicationl \PythonApplicationl.py",line 8,in 
cv2. imshow(" capture ,frame )
v2. error: OpenCV(4.2.0) C: \pro jects opencv py thon opencv \modules \hi ghgui \src window. cpp:376: error: ( 215:Assertion failed) size. width>0 & size. height>0 in function cV: : imshow
WARN:O] global C: \pro jects opencv- py thon opencv \modules \vi deoio\src\cap msmf. cpp (674) SourceReaderCB: : SourceReaderCB
terminating async callback 
请按任意键继续.

更改例程:

import cv2

cap = cv2.VideoCapture(1,cv2.CAP_DSHOW)
while(1):
    # get a frame
    ret, frame = cap.read()
    # show a frame
    cv2.imshow("capture", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows() 

即将cap = cv2.VideoCapture(1)改为了cap = cv2.VideoCapture(1,cv2.CAP_DSHOW)

你可能感兴趣的:(毕业设计)