Home | History | Annotate | Download | only in cpp
      1 #include <opencv2/core/core.hpp>
      2 #include <opencv2/videoio/videoio.hpp>
      3 #include <opencv2/highgui/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     if(argc != 2)
     22     {
     23         help(argv);
     24         return 1;
     25     }
     26 
     27     string first_file = argv[1];
     28     VideoCapture sequence(first_file);
     29 
     30     if (!sequence.isOpened())
     31     {
     32         cerr << "Failed to open the image sequence!\n" << endl;
     33         return 1;
     34     }
     35 
     36     Mat image;
     37     namedWindow("Image sequence | press ESC to close", 1);
     38 
     39     for(;;)
     40     {
     41         // Read in image from sequence
     42         sequence >> image;
     43 
     44         // If no image was retrieved -> end of sequence
     45         if(image.empty())
     46         {
     47             cout << "End of Sequence" << endl;
     48             break;
     49         }
     50 
     51         imshow("Image sequence | press ESC to close", image);
     52 
     53         if(waitKey(500) == 27)
     54             break;
     55     }
     56 
     57     return 0;
     58 }
     59