opencv/samples/cpp/imagelist_creator.cpp

55 lines
1.3 KiB
C++
Raw Normal View History

/*this creates a yaml or xml list of files from the command line args
*/
2016-02-15 21:37:29 +08:00
#include "opencv2/core.hpp"
2014-07-04 22:48:15 +08:00
#include "opencv2/imgcodecs.hpp"
2016-02-15 21:37:29 +08:00
#include "opencv2/highgui.hpp"
#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;
using namespace cv;
2012-06-08 01:21:29 +08:00
static void help(char** av)
{
2010-12-04 16:31:11 +08:00
cout << "\nThis creates a yaml or xml list of files from the command line args\n"
2012-06-08 01:21:29 +08:00
"usage:\n./" << av[0] << " imagelist.yaml *.png\n"
<< "Try using different extensions.(e.g. yaml yml xml xml.gz etc...)\n"
<< "This will serialize this list of images or whatever with opencv's FileStorage framework" << endl;
}
int main(int ac, char** av)
{
2015-08-01 23:24:23 +08:00
cv::CommandLineParser parser(ac, av, "{help h||}{@output||}");
if (parser.has("help"))
{
help(av);
2015-08-01 23:24:23 +08:00
return 0;
}
2015-08-01 23:24:23 +08:00
string outputname = parser.get<string>("@output");
2015-08-01 23:24:23 +08:00
if (outputname.empty())
{
help(av);
return 1;
}
Mat m = imread(outputname); //check if the output is an image - prevent overwrites!
if(!m.empty()){
std::cerr << "fail! Please specify an output file, don't want to overwrite you images!" << endl;
help(av);
return 1;
}
FileStorage fs(outputname, FileStorage::WRITE);
fs << "images" << "[";
for(int i = 2; i < ac; i++){
fs << string(av[i]);
}
fs << "]";
return 0;
}