Cant access usb webcam from a nvidia pytorch docker container

import cv2

Capture from the first camera

cap1 = cv2.VideoCapture(f’v4l2src device=/dev/video0 ! video/x-raw, width=640, height=360 ! videoconvert ! appsink’, cv2.CAP_GSTREAMER)

Capture from the second camera

cap2 = cv2.VideoCapture(f’v4l2src device=/dev/video2 ! video/x-raw, width=640, height=360 ! videoconvert ! appsink’, cv2.CAP_GSTREAMER)

while True:
# Read frames from both cameras
ret1, frame1 = cap1.read()
ret2, frame2 = cap2.read()
print(frame1)
print(frame2)
if ret1:
cv2.imshow(‘Camera 1’, frame1)

if ret2:
    cv2.imshow('Camera 2', frame2)

if cv2.waitKey(1) & 0xFF == ord(‘q’):

break

cap1.release()
cap2.release()
cv2.destroyAllWindows()

iam opening the docker using this command
sudo docker run -it --rm --runtime=nvidia --network=host -e NVIDIA_DRIVER_CAPABILITIES=compute,utility,video,graphics --device=/dev/video0:/dev/video0 --device=/dev/video2:/dev/video2 --gpus all --privileged -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v /etc/X11:/etc/X11 nvcr.io/nvidia/pytorch:24.05-py3-igpu

iam not able to access the webcam from inside the docker please help me
iam using the docker nvcr.io/nvidia/pytorch:24.05-py3-igpu

There is no update from you for a period, assuming this is not an issue any more.
Hence we are closing this topic. If need further support, please open a new one.
Thanks

Hi,

Could you share what kind of error you met?
Thanks.