-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframeExtract.cpp
More file actions
43 lines (35 loc) · 1.35 KB
/
frameExtract.cpp
File metadata and controls
43 lines (35 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// #include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
// #include "opencv2/highgui/highgui.hpp"
// #include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <string>
#include <cstdio>
using namespace cv;
using namespace std;
vector<Mat*> framesBuffer;
int main(int argc, char** argv) {
if(argc != 3){
printf("\nUsage: ./frameExtract [Path/to/input/video] [Path/to/output/folder]\n\n");
return -1;
}
VideoCapture cap(argv[1]); // open the video camera no. 0
if (!cap.isOpened()) { printf("ERROR INITIALIZING VIDEO CAPTURE\n" ); return -1; }// if not success, exit program
int total_frames = cap.get(CV_CAP_PROP_FRAME_COUNT);
printf("\ntotal frames: %d\nPlease enter cut interval: \n",total_frames);
int interval;
scanf("%d", &interval);
for (int i = 0; i < total_frames; ++i) {
Mat inputFrame;
if (!cap.read(inputFrame)) { printf("ERROR READING FRAME or finished\n" ); break; }
else if ( !(i%interval) && inputFrame.cols != 0 && inputFrame.rows != 0 ) {
char buffer [50];
sprintf (buffer, "%ld_%d.jpg", time(NULL), i);
string tmp(buffer);
string strPath = argv[2] + tmp;
cout << strPath << endl;
imwrite(strPath, inputFrame);
}
}
return 0;
}