imagelist_creator.cpp 1.3 KB

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