I’m trying to get the following code snippet to open a stream to the onboard camera, but can’t.
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
VideoCapture cap("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,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");
if (!cap.isOpened())
{
cout << "Failed to open camera." << endl;
return -1;
}
for(;;)
{
Mat frame;
cap >> frame;
imshow("original", frame);
waitKey(1);
}
cap.release();
}
The snippet was taking from the following post: https://devtalk.nvidia.com/default/topic/943129/jetson-tx1/highgui-error-v4l-v4l2-while-opening-camera-with-opencv4tegra-l4t-r24/post/4921383/#4921383.
I built the test program against opencv 3.1.0 with the following:
g++ -o test -I /usr/include/opencv -Wall test.cpp -L/usr/lib -l:libopencv_core.so.3.1.0 -l:libopencv_videoio.so.3.1.0 -l:libopencv_imgproc.so.3.1.0 -l:libopencv_highgui.so.3.1.0
.
The program doesn’t crash, but simply fails to open the video capture, and writes the output “Failed to open camera” to the console.
I built opencv 3.1 from source using the procedure given here: http://docs.opencv.org/master/d6/d15/tutorial_building_tegra_cuda.html
It’s also worth noting that using a simple test gstreamer pipe string like:
VideoCapture cap("fakesrc ! videoconvert ! appsink");
also does not work
I’m using L4T 24.2.1, Ubuntu 16.04 (using JetPack 2.3.1) Any help is greatly appreciated.