utils.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #ifndef OPENCV_CONTRIB_UTILS_HPP
  5. #define OPENCV_CONTRIB_UTILS_HPP
  6. #include <fstream>
  7. #include <iostream>
  8. #include <vector>
  9. #include <map>
  10. typedef std::vector<std::string> stringvec;
  11. typedef std::map<std::string, std::string> datasetType;
  12. namespace opencv_test{namespace {
  13. inline stringvec explode(const std::string &s, const char &c)
  14. {
  15. std::string buff;
  16. stringvec v;
  17. for (auto n:s)
  18. {
  19. if (n != c) { buff += n; }
  20. else if (n == c && !buff.empty())
  21. {
  22. v.push_back(buff);
  23. buff = "";
  24. }
  25. }
  26. if (!buff.empty()) { v.push_back(buff); }
  27. return v;
  28. }
  29. inline datasetType buildDataSet(std::string result_file_path)
  30. {
  31. std::ifstream result_file;
  32. datasetType dataset;
  33. result_file.open(result_file_path);
  34. std::string line;
  35. if (result_file.is_open())
  36. {
  37. while (std::getline(result_file, line))
  38. {
  39. stringvec result = explode(line, ',');
  40. std::string filename = result[0];
  41. if (dataset.find(filename) == dataset.end())
  42. {
  43. dataset[filename] = result[1];
  44. }
  45. }
  46. }
  47. result_file.close();
  48. return dataset;
  49. }
  50. }}
  51. #endif //OPENCV_CONTRIB_UTILS_HPP