-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.cpp
61 lines (49 loc) · 1.91 KB
/
player.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
#include "opencv2/highgui/highgui.hpp"
// highgui - an interface to video and image capturing.
#include
// The header files for performing input and output.
using namespace cv;
// Namespace where all the C++ OpenCV functionality resides.
using namespace std;
// For input output operations.
int main()
{
VideoCapture cap("Bumpy.mp4");
// cap is the object of class video capture that tries to capture Bumpy.mp4
if ( !cap.isOpened() ) // isOpened() returns true if capturing has been initialized.
{
cout << "Cannot open the video file. \n";
return -1;
}
double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video
// The function get is used to derive a property from the element.
// Example:
// CV_CAP_PROP_POS_MSEC : Current Video capture timestamp.
// CV_CAP_PROP_POS_FRAMES : Index of the next frame.
namedWindow("A_good_name",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
// first argument: name of the window.
// second argument: flag- types:
// WINDOW_NORMAL : The user can resize the window.
// WINDOW_AUTOSIZE : The window size is automatically adjusted to fitvthe displayed image() ), and you cannot change the window size manually.
// WINDOW_OPENGL : The window will be created with OpenGL support.
while(1)
{
Mat frame;
// Mat object is a basic image container. frame is an object of Mat.
if (!cap.read(frame)) // if not success, break loop
// read() decodes and captures the next frame.
{
cout<<"\n Cannot read the video file. \n";
break;
}
imshow("A_good_name", frame);
// first argument: name of the window.
// second argument: image to be shown(Mat object).
if(waitKey(30) == 27) // Wait for 'esc' key press to exit
{
break;
}
}
return 0;
}
// END OF PROGRAM