jetcam icon indicating copy to clipboard operation
jetcam copied to clipboard

RuntimeError: Could not initialize camera

Open deven96 opened this issue 5 years ago • 14 comments

RuntimeError: Could not read image from camera

deven96 avatar Nov 07 '19 18:11 deven96

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

beyondli avatar Nov 22 '19 09:11 beyondli

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.

mduaneh avatar Jan 17 '20 19:01 mduaneh

@beyondli your solution worked for me too. Interested like @mduaneh to know if this has any impact on performance? Seems fine on the surface. Thanks for this fix!

dbarnes10 avatar Jun 30 '20 08:06 dbarnes10

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?

anselanza avatar Sep 24 '20 08:09 anselanza

Also, the hack appears not to work for me, anyway.

anselanza avatar Sep 24 '20 08:09 anselanza

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

japrogramer avatar Nov 24 '20 23:11 japrogramer

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

Maralai avatar Feb 13 '21 20:02 Maralai

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

eugene-mobile avatar May 16 '21 00:05 eugene-mobile

After modify the docker command, remeber to restart your jetson nano!

Jasonx001 avatar Jul 27 '21 02:07 Jasonx001

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?

Chaitanya-Mehta avatar Mar 31 '22 21:03 Chaitanya-Mehta

@Jasonx001 @eugene-mobile @Maralai

Chaitanya-Mehta avatar Mar 31 '22 21:03 Chaitanya-Mehta

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

hs2415 avatar Jul 22 '22 10:07 hs2415

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 avatar Jul 22 '22 12:07 hs2415

@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?

fa00fa avatar Oct 26 '22 03:10 fa00fa