С++ 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条)