I am new to opencv and trying to access my Macbook's built-in camera through OpenCV python but it gives an error.
import cv2
frameWidth = 640
frameHeight = 480
cap = cv2.VideoCapture(0)
cap.set(3, frameWidth)
cap.set(4, frameHeight)
cap.set(10,150)
while True:
success, img = cap.read()
cv2.imshow("Result", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
Traceback (most recent call last):
File "/Users/hasanaktas/PycharmProjects/OpencvPython/project3.py", line 12, in <module>
cv2.imshow("Result", img)
cv2.error: OpenCV(4.2.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'
already tried changing VideoCapture(0) to VideoCapture(1) and adding the following code but still didn't help. Btw using PyCharm
cap.release()
cv2.destroyAllWindows()
cap.set(10,150)
? Try to avoid ugly constants like that and use the parameter names defined for you. – ShorttermApple Developer
from accessing any of the peripherals. This gave us problems because it would not let Audacity access the mic. We had to build a shell script wrapper around it. Bash was signed so the bash script that called audacity was allowed to access the mic. – Sheeb