Last active
July 13, 2023 18:48
-
-
Save itsrifat/66b253db2736b23f247c to your computer and use it in GitHub Desktop.
Revisions
-
itsrifat revised this gist
Nov 11, 2014 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,11 +4,11 @@ This functions opens a video file and extracts the frames and put them into a ve void extract_frames(const string &videoFilePath,vector<Mat>& frames){ try{ //open the video file VideoCapture cap(videoFilePath); // open the video file if(!cap.isOpened()) // check if we succeeded CV_Error(CV_StsError, "Can not open Video file"); //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++) { @@ -18,8 +18,8 @@ void extract_frames(const string &videoFilePath,vector<Mat>& frames){ } } catch( cv::Exception& e ){ cerr << e.msg << endl; exit(1); } } -
itsrifat revised this gist
Nov 7, 2014 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ /* This functions opens a video file and extracts the frames and put them into a vector of Mat(its the class for representing an img) */ void extract_frames(const string &videoFilePath,vector<Mat>& frames){ try{ @@ -21,7 +24,9 @@ void extract_frames(const string &videoFilePath,vector<Mat>& frames){ } /* It saves a vector of frames into jpg images into the outputDir as 1.jpg,2.jpg etc where 1,2 etc represents the frame number */ void save_frames(vector<Mat>& frames, const string& outputDir){ vector<int> compression_params; compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); -
itsrifat revised this gist
Nov 7, 2014 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,4 +19,18 @@ void extract_frames(const string &videoFilePath,vector<Mat>& frames){ std::cout << "exception caught: " << err_msg << std::endl; } } void save_frames(vector<Mat>& frames, const string& outputDir){ vector<int> compression_params; compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params.push_back(100); for(std::vector<Mat>::iterator frame = frames.begin(),frameNumber=0; frame != frame.end(); ++frame){ string filePath = outputDir + to_string(static_cast<long long>(frameNumber))+ ".jpg"; imwrite(filePath,*frame,compression_params); } } -
itsrifat created this gist
Nov 7, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ void extract_frames(const string &videoFilePath,vector<Mat>& 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; } }