How to find read the contents of usb_camera.py in the Juperlab

Hello all.

I am trying to get the hello camera project to work with a USB camera. I’ve tested the camera and it works on other linux machines, shows up as video0, but wont run because of :

R---------------------------------------------------------------------------
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)
in
2
3 #TODO change capture_device if incorrect for your system
----> 4 camera = USBCamera(width=224, height=224, capture_width=640, capture_height=480, capture_device=0)

/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

Where do I find usb_camera.py locally, I’m guessing I need to change the dimensions declared inside?
the file location is at /usr/local/lib/python3.6/dist-packages/jetcam-0.0.0-py3.6.egg/jetcam/usb_camera.py but I can’t get past the .jetcam-0.0.0-py3.6.egg part in terminal.

Any ideas?

Hi @murray, you can change these arguments from the Jupyter notebook as opposed to needing to change the dimensions inside jetcam library:

from jetcam.usb_camera import USBCamera

#TODO change capture_device if incorrect for your system
camera = USBCamera(width=224, height=224, capture_width=640, capture_height=480, capture_device=0)

And if you run the commands below outside of container, it will let you know what image formats your camera supports:

$ sudo apt-get install v4l-utils
$ v4l2-ctl --device=/dev/video0 --list-formats-ext

Hi dusty_nv

I have tried a similar method and changed the image size in the notebook to suit, but the error was the same.

I will try with v4l2-ctl tomorrow.

The webcam I am using is a raspberry pi W and works as a plug and play webcam on my Linux machine and PC.

It shows up as a uva or maybe uvc device, perhaps that’s the problem?

Thanks @dusty_nv

I had previously use, lsusb -s 001:002 -v | egrep “Width|Height” which gave me less detail but the same camera sizes.

Just to be sure I changed the capture to be the same as the camera:
camera = USBCamera(width=640, height=480, capture_width=640, capture_height=480, capture_device=0)

But its still the same error.

So I tried :

  • guvcview
    Opening in BLOCKING MODE
    Segmentation fault (core dumped)

  • cheese
    Unable to init server: Could not connect: Connection refused

** (cheese:6695): ERROR **: 22:14:27.087: cheese-application.vala:86: Unable to initialize libcheese-gtk
Trace/breakpoint trap (core dumped)

  • ffplay /dev/video0
    Segmentation fault (core dumped)

These all work on Linux Mint machine, ffplay might have a hint with the terminal output?
Input #0, video4linux2,v4l2, from ‘/dev/video1’:B sq= 0B f=0/0
Duration: N/A, start: 36283.717558, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 640x360, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
[swscaler @ 0x7f9918066bc0] deprecated pixel format used, make sure you did set range correctly

Interestingly running v4l2-ctl on a Linux Mint machine gives 2 different video formats and the Nano only has MJPG?

From a Linux Mint machine
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 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 640x360
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.100s (10.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 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 640x360
		Interval: Discrete 0.033s (30.000 fps)
	Size: Discrete 1280x720
		Interval: Discrete 0.033s (30.000 fps)

From the Jetson Nano
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: ‘MJPG’ (compressed)
Name : Motion-JPEG
Size: Discrete 640x360
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 800x600
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 1024x768
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 1280x960
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 1920x1080
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 1536x864
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 1600x900
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 1600x1200
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.067s (15.000 fps)
An extract from dmesg on the Nano

12.415975] usb 1-2: New USB device found, idVendor=1d6b, idProduct=0104
[ 12.415981] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 12.415985] usb 1-2: Product: Piwebcam
[ 12.415988] usb 1-2: Manufacturer: Show-me Webcam Project
[ 12.415991] usb 1-2: SerialNumber: 100000000d2386db
[ 12.447822] cdc_acm 1-2:2.2: ttyACM0: USB ACM device
[ 12.448211] usbcore: registered new interface driver cdc_acm
[ 12.448215] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[ 12.450630] uvcvideo: Found UVC 1.00 device Piwebcam (1d6b:0104)
[ 12.455437] uvcvideo 1-2:2.0: Entity type for entity Processing 2 was not initialized!
[ 12.463774] uvcvideo 1-2:2.0: Entity type for entity Camera 1 was not initialized!
[ 12.471755] input: Piwebcam as /devices/70090000.xusb/usb1/1-2/1-2:2.0/input/input4
[ 12.471970] usbcore: registered new interface driver uvcvideo
[ 12.471973] USB Video Class driver (1.1.1)

Perhaps a similar issue here but none of these fixes worked @DaneLLL

Reinstalling uvcdynctrl didnt work either.

any idea why its not working on a Nano but does on other Linux machines?

Thanks

Hi,
Looks like it only shows MJPEG on Jetson Nano. Please try gstreamer pipeline and check if you can see view preview:

$ export DISPLAY=:0
$ gst-launch-1.0 v4l2src ! image/jpeg,width=640,height=480,framerate=30/1 ! jpegparse ! jpegdec ! videoconvert ! xvimagesink

And USBCamera should work with YUV422 format such as YUYV or UYVY. If the camera dies not show YUYV on Jetson Nano, probably certain driver is missing. It looks to be about USB ACM. May try this:
Xavier NX not recognizing certain ACM USB device - #8 by DaneLLL

Hi DaneLLL.

I tried the gst-launch and got this:

Setting pipeline to PAUSED …
Invalid MIT-MAGIC-COOKIE-1 keyERROR: 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 took a look a the link, but it pointed to another link and I think it was really about rebuilding the kernel?
What part of the link was I supposed to read.

Thanks

Hi,
You probably don’t set export DISPLAY:=0(or 1), so it shows the error about display. If this works you can try to customize the app to run MJPEG decoding.

Without customizing the app, would need to check why YUYV is not shown. The error in enumeration looks related to ACM, so it might help to enable the configs and rebuild kernel.

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