Jupyter jetcam in docker, 'Could not initialize camera'

Hello everyone,

I’m trying to run trt_pose inside of docker container, for now I’m trying to run live_demp.ipynb, and everything works fine except for jetcam.

piece of code:

from jetcam.usb_camera import USBCamera
from jetcam.utils import bgr8_to_jpeg

camera = USBCamera(width=WIDTH, height=HEIGHT, capture_fps=30)
camera.running = True

error:

---------------------------------------------------------------------------
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-12-3efd176c52b8> in <module>
      3 from jetcam.utils import bgr8_to_jpeg
      4 
----> 5 camera = USBCamera(width=WIDTH, height=HEIGHT, capture_fps=30)
      6 # camera = CSICamera(width=WIDTH, height=HEIGHT, capture_fps=30)
      7 

/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.

output of v4l2-ctl -d /dev/video0 --list-formats-ext :

ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'YUYV'
	Name        : YUYV 4:2:2
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 160x120
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 176x144
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 320x240
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 352x288
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.100s (10.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.200s (5.000 fps)

	Index       : 1
	Type        : Video Capture
	Pixel Format: 'MJPG' (compressed)
	Name        : Motion-JPEG
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 160x120
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 176x144
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 320x240
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 352x288
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)

output of gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! xvimagesink:

Setting pipeline to PAUSED ...
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0: Could not initialise Xv output
Additional debug info:
xvimagesink.c(1773): gst_xv_image_sink_open (): /GstPipeline:pipeline0/GstXvImageSink:xvimagesink0:
Could not open display (null)
Setting pipeline to NULL ...
Freeing pipeline ...

I believe the reason of the problem is in the last command output, but I don’t understand what the command is actually trying to achieve…

I mapped the host machine webcam to the docker container, this mean the container recognize the camera, but jetcam don’t for some reason.

Thanks in advance,
Hassan

Information about the container:
the base image is nvcr.io/nvidia/tensorrt:20.03-py3
I installed all missing libraries using the bash inside of the container, and cloned trt_pose
the run command:
sudo docker run --gpus all -it --device=/dev/video0:/dev/video0 -p 8888:8888 --rm <image_name>

then run jupyter using:
jupyter notebook --ip 0.0.0.0 --no-browser --allow-root

and open jupyter on the host machine’s browser