Jetson Nano 2GB USB Camera not working in the course's Jupyter Notebook container

Hi all ,

I ran
ls /dev/video*
to find the webcam and I got the following output

ScreenshotLsVideo

I booted Nano 2GB using Jetpack 4.4.1
Then I ran the Docker container with the following command (as per the instructions given here)

mkdir -p ~/nvdli-data
> sudo docker run --runtime nvidia -it --rm --network host \
>     --volume ~/nvdli-data:/nvdli-nano/data \
>     --device /dev/video1 \
>     nvcr.io/nvidia/dli/dli-nano-ai:v2.0.1-r32.4.4

Once I open the jupyter notebook named usb_camera , and ran the cell for capturing image from USB cam , it is giving the following error

I changed the resolution also in that cell according to my camera ( 680x720) still I was getting the same error

Then I opened webbrowser and checked whether my webcam is working or not , it is working fine , attached the screenshot below
screenshotCam

Then I opened a new terminal and opened python3 and ran the following code

import cv2
video_capture = cv2.VideoCapture(1)
ret, frame = video_capture.read()
cv2.imwrite('screenshot.png',frame)

And I got an image named screenshot.png saved in home directory ( attached below )

Someone please help me to run the webcam in the jupyter notebook of nvidia jetson nano DL Course’s container

Hi,
Please check if you can launch the camera by following the steps in
Jetson Nano FAQ
Q: I have a USB camera. How can I launch it on Jetson Nano?

Thank you for the reply ,

I installed v4l-utils as given in the Jetson Nano FAQ
and after running

v4l2-ctl -d /dev/video0 --list-formats-ext

I got the below output
image

and when I ran

$ gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=640,height=480,framerate=30/1 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvoverlaysink

I got error , I am pasting the log below

gautham@gautham-desktop:~$ ls /dev/video*
/dev/video0
gautham@gautham-desktop:~$ sudo apt install v4l-utils
[sudo] password for gautham: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
v4l-utils is already the newest version (1.14.2-1).
The following packages were automatically installed and are no longer required:
  apt-clone archdetect-deb bogl-bterm busybox-static cryptsetup-bin
  dpkg-repack gir1.2-timezonemap-1.0 gir1.2-xkl-1.0 grub-common
  kde-window-manager kinit kio kpackagetool5 kwayland-data kwin-common
  kwin-data kwin-x11 libdebian-installer4 libkdecorations2-5v5
  libkdecorations2private5v5 libkf5activities5 libkf5attica5
  libkf5completion-data libkf5completion5 libkf5declarative-data
  libkf5declarative5 libkf5doctools5 libkf5globalaccel-data
  libkf5globalaccel5 libkf5globalaccelprivate5 libkf5idletime5
  libkf5jobwidgets-data libkf5jobwidgets5 libkf5kcmutils-data
  libkf5kcmutils5 libkf5kiocore5 libkf5kiontlm5 libkf5kiowidgets5
  libkf5newstuff-data libkf5newstuff5 libkf5newstuffcore5
  libkf5package-data libkf5package5 libkf5plasma5 libkf5quickaddons5
  libkf5solid5 libkf5solid5-data libkf5sonnet5-data libkf5sonnetcore5
  libkf5sonnetui5 libkf5textwidgets-data libkf5textwidgets5
  libkf5waylandclient5 libkf5waylandserver5 libkf5xmlgui-bin
  libkf5xmlgui-data libkf5xmlgui5 libkscreenlocker5
  libkwin4-effect-builtins1 libkwineffects11 libkwinglutils11
  libkwinxrenderutils11 libqgsttools-p1 libqt5designer5 libqt5help5
  libqt5multimedia5 libqt5multimedia5-plugins libqt5multimediaquick-p5
  libqt5multimediawidgets5 libqt5quickwidgets5 libxcb-composite0
  libxcb-cursor0 libxcb-damage0 os-prober python3-dbus.mainloop.pyqt5
  python3-icu python3-pam python3-pyqt5 python3-pyqt5.qtsvg
  python3-pyqt5.qtwebkit python3-sip
  qml-module-org-kde-kquickcontrolsaddons qml-module-qtmultimedia
  qml-module-qtquick2 rdate tasksel tasksel-data
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 86 not upgraded.
gautham@gautham-desktop:~$ gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=640,height=480,framerate=30/1 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvoverlaysink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
Additional debug info:
gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-negotiated (-4)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
gautham@gautham-desktop:~$ $ gst-launch-1.0 nvv4l2camerasrc device=/dev/video0 ! video/x-raw(memory:NVMM),format=UYVY,width=640,height=480,framerate=30/1 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvoverlaysink
bash: syntax error near unexpected token `('

I searched and found that nvidia has nvjpegdec format ; when I used it , I got the below output

gautham@gautham-desktop:~$ gst-launch-1.0 v4l2src device=/dev/video0 ! "image/jpeg,width=680,height=720, framerate=30/1" ! nvjpegdec ! video/x-raw ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvoverlaysink -e
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data stream error.
Additional debug info:
gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming stopped, reason not-negotiated (-4)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

Bump !!!

Hi,
Looks like the camera supports only MJPEG but not sure the width, height, framerate. You may run with –list-formats-ext and set exact width, height, framerate in the gstreamer pipeline.

Thankyou for replying ,but in index 1 it shows YUYV format when I used the below command

gautham@gautham-desktop:~$ v4l2-ctl -d /dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'MJPG' (compressed)
	Name        : Motion-JPEG

	Index       : 1
	Type        : Video Capture
	Pixel Format: 'YUYV'
	Name        : YUYV 4:2:2

gautham@gautham-desktop:~$ v4l2-ctl -d /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'MJPG' (compressed)
	Name        : Motion-JPEG
		Size: Discrete 680x720
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 480x640
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 416x720
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 640x480
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 320x240
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 240x320
			Interval: Discrete 0.033s (30.000 fps)

	Index       : 1
	Type        : Video Capture
	Pixel Format: 'YUYV'
	Name        : YUYV 4:2:2
		Size: Discrete 680x720
			Interval: Discrete 0.100s (10.000 fps)
		Size: Discrete 480x640
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 416x720
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 640x480
			Interval: Discrete 0.040s (25.000 fps)
		Size: Discrete 320x240
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 240x320
			Interval: Discrete 0.033s (30.000 fps)

Hi,
It supports 640x480p25 instead of 640x480p30. Setting frame rate to 25fps should work:

$ gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=640,height=480,framerate=25/1 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvoverlaysink