tx1 opencv3.1 cannot open camera

the error msg is
VIDEOIO ERROR: libv4l unable to ioctl VIDIOCSPICT

what’s the problem

You’ll probably need to post the command which produced the error.

@linuxdev, I uses the OpenCV3.1 test code in l4t 24.1, the main is:
VideoCapture cap(-1);
before that, i compile the OpenCV3.1 from source with cmake according to
https://devtalk.nvidia.com/default/topic/917386/jetson-tx1/usb-3-0-port-unstable-on-jetson-tx1-/post/4835793/#4835793
the main part i think is :
cmake -DWITH_CUDA=ON -DCUDA_ARCH_BIN=“5.3” -DCUDA_ARCH_PTX="" -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCUDA_FAST_MATH=ON -DCMAKE_INSTALL_PREFIX=/home/ubuntu/opencv-3.1.0 …

Hello,
What’s camera you are using?
for TX1 on-board camera, you need use GST pipeline. Refer to https://devtalk.nvidia.com/default/topic/943129/jetson-tx1/highgui-error-v4l-v4l2-while-opening-camera-with-opencv4tegra-l4t-r24/post/4921383/#4921383
for USB camera, just specify the correct id. You can paste your full test code.

br
ChenJian

Hello, ChenJian
I’m using TX1 on-board camera in ros.
My code is:

int main( int argc, char **argv )
{
  ros::init( argc, argv, "send_image" );

  ros::NodeHandle n;

  cv::VideoCapture capture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480,format=(string)I420, framerate=(fraction)120/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink");
  // cv::VideoCapture capture(1);
  
  if( not capture.isOpened() )
  {
    ROS_ERROR_STREAM(
      "Failed to open camera "
    );
    ros::shutdown();
  }
}

I has another usb camera on board, and the error msg is:

Socket read error. Camera Daemon stopped functioning.....
0:00:00.360139323  7246       0x648aa0 ERROR            nvcamerasrc /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvcamera/gstnvcamerasrc.cpp:2374:gst_nvcamera_open:<nvcamerasrc0> REQ_NVCAM_CREATE_SESSION to camera_daemon failed

gst_nvcamera_open() failed ret=0
0:00:00.360269166  7246       0x648aa0 WARN                 basesrc gstbasesrc.c:3584:gst_base_src_activate_push:<nvcamerasrc0> Failed to start in push mode
0:00:00.360295729  7246       0x648aa0 WARN                GST_PADS gstpad.c:994:gst_pad_set_active:<nvcamerasrc0:src> Failed to activate pad

(send_image:7246): GStreamer-CRITICAL **: 
Trying to dispose element capsfilter2, but it is in PAUSED instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(send_image:7246): GStreamer-CRITICAL **: 
Trying to dispose element capsfilter1, but it is in PAUSED instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(send_image:7246): GStreamer-CRITICAL **: 
Trying to dispose element capsfilter0, but it is in PAUSED instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(send_image:7246): GStreamer-CRITICAL **: 
Trying to dispose element nvvconv0, but it is in PAUSED instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(send_image:7246): GStreamer-CRITICAL **: 
Trying to dispose element nvcamerasrc0, but it is in READY instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(send_image:7246): GStreamer-CRITICAL **: 
Trying to dispose element pipeline0, but it is in READY instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

OpenCV Error: Unspecified error (GStreamer: unable to start pipeline
) in cvCaptureFromCAM_GStreamer, file /home/ubuntu/src/opencv-3.1.0/modules/videoio/src/cap_gstreamer.cpp, line 818
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/ubuntu/src/opencv-3.1.0/modules/videoio/src/cap_gstreamer.cpp:818: error: (-2) GStreamer: unable to start pipeline
 in function cvCaptureFromCAM_GStreamer

Aborted

Hello, suki_bean:
Would you please run a simple GST pipeline first to make sure that nvcamera plugin works?

br
Chenjian

Hello, Chenjian.
Thanks to your solution, it works actually.
However, I’m puzzled,
because i only unplug the usb camera,
when i insert again, the errors display.
No matter the ros code!

That’s weird. I tried in my side.
it works with or without USB camera.
nvcamerasrc is a plug-in for Jetson on-board camera.

you can test the gst pipeline first.

note that for 24.2, on-board camera also has v4l2 interface, which output bayer raw data. don’t mess it with usb camera. Refer to related document for details.

br
Chenjian

Hi Chenjian,
In terminal, I put the code:

gst-launch-1.0 nvcamerasrc fpsRange="30.0 30.0" ! 'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)30/1' ! nvtee ! nvvidconv flip-method=2 ! 'video/x-raw(memory:NVMM), format=(string)I420' ! nvoverlaysink -e

tx1 works without USB camera, but not with it.
And the error msg:

0:00:00.042851614  3644       0x58e490 WARN                     omx /dvs/git/dirty/git-master_linux/external/gstreamer/gst-omx/omx/gstomx.c:2839:plugin_init: Failed to load configuration file: Valid key file could not be found in search dirs (searched in: /home/ubuntu/.config:/etc/xdg as per GST_OMX_CONFIG_DIR environment variable, the xdg user config directory (or XDG_CONFIG_HOME) and the system config directory (or XDG_CONFIG_DIRS)
Setting pipeline to PAUSED ...
Inside NvxLiteH264DecoderLowLatencyInitNvxLiteH264DecoderLowLatencyInit set DPB and MjstreamingInside NvxLiteH265DecoderLowLatencyInitNvxLiteH265DecoderLowLatencyInit set DPB and MjstreamingSocket read error. Camera Daemon stopped functioning.....
0:00:00.336936614  3644       0x58e490 ERROR            nvcamerasrc /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvcamera/gstnvcamerasrc.cpp:2374:gst_nvcamera_open:<nvcamerasrc0> REQ_NVCAM_CREATE_SESSION to camera_daemon failed

gst_nvcamera_open() failed ret=0
0:00:00.337012135  3644       0x58e490 WARN                 basesrc gstbasesrc.c:3584:gst_base_src_activate_push:<nvcamerasrc0> Failed to start in push mode
0:00:00.337032135  3644       0x58e490 WARN                GST_PADS gstpad.c:994:gst_pad_set_active:<nvcamerasrc0:src> Failed to activate pad
ERROR: Pipeline doesn't want to pause.
Setting pipeline to NULL ...
Freeing pipeline ...

Hello, suki_bean:
As I mentioned, I cannot reproduce your issue in my side. So only some suggestions.

  1. Can you try with another USB camera? or all usb camera will conflict with nvcamerasrc?
  2. with USB camera in, can you capture /var/log/syslog as well? it may provide some useful log.

BTW: R24.2 is on-line. Please update SDK with Jetpack 2.3 for the testing.

br
ChenJian