XuAilib.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "XuAilib.h"
  2. bool XuAilib::Run(const char* path, const int roi[8], const char* format, string& result, string arg)
  3. {
  4. const char* pstrModelFile = "Model_det.m";
  5. CNanoDetector cNanoDetector(pstrModelFile);
  6. cNanoDetector.Init();
  7. Mat mat = imread(path);
  8. if (mat.data != NULL)
  9. {
  10. cNanoDetector.Execute(mat);
  11. vector<DetectorResult> vec;
  12. cNanoDetector.GetResults(vec);
  13. if (vec.size() > 0)
  14. {
  15. for (size_t i = 0; i < vec.size(); i++)
  16. {
  17. int width = vec[i].width;
  18. int height = vec[i].height;
  19. Rect m_select = Rect(vec[i].left, vec[i].top, width, height);
  20. if (string("biaopan").compare(vec[i].name) == 0)
  21. {
  22. if (arg.compare("biaopan") == 0)
  23. {
  24. Mat roi = mat(m_select);
  25. DoublePointerAlgorithm doublePointerAlgorithm;
  26. int resultValue = doublePointerAlgorithm.GetResult(roi, false);
  27. //cout << "biaopan结果 :" << resultValue << endl;
  28. result = "避雷器次数结果:" + to_string(resultValue) + "次";
  29. }
  30. }
  31. if (string("ceshi").compare(vec[i].name) == 0)
  32. {
  33. if (arg.compare("ceshi") == 0)
  34. {
  35. Mat roi = mat(m_select);
  36. SemicircularMeter semicircularMeter;
  37. double resultValue = semicircularMeter.GetResult(roi, false);
  38. //cout << "ceshi结果 :" << result << endl;
  39. result = "避雷器电流读数:" + to_string(resultValue) + "A";
  40. }
  41. }
  42. }
  43. waitKey(0);
  44. }
  45. }
  46. return false;
  47. }