I have the similar issue with this discussion, after I read it still don't have clue for how to address mine,that I post my case here
joy@raspberrypi:~ $ hostnamectl Static hostname: raspberrypi Icon name: computer Machine ID: 4aa79d3da798421f9882083733d765d5 Boot ID: b42eea511b8d4ad5bfec964bfb792d1b Operating System: Raspbian GNU/Linux 11 (bullseye) Kernel: Linux 5.15.61-v8+ Architecture: arm64
I use Raspberry Pi 4 ; 32 bit, linux Linux 5.15.61-v8+ run python3 ; logitech USB camera lens ; run in virtual environment
- the python script
opencv_camera.py
import cv2 # define a video capture object vid = cv2.VideoCapture(1) ########## 1- device id =1###if 1 deosn't work try 2 while(True): ret, frame = vid.read() cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break vid.release() cv2.destroyAllWindows()
error occur:
cv2.error: OpenCV(4.6.0) .... in function 'imshow'
- the output:
(venv) joy@raspberrypi:~/Desktop $ python opencv_camera.py [ WARN:[email protected]] global /tmp/pip-wheel-u79916uk/opencv-python_ea2489746b3a43bfb3f2b5331b7ab47a/opencv/modules/videoio/src/cap_v4l.cpp (902) open VIDEOIO(V4L2:/dev/video1): can't open camera by index Traceback (most recent call last): File "/home/joy/Desktop/opencv_camera.py", line 14, in <module> cv2.imshow('frame', frame) cv2.error: OpenCV(4.6.0) /tmp/pip-wheel-u79916uk/opencv-python_ea2489746b3a43bfb3f2b5331b7ab47a/opencv/modules/highgui/src/window.cpp:967: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
cv2.error:
in functionimshow
. Sorry, I though I made myself clear enough, but still have more things to learnLinux 5.15.61-v8+
is a kernel NOT an OS, but from the edited question it appears you are probably running Raspberry Pi OS Bullseye 64bit, which contradicts your Question. Unless you explain what you installed and how no one can help. Why are you running a virtual environment - this is an advanced technique but you seem to be struggling with basics?