mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.1 KiB
81 lines
2.1 KiB
14 years ago
|
/*
|
||
|
* 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?
|
||
|
*/
|
||
11 years ago
|
#include "opencv2/imgcodecs.hpp"
|
||
9 years ago
|
#include "opencv2/highgui.hpp"
|
||
14 years ago
|
#include <iostream>
|
||
14 years ago
|
#include <vector>
|
||
|
|
||
|
using namespace cv;
|
||
|
using namespace std;
|
||
|
|
||
6 years ago
|
static void help(char** av)
|
||
14 years ago
|
{
|
||
14 years ago
|
cout << "\nThis program gets you started being able to read images from a list in a file\n"
|
||
12 years ago
|
"Usage:\n./" << av[0] << " image_list.yaml\n"
|
||
14 years ago
|
<< "\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"
|
||
14 years ago
|
<< "\tTry running imagelist_creator to generate a list of images.\n"
|
||
12 years ago
|
"Using OpenCV version %s\n" << CV_VERSION << "\n" << endl;
|
||
14 years ago
|
}
|
||
|
|
||
6 years ago
|
static bool readStringList(const string& filename, vector<string>& l)
|
||
14 years ago
|
{
|
||
|
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;
|
||
|
}
|
||
|
|
||
6 years ago
|
static int process(const vector<string>& images)
|
||
14 years ago
|
{
|
||
12 years ago
|
namedWindow("image", WINDOW_KEEPRATIO); //resizable window;
|
||
|
for (size_t i = 0; i < images.size(); i++)
|
||
|
{
|
||
|
Mat image = imread(images[i], IMREAD_GRAYSCALE); // do grayscale processing?
|
||
|
imshow("image",image);
|
||
|
cout << "Press a key to see the next image in the list." << endl;
|
||
6 years ago
|
waitKey(); // wait infinitely for a key to be pressed
|
||
12 years ago
|
}
|
||
|
return 0;
|
||
14 years ago
|
}
|
||
|
|
||
|
int main(int ac, char** av)
|
||
|
{
|
||
9 years ago
|
cv::CommandLineParser parser(ac, av, "{help h||}{@input||}");
|
||
|
if (parser.has("help"))
|
||
|
{
|
||
|
help(av);
|
||
|
return 0;
|
||
|
}
|
||
|
std::string arg = parser.get<std::string>("@input");
|
||
|
if (arg.empty())
|
||
14 years ago
|
{
|
||
|
help(av);
|
||
|
return 1;
|
||
|
}
|
||
|
vector<string> imagelist;
|
||
|
|
||
|
if (!readStringList(arg,imagelist))
|
||
12 years ago
|
{
|
||
14 years ago
|
cerr << "Failed to read image list\n" << endl;
|
||
|
help(av);
|
||
14 years ago
|
return 1;
|
||
|
}
|
||
|
|
||
|
return process(imagelist);
|
||
|
}
|