opencv截取视频图片保存

#include 
#include 
using namespace std;
using namespace cv;
int main()
{
    VideoCapture capture("E:\\videos\\bdb.mp4");

    //设置开始帧()  
    int frameToStart = 0;
    //设置结束帧  
    int frameToStop = 70;
    int count=capture.get(CV_CAP_PROP_FRAME_COUNT);
    //cout << count << endl;
    //定义一个用来控制读取视频循环结束的变量  
    bool stop = false;

    string image_path = "E:\\videos\\";
    Mat ma;
    string image_name;

    long currentFrame = frameToStart;

    while (!stop){
            //文件名
            stringstream ss;
            ss << currentFrame;
            string s1 = ss.str();
            image_name = image_path + s1;
            cout << image_name << endl;

            //VideoCapture 类提供视频帧处理
            capture.grab();
            capture.retrieve(ma);

            imshow(image_name, ma);
            imwrite(image_name+".jpg", ma);
            waitKey(10);

            if (currentFrame > frameToStop)
            {
                stop = true;
            }
            currentFrame++;
    }
    capture.release();
    return 0;
}

你可能感兴趣的:(杂七杂八)