Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/cpp/image_sequence.cpp
16337 views
1
#include <opencv2/core.hpp>
2
#include <opencv2/videoio.hpp>
3
#include <opencv2/highgui.hpp>
4
5
#include <iostream>
6
7
using namespace cv;
8
using namespace std;
9
10
static void help(char** argv)
11
{
12
cout << "\nThis sample shows you how to read a sequence of images using the VideoCapture interface.\n"
13
<< "Usage: " << argv[0] << " <image_mask> (example mask: example_%02d.jpg)\n"
14
<< "Image mask defines the name variation for the input images that have to be read as a sequence. \n"
15
<< "Using the mask example_%02d.jpg will read in images labeled as 'example_00.jpg', 'example_01.jpg', etc."
16
<< endl;
17
}
18
19
int main(int argc, char** argv)
20
{
21
help(argv);
22
cv::CommandLineParser parser(argc, argv, "{@image| ../data/left%02d.jpg |}");
23
string first_file = parser.get<string>("@image");
24
25
if(first_file.empty())
26
{
27
return 1;
28
}
29
30
VideoCapture sequence(first_file);
31
32
if (!sequence.isOpened())
33
{
34
cerr << "Failed to open the image sequence!\n" << endl;
35
return 1;
36
}
37
38
Mat image;
39
namedWindow("Image sequence | press ESC to close", 1);
40
41
for(;;)
42
{
43
// Read in image from sequence
44
sequence >> image;
45
46
// If no image was retrieved -> end of sequence
47
if(image.empty())
48
{
49
cout << "End of Sequence" << endl;
50
break;
51
}
52
53
imshow("Image sequence | press ESC to close", image);
54
55
if(waitKey(500) == 27)
56
break;
57
}
58
59
return 0;
60
}
61
62