SegDetector.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "IObjectDetector.h"
  3. #include "dnninfer.h"
  4. #include "opencv2/core/base.hpp"
  5. #include <vector>
  6. class CSegDetector : public IObjectDetector
  7. {
  8. public:
  9. CSegDetector(const char* strModelFile, int iBatchSize = 1, int iInferMode = 1, int iDeviceIndex = 0);
  10. virtual ~CSegDetector();
  11. //初始化对象
  12. virtual bool Init();
  13. //释放对象
  14. virtual bool UnInit();
  15. //获取对象名
  16. virtual const char* GetType() { return "CSegDetector"; };
  17. //执行infer
  18. virtual bool Execute(cv::Mat& image);
  19. virtual bool Execute(std::vector<cv::Mat>& images);
  20. virtual bool ExecuteV2(cv::Mat& image);
  21. virtual bool ExecuteV3(cv::Mat& image);
  22. //获取结果
  23. virtual bool GetResults(std::vector<DetectorResult>& vecDetectorResults);
  24. void EnableMask(bool bEnableMask);
  25. void EnableContourArea(bool bEnableContourArea);
  26. void SetMinAreaAndHeight(int minArea, int minHeight);
  27. protected:
  28. bool ProcessInput(cv::Mat& cvInput, Datum& input, double& fx, double& fy, double& xoffset, double& yoffset);
  29. bool ProcessInputs(std::vector<cv::Mat>& cvInput, Datum& input, double& fx, double& fy, double& xoffset, double& yoffset);
  30. bool ProcessInput(cv::Mat& cvInputImage, cv::Mat& cvProcessedImage, double& fx, double& fy, double& xoffset, double& yoffset);
  31. bool MaskToDetectResult(const cv::Mat& mask, float min_area, float min_height, const cv::Size& image_size, std::vector<DetectorResult>& vecDetectResult);
  32. bool ProbToDetectResult(Datum& probDatum, float min_area, float min_height, const cv::Size& image_size, std::vector<DetectorResult>& vecDetectResult);
  33. private:
  34. bool m_bInit;
  35. int m_iBatchSize;
  36. int m_iInferMode;
  37. int m_iDeviceInedx;
  38. std::string m_strModelFile;
  39. std::vector<DetectorResult> m_vecDetectResult;
  40. void* m_pInfer;
  41. int m_iChannel;
  42. int m_iHeight;
  43. int m_iWidth;
  44. int m_iLabelNum;
  45. int m_iMinArea;
  46. int m_iMinHeight;
  47. Datum m_inputDatum;
  48. Datum m_outputDatum;
  49. Datum m_outputProbDatum;
  50. bool m_bEnableMask;
  51. bool m_bEnableContourArea;
  52. };