1 /*this creates a yaml or xml list of files from the command line args 2 */ 3 4 #include "opencv2/core/core.hpp" 5 #include "opencv2/imgcodecs.hpp" 6 #include "opencv2/highgui/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 help(char ** av)16static 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 main(int ac,char ** av)24int main(int ac, char** av) 25 { 26 if (ac < 3) 27 { 28 help(av); 29 return 1; 30 } 31 32 string outputname = av[1]; 33 34 Mat m = imread(outputname); //check if the output is an image - prevent overwrites! 35 if(!m.empty()){ 36 std::cerr << "fail! Please specify an output file, don't want to overwrite you images!" << endl; 37 help(av); 38 return 1; 39 } 40 41 FileStorage fs(outputname, FileStorage::WRITE); 42 fs << "images" << "["; 43 for(int i = 2; i < ac; i++){ 44 fs << string(av[i]); 45 } 46 fs << "]"; 47 return 0; 48 } 49