errors to enable TX1 on-board camera in opencv

Sir
I use Nsight Eclipse Edition with opencv to run target tracking programs.
The problem is that I cannot enable the on-board camera, while the pipeline example has been successful, like “gst-launch-1.0 nvcamerasrc ! ‘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”.
but the program get the error like:[b]GStreamer: Error opening bin: no element “nvcamerasrc”
The opencv proogram is :
int main()
{
VideoCapture cap(" nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480,format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink");
waitKey(50);
if (!cap.isOpened())
{
printf(“camera did not open\n”);
return -1;
}
for(;;)
{
Mat frame;
cap >> frame;
imshow(“original”, frame);
waitKey(10);
}
return 0;
}

BTW: I use opencv 3.1.0, and flash my TX1 with JetPack 2.3.1(without opencv)

You may check this post: https://devtalk.nvidia.com/default/topic/1001696/jetson-tx1/failed-to-open-tx1-on-board-camera/post/5117370/#5117370

I resolved the problem! My problem is created by the gstreamer-1.0. I fix it ,then the program work well. No need to add the gstreamer in the “include path” or “library”.

Hello, I am experiencing the exact same issue and have been trying to fix it for a while now. Would you be able to explain how you fixed gstreamer-1.0? I can also run it perfectly from a terminal, but when I try to open the video stream in opencv it fails saying:

GStreamer: Error opening bin: no element "nvcamerasrc"

I figured out what was wrong. I built opencv using the following configuration (the green coloured text should just be normal):

cmake \
     -DCMAKE_BUILD_TYPE=Release \
     -DCMAKE_INSTALL_PREFIX= /usr \
     -DBUILD_PNG=OFF \
     -DBUILD_TIFF=OFF \
     -DBUILD_TBB=OFF \
     -DBUILD_JPEG=OFF \
     -DBUILD_JASPER=OFF \
     -DBUILD_ZLIB=OFF \
     -DBUILD_EXAMPLES=ON \
     -DBUILD_opencv_java=OFF \
     -DBUILD_opencv_python2=ON \
     -DBUILD_opencv_python3=OFF \
     -DENABLE_PRECOMPILED_HEADERS=OFF \
     -DWITH_OPENCL=OFF \
     -DWITH_OPENMP=OFF \
     -DWITH_FFMPEG=ON \
     -DWITH_GSTREAMER=ON \
     -DWITH_GSTREAMER_0_10=OFF \
     -DWITH_CUDA=ON \
     -DWITH_GTK=ON \
     -DWITH_VTK=OFF \
     -DWITH_TBB=ON \
     -DWITH_1394=OFF \
     -DWITH_OPENEXR=OFF \
     -D WITH_LIBV4L=ON \
     -D WITH_V4L=OFF \
     -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \
     -DCUDA_ARCH_BIN=5.3 \
     -DCUDA_ARCH_PTX="" \
     -DINSTALL_C_EXAMPLES=ON \
     -DINSTALL_TESTS=OFF \
     -DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \
     ../opencv

Then I built the library on the TX1 using

make -j4

then

make install

. I also had to apply a couple of cherry picks to my local git repo when I was getting the opencv source code version 3.1.0. I followed the installation process at http://docs.opencv.org/3.2.0/d6/d15/tutorial_building_tegra_cuda.html for the most part (replace their cmake config command with the one above and it should work). Also, during the configuration step, make sure that all the libraries related to gstreamer are FOUND. Make sure you install the gstreamer-1.0 libraries. It doesn’t matter whether or not you have the -0.10 libraries installed.

Previously I was using

_DWITH_GSTREAMER_0_10=ON

which I think caused issues when opencv tried to access the video. I am a beginner when it comes to gstreamer (and linux in general), so i might not be interpreting the results correctly. But it does work now using the following code:

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

using namespace std;
using namespace cv;

int main()
{
	cout << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << endl;

	const char* gst =  "nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)I420, framerate=(fraction)120/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)I420 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink";

    	cv::VideoCapture cap(gst);
    
	//const char* env = "GST_DEBUG=*:3";
	//putenv((char*)env);	

	if(!cap.isOpened()) { // check if we succeeded
		cerr << "Failed to open camera " << endl;
		return -1;
	}

	for(;;)
	{
		
		Mat frame;
		cap >> frame; // get a new frame from camera
		imshow("original", frame);
		waitKey(1);
	}
	// the camera will be deinitialized automatically in VideoCapture destructor
	cap.release();
	return 0;
}

I think the problem is something wrong with your gstreamer-1.0 library, I copy the gstreamer-1.0 library files in another TX1, then it works! If there’s nothing important you can flash the TX1,and it has the library already ,no need to install the gstreamer again.