RuntimeError: Could not initialize camera
Opened this issue ยท 14 comments
RuntimeError: Could not read image from camera
if your opencv is not installed with jetpack ,you should modified code
in the file usb_camera.py, line 20
#self.cap = cv2.VideoCapture(self._gst_str(), cv2.CAP_GSTREAMER)
self.cap = cv2.VideoCapture(self.capture_device)
then reinstall jetcam, camera should be OK
What is meant by "OpenCV" not installed with jetpack?
I just installed jetpack 4.3, then added all the apt-get install Nvidia-jetpack modules.
There are OpenCV items listed in there as being installed.
Adding the fix above allowed my capture to work, I'm not sure at what cost.
Trying to get basic demo (csi_camera) working and getting the same error. I am using Jetpack 4.4 on a Xavier NX, and have a Raspberry Pi v2 camera connected to cam0. Works fine with gstreamer from command-line (can see camera image and all).
Is openCV not installed with Jetpack anyway? Or are you saying there is a different version? Why the need to hack the source code?
Also, the hack appears not to work for me, anyway.
I am also getting this error Im working through the
Getting Started with AI on Jetson Nano!
course but the camera doesn't work in the container
!ls -ltrh /dev/video*
crw-rw---- 1 root video 81, 0 Nov 24 22:59 /dev/video0
from jetcam.csi_camera import CSICamera
camera = CSICamera(width=224, height=224, capture_device=0) # confirm the capture_device number
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/csi_camera.py in __init__(self, *args, **kwargs)
23 if not re:
---> 24 raise RuntimeError('Could not read image from camera.')
25 except:
RuntimeError: Could not read image from camera.
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
<ipython-input-6-b46e6557b315> in <module>
1 from jetcam.csi_camera import CSICamera
2
----> 3 camera = CSICamera(width=224, height=224, capture_device=0) # confirm the capture_device number
/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/csi_camera.py in __init__(self, *args, **kwargs)
25 except:
26 raise RuntimeError(
---> 27 'Could not initialize camera. Please see error trace.')
28
29 atexit.register(self.cap.release)
RuntimeError: Could not initialize camera. Please see error trace.
When I try this, there is no error but the image is all one shade of green.
import cv2
cam = cv2.VideoCapture(0)
ret, frame = cam.read()
cv2.imwrite("test.png", frame)
However the camera does work with this
gst-launch-1.0 nvarguscamerasrc ! nvoverlaysink
โ ~ v4l2-ctl -d /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'RG10'
Name : 10-bit Bayer RGRG/GBGB
Size: Discrete 3264x2464
Interval: Discrete 0.048s (21.000 fps)
Size: Discrete 3264x1848
Interval: Discrete 0.036s (28.000 fps)
Size: Discrete 1920x1080
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1640x1232
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.017s (60.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.017s (60.000 fps)
Found solution
was missing -volume /tmp/argus_socket:/tmp/argus_socket
Found solution
was missing
-volume /tmp/argus_socket:/tmp/argus_socket
The solution for me was to append this command to the docker run
:
-v /tmp/argus_socket:/tmp/argus_socket
Adding --volume /tmp/argus_socket:/tmp/argus_socket
to docker run command definitely helped me trying to use IMX219 camera in a dli-nano jupiter.
Just for reference, my full docker command now is:
sudo docker run \
--runtime nvidia -it --rm --network host \
--volume ~/nvdli-data:/nvdli-nano/data \
--device /dev/video0 \
--volume /tmp/argus_socket:/tmp/argus_socket \
nvcr.io/nvidia/dli/dli-nano-ai:v2.0.1-r32.5.0
After modify the docker command, remeber to restart your jetson nano!
I am trying to run the interactive_motion.py example for my jetracer kit. But
from jetcam.csi_camera import CSICamera
camera = CSICamera(width=224, height=224)
camera.running = True
Throws an error
RuntimeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/csi_camera.py in init(self, *args, **kwargs)
23 if not re:
---> 24 raise RuntimeError('Could not read image from camera.')
25 except:
RuntimeError: Could not read image from camera.
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
in
2 # from jetcam.usb_camera import USBCamera
3
----> 4 camera = CSICamera(width=224, height=224)
5 # camera = USBCamera(width=224, height=224)
6
/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/csi_camera.py in init(self, *args, **kwargs)
25 except:
26 raise RuntimeError(
---> 27 'Could not initialize camera. Please see error trace.')
28
29 atexit.register(self.cap.release)
RuntimeError: Could not initialize camera. Please see error trace.
Can you guys help me solve this error?
Did you find a solution?
I am having the same issue. I'm running Jetpack 4.4.1 and have openCV version 4.1.1, so @anselanza's solution wasn't relevant
Adding
--volume /tmp/argus_socket:/tmp/argus_socket
to docker run command definitely helped me trying to use IMX219 camera in a dli-nano jupiter. Just for reference, my full docker command now is:sudo docker run \ --runtime nvidia -it --rm --network host \ --volume ~/nvdli-data:/nvdli-nano/data \ --device /dev/video0 \ --volume /tmp/argus_socket:/tmp/argus_socket \ nvcr.io/nvidia/dli/dli-nano-ai:v2.0.1-r32.5.0
The course has been updated to include this but it is still throwing up an error for me even after including the
/tmp/argus_socket:/tmp/argus_socket
@hs2415 @Chaitanya-Mehta @japrogramer
What does executing this statement :
from jetcam.csi_camera import CSICamera
camera = CSICamera(width=224, height=224)
and execute this --volume /tmp/argus_socket:/tmp/argus_socket
What does it matter?