Making Nvidia DLI hello camera notebook work with a Logitech QuickCam Express USB webcam

Hi, I have a Logitech QuickCam Express webcam that I want to use for the ‘Getting Started with AI on Jetson Nano’ course.

The hello_camera notebook gives errors when trying to connect to the webcam at:

camera = USBCamera(width=224, height=224, capture_width=640, capture_height=480, capture_device=0)
RuntimeError: Could not initialize camera.  Please see error trace.

capture_device=0 seems correct because I have /dev/video0.

I read some posts in this forum that referred to GStreamer (e.g. here). I can make this camera work (X11 fowarding) with GStreamer using:

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-bayer,format=gbrg,width=176,height=144,framerate=2/1 ! bayer2rgb ! ximagesink

But how can I now adapt the Python code in the hello_camera notebook to make use of this GStreamer and make the notebook work?

Have you tried giving the same width, height and framerate information in the API call?

Thanks. Yes indeed, I have tried specifying those parameters. Without any luck though.

What does the error trace say? If it is a V4L2 device (as it seems to be), is there any particular reason for using the NVIDIA API? Its best to avoid 3rd party libraries if you can as it just adds an unnecessary layer of abstraction to the hardware…

Thanks for your reply. There’s no particular reason for using the NVIDIA API; I just want to follow the Python notebooks of the nvidia ‘Getting Started with AI’ course. It’s all quite new to me, so those notebooks are all I got.

Below is the full error trace:

from jetcam.usb_camera import USBCamera
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)
<ipython-input-1-f18496a4fe52> in <module>
      1 from jetcam.usb_camera import USBCamera
      2 
----> 3 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.

Can you run these commands (outside of Docker) and post the output of the bottom command?

$ sudo apt-get install v4l-utils
$ v4l2-ctl --device=/dev/video0 --list-formats-ext

This will print out the formats/resolutions that your camera supports. My guess is that the Bayer format you are using is throwing it off in the notebook. This is the line from the Jetcam module that you can modify inside your container to change the GStreamer pipeline that is used for the camera capture:

Note how that code is setup for video/x-raw (which is more commonly used) and not video/x-bayer

The Bayer format might indeed be an issue. Here’s the output of v4l2-ctl:

v4l2-ctl --device=/dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'S561' (compressed)
	Name        : GSPCA SPCA561
		Size: Discrete 320x240
		Size: Discrete 352x288

	Index       : 1
	Type        : Video Capture
	Pixel Format: 'GBRG'
	Name        : 8-bit Bayer GBGB/RGRG
		Size: Discrete 160x120
		Size: Discrete 176x144

I believe S561 also refers to the Bayer format. Do you think this is the issue with this webcam, and do you think it could be solved by modifying that line 33 in the JetCam USBCamera module?

Hi,
The formats are special and need additional process like debayering. Is not able to work directly. Please consider to use cameras with YUV422 format such as UYVY, YUYV.

You can refer to the steps to check if the camera works on Jetson platforms:


Q: I have a USB camera. How can I launch it on Jetson Nano?

Thank you, I’ll give it a try.

Since you confirmed that your standalone GStreamer pipeline with x-video/bayer does work, you may be able to modify JetCam inside the container to use the same. However, your other issue is that the camera only supports a max resolution of 176x144 in that format - whereas the DNN models used in the notebooks need a minimum of 224x224.

As @DaneLLL suggested, you may want to look at upgrading your camera - the Logitech C270 and C920 are tested with the DLI container.