I noticed I started having this issue as soon as I built the opencv_contrib module, because before my code was working and now I cannot access my web-cam with opencv even with the simple face detection program. Instead I get this error:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /io/opencv/modules/imgproc/src/color.cpp:10638: error: (-215) scn == 3 || scn == 4 in function cvtColor
But for a simple program to open Camera it just exits i am with the opinion that it reads false for ret at line ret, frame = cam.read
This is my code for launching: web-cam
import cv2
cv2.namedWindow("preview")
cam = cv2.VideoCapture(0)
if cam.isOpened(): # try to get the first frame
ret, frame = cam.read()
else:
ret = False
while ret:
cv2.imshow("preview", frame)
ret, frame = cam.read()
key = cv2.waitKey(20)
if key == 27:
break
cv2.destroyWindow("preview")
cam.release()
In[5] print (cv2.__version__)
3.3.0
In[6] webcam = cv2.VideoCapture(0)
ret,frame = webcam.read()
print (ret)
False