Skip to content

Instantly share code, notes, and snippets.

@ivder
Last active August 1, 2019 04:36
Show Gist options
  • Save ivder/09ad727967c52b594df5f0575e1e98e5 to your computer and use it in GitHub Desktop.
Save ivder/09ad727967c52b594df5f0575e1e98e5 to your computer and use it in GitHub Desktop.
Opening GoPro with AverMedia ExtremeCap UVC, e-cons , and on board camera on Jetson TX2
/*
Terminal gstreamer pipeline
GoPro - UVC
gst-launch-1.0 v4l2src device="/dev/video1" ! "video/x-raw,width=1920,height=1080,format=YUY2" ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvvidconv ! xvimagesink
E-cons camera
gst-launch-1.0 v4l2src device="/dev/video1" ! "video/x-raw,width=1920,height=1080,format=UYVY" ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvoverlaysink
Jetson on board camera
gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! 'video/x-raw(memory:NVMM),width=1920, height=1080, framerate=30/1, format=NV12' ! nvoverlaysink -ev
*/
#include "opencv2/opencv.hpp"
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char *argv[]){
// Create a VideoCapture object and open the input file
// If the input is the web camera, pass 0 instead of the video file name
string gst;
string idx = argv[1];
string cam = argv[2];
//GoPro UVC Camera format=YUY2
if (cam == "1")
gst = "v4l2src device=/dev/video"+idx+" ! video/x-raw, width=(int)1920, height=(int)1080, format=(string)YUY2 ! videoconvert ! appsink";
//E-Con Camera format=UYVY
else if (cam == "2")
gst = "v4l2src device=/dev/video"+idx+" ! video/x-raw, width=(int)1920, height=(int)1080, format=(string)UYVY ! videoconvert ! appsink";
//Jetson On board Camera format = nvarguscamerasrc (nvcamerasrc is deprecated in Jetpack 4.2)
else if (cam == "3")
gst = "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)NV12, framerate=(fraction)24/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink";
VideoCapture cap(gst); //Choose gst pipeline
if(!cap.isOpened()){
cout << "Error opening video stream or file" << endl;
return -1;
}
while(1){
Mat frame;
cap >> frame;
if (frame.empty())
break;
imshow( "Frame", frame );
char c=(char)waitKey(25);
if(c==27)
break;
}
cap.release();
destroyAllWindows();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment