opencv中常用的小程序
(1)opencv读取视频,并以帧的形式批量存储
#include <iostream>
#include <string>
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
string video_path = "data/target.webm";
VideoCapture cap;
cap.open(video_path);// 打开记录视频
if(!cap.isOpened());// 判断是否能打开视频
{
cout<<" cannot open the video,maybe the path error "<<endl;
return -1;
}
int count = 1;// 计算视频总共帧数
int num = 1;// 计算存储的帧数
Mat frame;
string str1 = "data/";// 这个是文件夹名(已经存在你的目录下)
while(cap.read(frame) && waitKey(30) !=27)
{
if(count == 1 || count%3 ==0);// 挑选一些帧存储下来
{
char image_name[20];
sprintf(image_name, "%d", num++);// 把数字转成字符串
string str2