-
Notifications
You must be signed in to change notification settings - Fork 9
/
vidPlayer.cpp
77 lines (56 loc) · 1.96 KB
/
vidPlayer.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int slider_pos = 0;
int run = 1, dontset = 0;
cv::VideoCapture cap;
void onTrackbarSlide(int pos, void *) {
cap.set(cv::CAP_PROP_POS_FRAMES, pos);
if (!dontset)
run = 1;
dontset = 0;
}
int main(int args, char** argv) {
cv::namedWindow("Video", cv::WINDOW_AUTOSIZE);
cap.open(string(argv[1]));
int frames = (int) cap.get(cv::CAP_PROP_FRAME_COUNT);
int w = (int) cap.get(cv::CAP_PROP_FRAME_WIDTH);
int h = (int) cap.get(cv::CAP_PROP_FRAME_HEIGHT);
cout << "Frames: " << frames << endl;
cout << "Frame width: " << w << endl;
cout << "Frame height: " << h << endl;
cout << "Press r to run the video, s to pause or run the video frame by frame, h for help and esc to quit" << endl;
cv::createTrackbar("Position", "Video", &slider_pos, frames, onTrackbarSlide);
cv::Mat frame;
while(true) {
if(run != 0) {
cap >> frame;
if(frame.empty())
break;
int current_position = (int)cap.get(cv::CAP_PROP_POS_FRAMES);
dontset = 1;
cv::setTrackbarPos("Position", "Video", current_position);
cv::imshow("Video", frame);
run = run - 1;
}
char ch = (char) cv::waitKey(10);
if(ch == 's') {
run = 1;
cout << "Single Step, run = " << run << endl;
}
if(ch == 'r') {
run = -1;
cout << "Run mode, run = " << run << endl;
}
if(ch == 'h') {
run = run;
cout << "Press r to run the video, s to pause or run the video frame by frame, h for help and esc to quit" << endl;
}
if(ch == 27)
break;
}
return(0);
}