I can't use the webcam from the docker container

I’m in trouble!

I used NVIDIA L4T PyTorch to get YOLO v5 working.
In YOLO v5, object detection from images worked.
Next, I tried to detect the object from the image from the webcam.

I have added the --device option to the following command.
sudo docker run --runtime nvidia -it --rm --net host --device /dev/video0 -v /home/User/Desktop/work/1/yolov5:/yolov5 nvcr.io/nvidia/l4t-pytorch:r32.7.1-pth1.9-py3 bash

The container creation is successful.
Then I installed the required libraries for YOLO v5 in the container.

I entered the webcam as source 0 and started YOLO v5.
python3 detect.py --source 0 --weights yolov5s.pt

However, it fails as shown in the image below.
Could you please tell me what is missing?

I want the support of people all over the world!!

Hi,

The error shows the display cannot be opened.
Could you try to launch the container as follows:

$ export DISPLAY=:0
$ xhost +
$ sudo docker run -it --rm --net=host --runtime nvidia  -e DISPLAY=$DISPLAY ...

Then export the DISPLAY variable inside the container as well:
For example:

# export DISPLAY=:0
# python3 detect.py --source 0

Thanks.

1 Like

Thank you for your help.
It worked! !!
I’m so excited.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.