С++ opencv读取视频提取图片并保存

С++ opencv读取视频提取图片并保存

读取本地视频,获取前50帧的图像并保存图片

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>using namespace std;
using namespace cv;int main()
{//Open videoVideoCapture capture("C:\\Users\\10985\\source\\repos\\CVDemo01\\video.mp4");//Check whether it is opened normally: when successfully opened, isOpened returns trueif (!capture.isOpened())cout << "Video reading error !" << endl;//Set start frame()int frameToStart = 1;capture.set(CV_CAP_PROP_POS_FRAMES, frameToStart);int frameToStop = 50;//Carry the image of each frameMat frame;//Use while loop to read frames//currentFrame is a variable that controls the end of the loop after reading the specified frame in the loop bodyint currentFrame = frameToStart;while (currentFrame <= frameToStop){//Read next frameif (!capture.read(frame)){cout << "Fail to read" << endl;return -1;}stringstream str;str << "C:/Users/10985/source/repos/CVDemo01/test01_pictures/" << currentFrame << ".png";   /*Picture storage location*/  cout << str.str() << endl;imwrite(str.str(), frame);currentFrame++;}//Close video filecapture.release();return 0;
}

 结果文件test01_pictures

 

发布者:admin,转转请注明出处:http://www.yc00.com/news/1700319160a1000140.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信