2010-11-25 01:39:43 +01:00
|
|
|
/*
|
|
|
|
* starter_imagelist.cpp
|
|
|
|
*
|
|
|
|
* Created on: Nov 23, 2010
|
|
|
|
* Author: Ethan Rublee
|
|
|
|
*
|
|
|
|
* A starter sample for using opencv, load up an imagelist
|
|
|
|
* that was generated with imagelist_creator.cpp
|
|
|
|
* easy as CV_PI right?
|
|
|
|
*/
|
2011-05-21 20:32:34 +02:00
|
|
|
#include "opencv2/highgui/highgui.hpp"
|
2010-11-26 18:59:40 +01:00
|
|
|
#include <iostream>
|
2010-11-25 01:39:43 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//hide the local functions in an unnamed namespace
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
void help(char** av)
|
|
|
|
{
|
2010-12-04 09:31:02 +01:00
|
|
|
cout << "\nThis program gets you started being able to read images from a list in a file\n"
|
2012-10-17 09:12:04 +02:00
|
|
|
"Usage:\n./" << av[0] << " image_list.yaml\n"
|
2010-11-25 01:39:43 +01:00
|
|
|
<< "\tThis is a starter sample, to get you up and going in a copy pasta fashion.\n"
|
|
|
|
<< "\tThe program reads in an list of images from a yaml or xml file and displays\n"
|
|
|
|
<< "one at a time\n"
|
2010-12-04 09:31:02 +01:00
|
|
|
<< "\tTry running imagelist_creator to generate a list of images.\n"
|
2012-10-17 09:12:04 +02:00
|
|
|
"Using OpenCV version %s\n" << CV_VERSION << "\n" << endl;
|
2010-11-25 01:39:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool readStringList(const string& filename, vector<string>& l)
|
|
|
|
{
|
|
|
|
l.resize(0);
|
|
|
|
FileStorage fs(filename, FileStorage::READ);
|
|
|
|
if (!fs.isOpened())
|
|
|
|
return false;
|
|
|
|
FileNode n = fs.getFirstTopLevelNode();
|
|
|
|
if (n.type() != FileNode::SEQ)
|
|
|
|
return false;
|
|
|
|
FileNodeIterator it = n.begin(), it_end = n.end();
|
|
|
|
for (; it != it_end; ++it)
|
|
|
|
l.push_back((string)*it);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int process(vector<string> images)
|
|
|
|
{
|
|
|
|
namedWindow("image",CV_WINDOW_KEEPRATIO); //resizable window;
|
|
|
|
for (size_t i = 0; i < images.size(); i++)
|
|
|
|
{
|
|
|
|
Mat image = imread(images[i], CV_LOAD_IMAGE_GRAYSCALE); // do grayscale processing?
|
|
|
|
imshow("image",image);
|
|
|
|
cout << "Press a key to see the next image in the list." << endl;
|
|
|
|
waitKey(); // wait indefinitely for a key to be pressed
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int ac, char** av)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ac != 2)
|
|
|
|
{
|
|
|
|
help(av);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
std::string arg = av[1];
|
|
|
|
vector<string> imagelist;
|
|
|
|
|
|
|
|
if (!readStringList(arg,imagelist))
|
2012-10-17 09:12:04 +02:00
|
|
|
{
|
2010-12-01 02:43:22 +01:00
|
|
|
cerr << "Failed to read image list\n" << endl;
|
|
|
|
help(av);
|
2010-11-25 01:39:43 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return process(imagelist);
|
|
|
|
}
|