Capture video with opencv2.4.11

My opencv version is 2.4.11, and when I was followed by the instructions to run a test using opencv to capture the video
#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");  
  //VideoCapture cap("fakesrc ! videoconvert ! appsink");  
  if (!cap.isOpened())  
    {  
      cout << "Failed to open camera." << endl;  
      return -1;  
    }  
  
  for(;;)  
    {  
      Mat frame;  
      cap >> frame;  
      imshow("original", frame);  
      //waitKey(1);  
      if(waitKey(30) >= 0)  
      break;  
    }  
  return 0;  
  //cap.release();  
}  

The result was “Failed to open the camera”. My camera was the onboard camera and I assume that the driver was installed because I could get the video by the instruction “nvgstcapture-1.0”. My storage is not enough to install opencv3.1 so I’m wondering whether I should uninstall the opencv 2.4. Any help is greatly appreciated.

Hi Aust1n,

We have some threads discussing about enable gstreamer in opencv. Currently, only opencv 3.x is verified that support gstreamer1.0. You could try to add “-DWITH_GSTREAMER=ON” in cmake and see if it works on opencv2.4.11.

Thread for 2.4.9
https://devtalk.nvidia.com/default/topic/1016103/opencv-python-and-gpu-on-tk1/

How much does your storage have?

Only 170MB left, I’ve tried to add that, but it still not works.

An alternative would be to capture video raw data with (low-level) V4L2 API and then convert the data into cv::Mat. That would work with the stock OpenCV4Tegra provided by NVIDIA.