2 * starter_imagelist.cpp
4 * Created on: Nov 23, 2010
7 * A starter sample for using opencv, load up an imagelist
8 * that was generated with imagelist_creator.cpp
11 #include "opencv2/imgcodecs.hpp"
12 #include "opencv2/highgui/highgui.hpp"
19 //hide the local functions in an unnamed namespace
24 cout << "\nThis program gets you started being able to read images from a list in a file\n"
25 "Usage:\n./" << av[0] << " image_list.yaml\n"
26 << "\tThis is a starter sample, to get you up and going in a copy pasta fashion.\n"
27 << "\tThe program reads in an list of images from a yaml or xml file and displays\n"
29 << "\tTry running imagelist_creator to generate a list of images.\n"
30 "Using OpenCV version %s\n" << CV_VERSION << "\n" << endl;
33 bool readStringList(const string& filename, vector<string>& l)
36 FileStorage fs(filename, FileStorage::READ);
39 FileNode n = fs.getFirstTopLevelNode();
40 if (n.type() != FileNode::SEQ)
42 FileNodeIterator it = n.begin(), it_end = n.end();
43 for (; it != it_end; ++it)
44 l.push_back((string)*it);
48 int process(vector<string> images)
50 namedWindow("image", WINDOW_KEEPRATIO); //resizable window;
51 for (size_t i = 0; i < images.size(); i++)
53 Mat image = imread(images[i], IMREAD_GRAYSCALE); // do grayscale processing?
54 imshow("image",image);
55 cout << "Press a key to see the next image in the list." << endl;
56 waitKey(); // wait indefinitely for a key to be pressed
63 int main(int ac, char** av)
71 std::string arg = av[1];
72 vector<string> imagelist;
74 if (!readStringList(arg,imagelist))
76 cerr << "Failed to read image list\n" << endl;
81 return process(imagelist);