Skip to content

Instantly share code, notes, and snippets.

@kuasha
Created December 19, 2016 23:18
Show Gist options
  • Save kuasha/f768c2d92895298b0aaba6bc12c2c601 to your computer and use it in GitHub Desktop.
Save kuasha/f768c2d92895298b0aaba6bc12c2c601 to your computer and use it in GitHub Desktop.
// Tested on Raspberry Pi 3
#include<stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
int camid = 0;
FILE *fp = fopen("config.txt", "rt");
if(fp){
fscanf(fp, "%d", &camid);
fclose(fp);
}
cout << "Selecting camera " << camid << endl;
// Load input video
cv::VideoCapture input_cap(camid);
if (!input_cap.isOpened())
{
std::cout << "!!! Input video could not be opened" << std::endl;
return -1;
}
// Setup output video
cv::VideoWriter output_cap(argv[1],
CV_FOURCC('D','I','V','X'),
29,
cv::Size(640,480));
if (!output_cap.isOpened())
{
std::cout << "!!! Output video could not be opened" << std::endl;
return -1;
}
// Loop to read from input and write to output
cv::Mat frame;
while (true)
{
if (!input_cap.read(frame))
break;
output_cap.write(frame);
}
input_cap.release();
output_cap.release();
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment