Cannot get USB cam to work in jetpack docker

Hi
Its been asked a million times, but none of the existing threads got my cam working.

SW version/tag:v2.0.1-r32.5.1

I’m going through the introductory courseware for a second time.

My first time throug, was able to get everything working on the CSI Pi ribbon camera, but when I try from my USB webcam, I get the following:

!ls -ltrh /dev/video*
crw-rw---- 1 root video 81, 0 Apr 19 19:20 /dev/video0

from jetcam.usb_camera import USBCamera

#TODO change capture_device if incorrect for your system
camera = USBCamera(width=224, height=224, capture_width=640, capture_height=480, capture_device=0)


RuntimeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/usb_camera.py in init(self, *args, **kwargs)
23 if not re:
—> 24 raise RuntimeError(‘Could not read image from camera.’)
25

RuntimeError: Could not read image from camera.

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last)
in
2
3 #TODO change capture_device if incorrect for your system
----> 4 camera = USBCamera(width=224, height=224, capture_width=640, capture_height=480, capture_device=0)

/usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/usb_camera.py in init(self, *args, **kwargs)
26 except:
27 raise RuntimeError(
—> 28 ‘Could not initialize camera. Please see error trace.’)
29
30 atexit.register(self.cap.release)

RuntimeError: Could not initialize camera. Please see error trace.

I ran the following to get info on my cam:

v4l2-ctl -d /dev/video0 --list-formats-ext

ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: ‘MJPG’ (compressed)
Name : Motion-JPEG
Size: Discrete 1920x1080
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 3840x2160
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 3264x1836
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 2592x1944
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 2048x1536
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 800x600
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 640x480
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 320x240
Interval: Discrete 0.040s (25.000 fps)

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUYV 4:2:2
            Size: Discrete 1280x720
                    Interval: Discrete 0.100s (10.000 fps)
            Size: Discrete 800x600
                    Interval: Discrete 0.050s (20.000 fps)
            Size: Discrete 640x480
                    Interval: Discrete 0.040s (25.000 fps)
            Size: Discrete 320x240
                    Interval: Discrete 0.040s (25.000 fps)

I was really pleased I got the CSI device to work without any fuss, but this USB cam is a real pain.
Any help is greatly appreciated.

Hi,
It looks like you need to set framerate. The gstreamer string is
jetcam/usb_camera.py at master · NVIDIA-AI-IOT/jetcam · GitHub

'v4l2src device=/dev/video{} ! video/x-raw, width=(int){}, height=(int){}, framerate=(fraction){}/1 ! videoconvert !  video/x-raw, format=(string)BGR ! appsink'.format(self.capture_device, self.capture_width, self.capture_height, self.capture_fps)

Please add framerate and try again.

Thank you, DaneLLL
I have a few follow-ups

  1. How were you able to determine that this is what was causing the failure?
  2. That looks like the code line from usb_camera.py, so do I define framerate as a property when defining camera= in the notebook code? I attempted adding “framerate=x/1” to the camera= line in the notebook, trying 20,25, and 30 for x. None of those worked.
  3. I’ve noticed if I try to run any v4l2src commands from a shell running in the docker, it doesn’t work, but it is recognized by my host. I’m not familiar enough with docker containers to know if anything need to happen to extend v4l2src to the container

Thanks

One other item, Cheese does recognize the camera. Can I leverage the information that Cheese has to make it work under the docker image?

About cheese failure, you may check this.

Adding framerate didn’t help. I began digging deeper into gstreamer, but ultimately decided to just buy a logitech usb cam. I’d like to troubleshoot this, but it looks like more trouble than its worth.

You may try to see if you can just display your camera with gstreamer.
Be sure you have at least USB2 speed for your camera using lsusb -t.
Better try without any other USB device than mouse and keyboard.
Be aware that if going through a lower speed USB hub, that will limit your camera speed.
Be sure to have enough power supply for the camera.

From the logs above, your camera can provide MJPEG or YUYV 4:2:2. Let’s first try the lowest resolution and framerate.

# Raw mode YUYV 4:2:2, using YUY2 format for gstreamer
gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw, format=YUY2, width=320, height=240, framerate=25/1 ! xvimagesink

# MJPEG mode
gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg, width=320, height=240, framerate=25/1 ! jpegparse ! nvv4l2decoder mjpeg=1 ! nvvidconv ! xvimagesink