#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
cv::VideoCapture iv;
iv.open(0);
if(!iv.isOpened())
{
cout<<"Could not open reference "<<endl;
return -1;
}
else
{
cout<<"usb camera success "<<video_dir<<endl;
}
Mat src;
iv >> src;
bool isColor = (src.type() == CV_8UC3);
VideoWriter writer;
int codec = VideoWriter::fourcc('M', 'J', 'P', 'G'); // 选择视频的格式
double fps = 10.0;//保存的帧率,如果想要保存后的视频时间和录的时间一样,此处fps需要和相机帧率保持一致
string filename = "/home/robooster/camera.mp4"; // 视频保存的路径
writer.open(filename, codec, fps, src.size(), isColor);
// 检查视频是否读取出来
if (!writer.isOpened())
{
cerr << "Could not open the video file\n";
return -1;
}
while (1)
{
iv >> src;
writer.write(src);
}
}