Getting Started Course - "Could not initialize camera" inside DLI container

I’m using a Jetson Nano Dev Kit for the first time, starting with the “Getting Started with AI on Jetson Nano” Course (course-v1:DLI+S-RX-02+V2/)

When I try to connect to the USB camera from within the DLI container using command

camera = USBCamera(width=224, height=224, capture_width=640, capture_height=480, capture_device=0)

inside the Jupyter notebook “/hello_camera/usb_camera.ipynb” I get the follwing error message:

---------------------------------------------------------------------------
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)
<ipython-input-2-5a6744da9a88> in <module>
      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.

The camera is shown as /dev/video0 inside the container and in the host. I’ve read that the commands

export DISPLAY=:0
nvgstcapture-1.0

help to identify the problems but not sure what to make of the outputs and running them on the host looks like that:

nvidia@nvidia-desktop:~/nvdli-data$ export DISPLAY=:0
nvidia@nvidia-desktop:~/nvdli-data$ nvgstcapture-1.0
Encoder null, cannot set bitrate!
Encoder Profile = High
Supported resolutions in case of ARGUS Camera
  (2) : 640x480
  (3) : 1280x720
  (4) : 1920x1080
  (5) : 2104x1560
  (6) : 2592x1944
  (7) : 2616x1472
  (8) : 3840x2160
  (9) : 3896x2192
  (10): 4208x3120
  (11): 5632x3168
  (12): 5632x4224

Runtime ARGUS Camera Commands:

  Help : 'h'
  Quit : 'q'
  Set Capture Mode:
      mo:<val>
          (1): image
          (2): video
  Get Capture Mode:
      gmo
  Set sensor orientation:
      so:<val>
          (0): none
          (1): Rotate counter-clockwise 90 degrees
          (2): Rotate 180 degrees
          (3): Rotate clockwise 90 degrees
  Get sensor orientation:
      gso
  Set sensor mode:
      smo:<val> e.g., smo:1
  Get sensor mode:
      gsmo
  Set Whitebalance Mode:
      wb:<val>
          (0): off
          (1): auto
          (2): incandescent
          (3): fluorescent
          (4): warm-fluorescent
          (5): daylight
          (6): cloudy-daylight
          (7): twilight
          (8): shade
          (9): manual
  Get Whitebalance Mode:
      gwb
  Set Saturation (0 to 2):
      st:<val> e.g., st:1.25
  Get Saturation:
      gst
  Set Exposure Compensation (-2 to 2):
      ec:<val> e.g., ec:-2
  Get Exposure Compensation:
      gec
  Set Auto Whitebalance Lock:
      awbl:<val> e.g., awbl:0
  Get Auto Whitebalance Lock:
      awbl
  Set Auto Exposure Lock:
      ael:<val> e.g., ael:0
  Get Auto Exposure Lock:
      gael
  Set TNR Mode:
      tnrm:<val> e.g., tnrm:1
          (0): OFF
          (1): FAST
          (2): HIGH QUALITY
  Get TNR Mode:
      gtnrm
  Set TNR Strength (-1 to 1):
      tnrs:<val> e.g., tnrs:0.5
  Get TNR Strength:
      gtnrs
  Set EE Mode:
      eem:<val> e.g., eem:1
          (0): OFF
          (1): FAST
          (2): HIGH QUALITY
  Get EE Mode:
      geem
  Set EE Strength (-1 to 1):
      ees:<val> e.g., ees:0.5
  Get EE Strength:
      gees
  Set Auto Exposure Anti-Banding (0 to 3):
      aeab:<val> e.g., aeab:2
          (0): OFF
          (1): MODE AUTO
          (2): MODE 50HZ
          (3): MODE 60HZ
  Get Auto Exposure Anti-Banding:
      gaeab
  Set Gain Range:
      gr:<val><space><val> e.g., gr:1 16
  Get Gain Range:
      ggr
  Set Exposure Time Range:
      etr:<val><space><val> e.g., etr:34000 35000
  Get Exposure Time Range:
      getr
  Set ISP Digital Gain Range:
      dgr:<val><space><val> e.g., dgr:2 152
  Get ISP Digital Gain Range:
      gdgr
  Capture: enter 'j' OR
           followed by a timer (e.g., jx5000, capture after 5 seconds) OR
           followed by multishot count (e.g., j:6, capture 6 images)
           timer/multihot values are optional, capture defaults to single shot with timer=0s
  Start Recording : enter '1'
  Stop Recording  : enter '0'
  Video snapshot  : enter '2' (While recording video)
  Get Preview Resolution:
      gpcr
  Get Image Capture Resolution:
      gicr
  Get Video Capture Resolution:
      gvcr


Runtime encoder configuration options:

  Set Encoding Bit-rate(in bytes):
      br:<val> e.g., br:4000000
  Get Encoding Bit-rate(in bytes):
      gbr
  Set Encoding Profile(only for H.264):
      ep:<val> e.g., ep:1
          (0): Baseline
          (1): Main
          (2): High
  Get Encoding Profile(only for H.264):
      gep
  Force IDR Frame on video Encoder(only for H.264):
      Enter 'f'


No protocol specified
nvbuf_utils: Could not get EGL display connection
bitrate = 4000000
Encoder Profile = High
Encoder control-rate = 1
Encoder EnableTwopassCBR = 0
Opening in BLOCKING MODE
** Message: 17:18:20.330: <main:4674> iterating capture loop ....
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:740 No cameras available
NvMMLiteOpen : Block : BlockType = 4
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4
^C** Message: 17:20:34.207: <_intr_handler:4262> User Interrupted..

Terminating the camera pipeline ...
** Message: 17:20:34.281: <main:4684> Capture completed
** Message: 17:20:34.281: <main:4733> Camera application will now exit

Inside the container there’s no executable for nvgstcapture-1.0.

What could I do to resolve? Please explain for noobs, thanks!

Hi,
For USB cameras, we capture frame data through v4l2 interface. Please refer to the steps in Jetson Nano FAQ

Q: I have a USB camera. How can I launch it on Jetson Nano?

See if you can successfully run gstreamer command first.

Hi DaneLLL,

it didn’t work, and I’ve tried other approaches I could find to get a simple output, see below:

nvidia@nvidia-desktop:~$ v4l2-ctl -d0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'JPEG' (compressed)
        Name        : JFIF JPEG
                Size: Discrete 160x120
                Size: Discrete 320x240
                Size: Discrete 640x480

nvidia@nvidia-desktop:~$ gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,format=YUY2,width=640,height=480,framerate=10/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 ...

I was thinking that the format settings might be wrong but letting gst-launch determine them doesn’t work either.

nvidia@nvidia-desktop:~$ gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert! videoscale ! video/x-raw, width=640, height=480 ! autovideosink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
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)
Execution ended after 0:00:00.008087292
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
nvidia@nvidia-desktop:~$ nvgstcapture-1.0 --camsrc=0
Encoder null, cannot set bitrate!
Encoder Profile = High
Runtime USB Camera Commands:

[... generic help message displayed ...]

Cannot open display specified with DISPLAY environment variable

can't create window, Display NULL

** (nvgstcapture-1.0:10376): CRITICAL **: 16:14:54.675: <create_capture_pipeline:4051> can't set camera to playing


** (nvgstcapture-1.0:10376): CRITICAL **: 16:14:54.675: <main:4677> Capture Pipeline creation failed
** Message: 16:14:54.676: <main:4684> Capture completed
** Message: 16:14:54.676: <main:4733> Camera application will now exit

Hi,
Please try other USB cameras which can generate YUV422 frame data, such as YUYV(YUY2) or UYVY. This camera supports only JPEG and it may not work properly.

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