void extract_frames(const string &videoFilePath,vector& frames){ try{ //open the video file VideoCapture cap(videoFilePath); // open the video file if(!cap.isOpened()) // check if we succeeded return -1; //cap.get(CV_CAP_PROP_FRAME_COUNT) contains the number of frames in the video; for(int frameNum = 0; frameNum < cap.get(CV_CAP_PROP_FRAME_COUNT);frameNum++) { Mat frame; cap >> frame; // get the next frame from video frames.push_back(frame); } } catch( cv::Exception& e ){ const char* err_msg = e.what(); std::cout << "exception caught: " << err_msg << std::endl; } } void save_frames(vector& frames, const string& outputDir){ vector compression_params; compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params.push_back(100); for(std::vector::iterator frame = frames.begin(),frameNumber=0; frame != frame.end(); ++frame){ string filePath = outputDir + to_string(static_cast(frameNumber))+ ".jpg"; imwrite(filePath,*frame,compression_params); } }