Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/cpp/imagelist_creator.cpp
16337 views
1
/*this creates a yaml or xml list of files from the command line args
2
*/
3
4
#include "opencv2/core.hpp"
5
#include "opencv2/imgcodecs.hpp"
6
#include "opencv2/highgui.hpp"
7
#include <string>
8
#include <iostream>
9
10
using std::string;
11
using std::cout;
12
using std::endl;
13
14
using namespace cv;
15
16
static void help(char** av)
17
{
18
cout << "\nThis creates a yaml or xml list of files from the command line args\n"
19
"usage:\n./" << av[0] << " imagelist.yaml *.png\n"
20
<< "Try using different extensions.(e.g. yaml yml xml xml.gz etc...)\n"
21
<< "This will serialize this list of images or whatever with opencv's FileStorage framework" << endl;
22
}
23
24
int main(int ac, char** av)
25
{
26
cv::CommandLineParser parser(ac, av, "{help h||}{@output||}");
27
if (parser.has("help"))
28
{
29
help(av);
30
return 0;
31
}
32
string outputname = parser.get<string>("@output");
33
34
if (outputname.empty())
35
{
36
help(av);
37
return 1;
38
}
39
40
Mat m = imread(outputname); //check if the output is an image - prevent overwrites!
41
if(!m.empty()){
42
std::cerr << "fail! Please specify an output file, don't want to overwrite you images!" << endl;
43
help(av);
44
return 1;
45
}
46
47
FileStorage fs(outputname, FileStorage::WRITE);
48
fs << "images" << "[";
49
for(int i = 2; i < ac; i++){
50
fs << string(av[i]);
51
}
52
fs << "]";
53
return 0;
54
}
55
56