opencv将视频序列转换为图像序列保存

来源:互联网 发布:mysql 查询赋值给变量 编辑:程序博客网 时间:2024/05/24 02:46

          在视频处理中,常常需要对视频序列进行转换,一方面是为了处理的方便,另一方面也是项目的要求。对视频序列转换为图像帧的好像可以逐渐的对图片序列进行必要的事前处理,比如进行标注、先验信息的提取等。这里借用Opencv平台库简单的视频将一个输入视频序列转换为图片序列的程序。

int _tmain(int argc, char* argv[]){const string strFilePath="D:\\testVideo\\person.avi"; VideoCapture cap;Mat frame;int frmNum = 0;char _path[255];char prefix[]="D:\\images\\";char postfix[]=".jpg";cap.open(strFilePath);if( !cap.isOpened() ){printf("can not open camera or video file\n");return -1;}for (;;){frmNum++;cap>>frame;if (frame.empty()){printf("Video File Finished !\n");return -1;}memset(_path,'\0',sizeof(char)*255);sprintf(_path,"%sframe_%04d%s",prefix,frmNum,postfix);imwrite(_path,frame);imshow("video",frame);waitKey(10);}printf("Video File Finished !\n");system("pause");return 0;}

原创粉丝点击