import cv2
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Don't open camera")
else:
ret, frame = cap.read()
if ret:
cv2.imshow('frame', frame)
cv2.waitKey(0)
cap.release()
cv2.destroyAllWindows()
Here is the error message that is being printed:
[ WARN:0] global /tmp/pip-req-build-6icxdfha/opencv/modules/videoio/src/cap_v4l.cpp (890) open VIDEOIO(V4L2:/dev/video0): can’t open camera by index
Does your opencv version have V4L2 and Gstreamer support compiled in? Run opencv_version -v to find out.
Some things you can try are to use the GStreamer backend as you know this is working, however if your OpenCV version is not have that compiled in then you will need to compile yourself.