Python 3.7.6, opencv-python 4.4.0, Windows 10
Code
import cv2
cap = cv2.VideoCapture(1)
while True:
success, frame = cap.read()
cv2.imshow("frame", frame)
if cv2.waitKey(0) & 0xFF == ord('q'):
break
I want to access my external usb webcam. I am new to opencv and got the following error message.
C:\Users\92311\PycharmProjects\ObjectDetector\venv\Scripts\python.exe C:/Users/92311/PycharmProjects/ObjectDetector/main.py
[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-2b5g8ysb\opencv\modules\videoio\src\cap_msmf.cpp (435) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
Traceback (most recent call last):
File "C:/Users/92311/PycharmProjects/ObjectDetector/main.py", line 5, in <module>
cv2.imshow("frame", frame)
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-2b5g8ysb\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
Process finished with exit code 1
Can any one explain what's the real problem.
Python 3.7.6, opencv-python 4.4.0, Windows 10
Code
import cv2
cap = cv2.VideoCapture(1)
while True:
success, frame = cap.read()
cv2.imshow("frame", frame)
if cv2.waitKey(0) & 0xFF == ord('q'):
break
I want to access my external usb webcam. I am new to opencv and got the following error message.
C:\Users\92311\PycharmProjects\ObjectDetector\venv\Scripts\python.exe C:/Users/92311/PycharmProjects/ObjectDetector/main.py
[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-2b5g8ysb\opencv\modules\videoio\src\cap_msmf.cpp (435) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
Traceback (most recent call last):
File "C:/Users/92311/PycharmProjects/ObjectDetector/main.py", line 5, in <module>
cv2.imshow("frame", frame)
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-2b5g8ysb\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
Process finished with exit code 1
Can any one explain what's the real problem.
cv2.VideoCapture(0,cv2.CAP_DSHOW) 如果是 windows7 试试这个对我有用
Python 3.7.6, opencv-python 4.4.0, Windows 10
Code
import cv2
cap = cv2.VideoCapture(1)
while True:
success, frame = cap.read()
cv2.imshow("frame", frame)
if cv2.waitKey(0) & 0xFF == ord('q'):
break
I want to access my external usb webcam. I am new to opencv and got the following error message.
C:\Users\92311\PycharmProjects\ObjectDetector\venv\Scripts\python.exe C:/Users/92311/PycharmProjects/ObjectDetector/main.py
[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-2b5g8ysb\opencv\modules\videoio\src\cap_msmf.cpp (435) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
Traceback (most recent call last):
File "C:/Users/92311/PycharmProjects/ObjectDetector/main.py", line 5, in <module>
cv2.imshow("frame", frame)
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-2b5g8ysb\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
Process finished with exit code 1
Can any one explain what's the real problem.
try this one if cv2.waitkey(1) & 0xFF == ord('q'): break
note that its waitkey(1) and not 0 as argument.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.