Xavier OpenCV issue (videocapture, nvarguscamerasrc)

Hello, I am working on displaying images using CSI camera(e-CAM20_CUXVR, e-con systems) which is applicable to Xavier. I want to use this camera to stream multi-camera images on OpenCV.

First of all, based on GStreamer, I ran the following command on terminal with single camera and it works!

gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! "video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12" ! nvoverlaysink -e

So I coded it to stream in OpenCV based on that command.
But I had a “camera open error” problem.

#include <iostream>
#include <opencv2/opencv.hpp>

int main(int argc, char** argv)
{
    cv::Mat frame;
    bool frame_flag = false;


    const char* cam = "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)NV12 ! videoconvert ! video/x-raw, format=(string)BGR ! nvoverlaysink -e";
    cv::VideoCapture cap(cam);
    if(!cap.isOpened())
    {
        std::cout<<"Failed to open the camera" <<std::endl;
        return -1;
    }
}

Please let me know what I coded wrong.
The additional information is written below

ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'GB10'
	Name        : 10-bit Bayer GBGB/RGRG
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)

	Index       : 1
	Type        : Video Capture
	Pixel Format: 'GB12'
	Name        : 12-bit Bayer GBGB/RGRG
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)

This is an additional question.(You don’t have to answer this.)
I tried multi-streaming as below command and it failed. I want you to tell me what the problem is.

gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! "video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12" ! nvoverlaysink -e nvarguscamerasrc sensor-id=1 ! "video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12" ! nvoverlaysink -e nvarguscamerasrc sensor-id=2 ! "video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12" ! nvoverlaysink -e nvarguscamerasrc sensor-id=3 ! "video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12" ! nvoverlaysink -e

Error message

nvdc: open: Too many open files
nvdc: failed to open '/dev/tegra_dc_2'.
NvxBaseWorkerFunction[2575] comp OMX.Nvidia.std.iv_renderer.overlay.yuv420 Error -2147479552

Thanks in advance!

First, the gstreamer pipeline you are using in opencv is not correct.
OpenCV only provides limited interface to get the frame from gstreamer. You have to use appsink to get frame as below link.

Second, Please note that such method does not use nvoverlaysink to preview. To preview something, you have to use native opencv function like imshow(), which is X11 based.

As for your multi-pipeline issue, it is a common question on forum.

[url]nvoverlaysink issue on TX2 - Jetson TX2 - NVIDIA Developer Forums