opencv提取视频之后存成图片

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
	VideoCapture cap("F:\\BaiduyunDowoload\\train\\6.mp4");
	//
	long totalFrameNum = cap.get(CV_CAP_PROP_FRAME_COUNT);
	cout << "total frame" << totalFrameNum << endl;
	Mat frame;
	bool flags = true;
	long currentFrame = 0;
	//namedWindow("src");
	while (flags)
	{
		cap.read(frame);
		//imshow("src",frame);
		stringstream str;
		str << "cqh" << currentFrame << ".jpg";
		cout << "dealing " << currentFrame << "frame" << endl;
		printf("\n");
		if (currentFrame % 30 == 0)
		{ 
			imwrite("F:\\BaiduyunDowoload\\train\\pic\\6\\" +str.str(), frame);
		}
			

		if (currentFrame>=totalFrameNum)
		{
			flags = false;
		}
	
		currentFrame++;

	}
	
	cap.release();
	waitKey(0);
	return 0;
	//system("pause");
}


出现错误


百度了好多原因,终于找到了原因:

在debug模式下存储图片只能存.bmp文件格式

在release模式下可以存储.jpg等格式

我存储的图片格式是.jpg格式所有需要调到Release模式下,

此时当然在配置opencv是也需要配置Release下的属性

有d的是Debug,没d的是Release

猜你喜欢

转载自blog.csdn.net/leo_whj/article/details/78901185