0
点赞
收藏
分享

微信扫一扫

用Opencv实现以‘H‘‘2‘‘6‘‘4‘格式录制并预览摄像机视频代码

E_topia 2022-01-24 阅读 42
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
VideoCapture cam(0);//到开摄像头
if (!cam.isOpened())
{
cout << "cam open failed !" << endl;
getchar();
return -1;

}
cout << "cam open success !" << endl;
namedWindow("cam");
Mat img;
VideoWriter vw;//生成视频流对象
int fps = cam.get(CAP_PROP_FPS);
if (fps <= 0)fps = 25;
vw.open("D:/tupian/1out.avi", VideoWriter::fourcc('X', '2', '6', '4'), fps,
Size(cam.get(CAP_PROP_FRAME_WIDTH), cam.get(CAP_PROP_FRAME_HEIGHT)));//创建视频文件
if (!vw.isOpened())
{
cout << "VideoWriter open failed !" << endl;
getchar();
return -1;
}
cout << "VideoWriter open failed !" << endl;

for (;;)
{
cam.read(img);
if(img.empty())break;
imshow("cam", img);
vw.write(img);//将画面写入该文件下
if(waitKey(5)=='q')break;

}


waitKey(0);
return 0;

}
举报

相关推荐

0 条评论