saving an image sequence from video using opencv2

前端 未结 3 1002
青春惊慌失措
青春惊慌失措 2021-01-15 16:48

Newbie question and yes I have spent a lot of time sifting through similar questions and Answers with no luck.

What I am trying to do is save frames from a video fil

3条回答
  •  不知归路
    2021-01-15 17:21

    This is my code... I tryed a lot and finally made it this is c++ using opencv 3... hope it works

    #include "opencv2/opencv.hpp"
    #include 
    #include 
    
    
    using namespace cv;
    using namespace std;
    
     Mat frame,img;
        int counter;
    
    int main(int,char**)
       {
            VideoCapture vid("video3.avi");
    
    
    while (!vid.isOpened())
    {
        VideoCapture vid("video2.MOV");
        cout << "charging" << endl;
        waitKey(1000);
    
    }
    
    cout << "Video opened!" << endl;
    
    while(1)
    {
        stringstream file;
    
        vid.read(frame);
        if(frame.empty()) break;
        file << "/home/pedro/workspace/videoFrame/Debug/frames/image" << counter << ".jpg";
        counter++;
        imwrite(file.str(),frame);
    
        char key = waitKey(10);
     if ( key == 27)
     {break;}
    
    
    }
    
    
    } 
    

提交回复
热议问题