cvvideocapture.cpp
1 | /**
|
---|---|
2 | * @file cvvideocapture.cpp |
3 | * @author Julien Hirel |
4 | * @date Fri May 4 12:31:59 2012 |
5 | * |
6 | * @brief Test of the VideoCapture class from OpenCV |
7 | * |
8 | * This test tries to open and display the video (or image) given as a |
9 | * parameter. It uses the VideoCapture object from OpenCV. |
10 | */ |
11 | |
12 | |
13 | #include <iostream> |
14 | |
15 | #include <opencv2/core/core.hpp> |
16 | #include <opencv2/highgui/highgui.hpp> |
17 | |
18 | |
19 | int main(int ac, char *av[]) |
20 | { |
21 | if (ac <= 1) |
22 | { |
23 | std::cerr << "The name of the video file must be supplied as a parameter" << std::endl;
|
24 | exit(1);
|
25 | } |
26 | |
27 | cv::VideoCapture video; |
28 | |
29 | if (video.open(av[1]) == false) |
30 | { |
31 | std::cerr << "The video file (" << av[1] << ")could not be opened" << std::endl; |
32 | exit(1);
|
33 | } |
34 | |
35 | cv::namedWindow("Display");
|
36 | |
37 | cv::Mat videoFrame; |
38 | |
39 | while(1) |
40 | { |
41 | std::cout << "Rewinding video" << std::endl;
|
42 | |
43 | // Rewind video
|
44 | if (video.set(CV_CAP_PROP_POS_FRAMES, 0) == false) |
45 | { |
46 | std::cerr << "The video could not be rewinded" << std::endl;
|
47 | exit(1);
|
48 | } |
49 | |
50 | while (video.read(videoFrame) == true) |
51 | { |
52 | cv::imshow("Display", videoFrame);
|
53 | cv::waitKey(5);
|
54 | |
55 | std::cout << "timestamp = " << time(0) << std::endl; |
56 | if (video.get(CV_CAP_PROP_POS_FRAMES) == video.get(CV_CAP_PROP_FRAME_COUNT))
|
57 | { |
58 | break;
|
59 | } |
60 | } |
61 | } |
62 | } |