利用opencv读取摄像头并保存视频



#include  
#include  
#include  
using namespace cv;
using namespace std;
int main()
{
//打开摄像头  
VideoCapture captrue(0);
//视频写入对象  
VideoWriter write;
//写入视频文件名  
string outFlie = "E://fcq.avi";
//获得帧的宽高  
int w = static_cast(captrue.get(CV_CAP_PROP_FRAME_WIDTH));
int h = static_cast(captrue.get(CV_CAP_PROP_FRAME_HEIGHT));
Size S(w, h);
//获得帧率  
double r = captrue.get(CV_CAP_PROP_FPS);
//打开视频文件,准备写入  
write.open(outFlie, -1, r, S, true);
//打开失败  
if (!captrue.isOpened())
{
return 1;
}
bool stop = false;
Mat frame;
//循环  
while (!stop)
{
//读取帧  
if (!captrue.read(frame))
break;
imshow("Video", frame);
//写入文件  
write.write(frame);
if (waitKey(10) > 0)
{
stop = true;
}
}
//释放对象  
captrue.release();
write.release();
cvDestroyWindow("Video");
return 0;
}

你可能感兴趣的:(C++)