dusty-nv / jetson-containers

Machine Learning Containers for NVIDIA Jetson and JetPack-L4T
MIT License
1.97k stars 425 forks source link

Using opencv VideoCapture #66

Open Noam-M opened 3 years ago

Noam-M commented 3 years ago

Hello @dusty-nv,

Iv'e been using the l4t-ml docker container using images saved locally on my Jetson Xavier NX, and now I'm interested in using my network directly using my USB webcam.

I have successfully connected it and I see it as '/dev/video0'. I'm using the following code but cannot capture the actual images:

cap = cv2.VideoCapture(0)
ret, frame = cap.read()
print(frame)

Which simply outputs None

I have also tried to mount the'/dev'directory onto the docker image as follows: sudo docker run -it --rm --runtime nvidia --network host -v /dev:/dev nvcr.io/nvidia/l4t-ml:r32.4.4-py3 I can see '/dev/video0 inside the container but unfortunately it didn't help using VideoCapture

Do you have an idea what's missing?

Thanks!

dusty-nv commented 3 years ago

Hmm. If you run this inside container, can it print information about your /dev/video0 device?

apt-get update && apt-get install v4l-utils
v4l2-ctl --device /dev/video0 --list-formats-ext
Noam-M commented 3 years ago

Hello @dusty-nv

Thank you for the quick reply! I have tried that in my container and got the following output: Failed to open /dev/video0: Operation not permitted Doing the same thing outside the container worked flawlessly How can I change the permissions for the operation?

Thanks

dusty-nv commented 3 years ago

Hmm. Can you try mounting /dev/video0 instead of /dev


From: Noam-M @.> Sent: Saturday, May 29, 2021 5:17:10 PM To: dusty-nv/jetson-containers @.> Cc: Dustin Franklin @.>; Mention @.> Subject: Re: [dusty-nv/jetson-containers] Using opencv VideoCapture (#66)

Hello @dusty-nvhttps://github.com/dusty-nv

Thank you for the quick reply! I have tried that in my container and got the following output: Failed to open /dev/video0: Operation not permitted Doing the same thing outside the container worked flawlessly How can I change the permissions for the operation?

Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/dusty-nv/jetson-containers/issues/66#issuecomment-850900131, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADVEGKZM65JYEDGLGL52I4LTQFKVNANCNFSM45WLBPZQ.

Noam-M commented 3 years ago

Hello @dusty-nv

I tried this: sudo docker run -it --rm --runtime nvidia --network host -v /dev/video0:/dev/video0 nvcr.io/nvidia/l4t-ml:r32.4.4-py3 And still the VideoCapture didn't work (got None) Trying to run v4l2-ctl --device /dev/video0 --list-formats-ext from within the container, I got Failed to open /dev/video0: Is a directory as output

I then tried to run the docker as follows: sudo docker run -it --rm --runtime nvidia --network host -v /dev/video0:/dev nvcr.io/nvidia/l4t-ml:r32.4.4-py3 But it didn't run at all, issuing the following error: docker: Error response from daemon: OCI runtime create failed: container_linux.go:367: starting container process caused: process_linux.go:495: container init caused: open /dev/ptmx: no such file or directory: unknown.

Any further ideas?

Thanks!

Noam-M commented 3 years ago

Hello @dusty-nv Any other ideas of how to use a video from a webcam in real time?

Thanks!

dusty-nv commented 3 years ago

Hmm...what is the USB webcam you are using?


From: Noam-M @.> Sent: Sunday, June 6, 2021 2:08:25 PM To: dusty-nv/jetson-containers @.> Cc: Dustin Franklin @.>; Mention @.> Subject: Re: [dusty-nv/jetson-containers] Using opencv VideoCapture (#66)

Hello @dusty-nvhttps://github.com/dusty-nv Any other ideas of how to use a video from a webcam in real time?

Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/dusty-nv/jetson-containers/issues/66#issuecomment-855438609, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADVEGK2IISVVH37ETOW5JQ3TRO2RTANCNFSM45WLBPZQ.

Noam-M commented 3 years ago

Hello @dusty-nv

My webcam is Xiaomi IMILAB Full HD 1080P Webcam W88 S.

Noam-M commented 3 years ago

Hello @dusty-nv Any suggestions?

Thanks!

dusty-nv commented 3 years ago

Hi @Noam-M, sorry for the delay. Can you try mounting /dev/video0 with the --device flag instead?

sudo docker run -it --rm --runtime nvidia --network host --device /dev/video0 nvcr.io/nvidia/l4t-ml:r32.4.4-py3
sudhamsursr commented 2 years ago

Hi,

The last command posted by @dusty-nv has worked for me on Jetson Xavier: sudo docker run -it --rm --runtime nvidia --network host --device /dev/video0 nvcr.io/nvidia/l4t-ml:r32.4.4-py3

However, if you have multiple cameras, the following command had worked for me: (4 cameras for example) sudo docker run -it --rm --runtime nvidia --network host --device /dev/video0 --device /dev/video1 --device /dev/video2 --device /dev/video4 nvcr.io/nvidia/l4t-ml:r32.4.4-py3