Reputation: 99
I am new to OpenCV and am trying to make a live face tracker on my computer. I seem to be having an issue with my video input (is it not getting any?). I'm on a mac laptop and am trying to use my built-in webcam.
Error:
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'
Code:
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()
I tried to change cv2.VideoCapture(0) to cv2.VideoCapture(1), but that resulted in this error:
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)
Upvotes: 1
Views: 3990
Reputation: 911
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()
Upvotes: 1