I am following the official documentation trying to read a video from a webcam. When I ran part of the code from the documentation:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
it does not work with the following output:
OpenCV error: statement failed (scn == 3 || scn == 4) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 9748
Traceback (last last call):
File "capture. py ", line 11, in
gray = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY)
cv2.error: /io/opencv/modules/imgproc/src/color.cpp: 9748: error: (-215) scn == 3 || scn == 4 in the cvtColor function
After examining it, it turned out that:
retalways False.cap.get(3) ( ) 0.0.cap.isOpened(), False.cap.open(0), open False.cap.open("/dev/video0") .cap = cv2.VideoCapture(0) cap = cv2.VideoCapture("/dev/video0") .
/dev/video0 VLC -. , -. .
?