-
Notifications
You must be signed in to change notification settings - Fork 1
/
showvideo.cpp
49 lines (47 loc) · 1.33 KB
/
showvideo.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
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <fstream>
using namespace std;
int g_slider_position = 0;
int g_run = 1; //start out in single step mode
cv::VideoCapture g_cap;
void onTrackbarSlide( int pos, void * ) {
g_cap.set( cv::CAP_PROP_POS_FRAMES, pos );
}
int main( int argc, char** argv ) {
cv::namedWindow( "Video Player", cv::WINDOW_AUTOSIZE );
g_cap.open( string(argv[1]));
int frames = (int) g_cap.get(cv::CAP_PROP_FRAME_COUNT);
int tmpw= (int) g_cap.get(cv::CAP_PROP_FRAME_WIDTH);
int tmph= (int) g_cap.get(cv::CAP_PROP_FRAME_HEIGHT);
cout << "Video has "<< frames << " frames of dimensions("<< tmpw << ", " << tmph << ")." << endl;
cv::createTrackbar("Position", "Video Player", &g_slider_position, frames,onTrackbarSlide);
cv::Mat frame;
for(;;) {
if( g_run != 0) {
g_cap >> frame; if(frame.empty()) break;
int current_pos = (int)g_cap.get(cv::CAP_PROP_POS_FRAMES);
// g_dontset = 1;
cv::setTrackbarPos("Position", "Video Player", current_pos);
cv::imshow( "Video Player", frame );
g_run+=1;
}
char c= (char) cv::waitKey(30);
if(c==32)
{
if(g_run>0)
{g_run=-1; cout<<"Pause"<<endl;}
else{
g_run=1;cout<<"PLay"<<endl;
}
}
// if(c=='r')
// {
// g_run=1; cout<<"Play"<<endl;
// }
if(c==27)
break;
}
return 0;
}