我是OpenCV的新手,正在尝试在计算机上制作一个实时面部跟踪器。我的视频输入似乎有问题(没有得到任何声音吗?)。我在Mac笔记本电脑上,正在尝试使用内置的网络摄像头。
错误:
cv2.error: OpenCV(4.3.0) /Users/travis/build/skvark/opencv-
python/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0
&& size.height>0 in function 'imshow'
代码:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while True:
#capture frame by frame
ret, img = cap.read()
cv2.imshow('test', img)
cv2.waitKey(0) & 0xFF
cv2.destroyAllWindows()
cap.release()
我试图将cv2.VideoCapture(0)更改为cv2.VideoCapture(1),但这导致了此错误:
You might be loading two sets of Qt binaries into the same process. Check that all plugins
are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that
only one set of binaries are being loaded.
QObject::moveToThread: Current thread (0x7ff06a82c5d0) is not the object's thread
(0x7ff06a876c30).
Cannot move to target thread (0x7ff06a82c5d0)
答案 0 :(得分:1)
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
# Check if camera opened successfully
if (cap.isOpened()== False):
print("Error opening video stream or file")
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
cv2.imshow('Frame',frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()