handleAI.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #pragma once
  2. #include <opencv2/core/core.hpp>
  3. enum ClsStatus
  4. {
  5. Cls_Undifne = -1,
  6. Cls_Success,
  7. Cls_NG1,
  8. Cls_NG2,
  9. Cls_NG3
  10. };
  11. enum SegStatus
  12. {
  13. Seg_Undifne = -1,
  14. Seg_Success,
  15. Seg_NG1,
  16. Seg_NG2,
  17. Seg_NG3
  18. };
  19. enum OCRStatus
  20. {
  21. OCR_Undifne = -1,
  22. OCR_Success,
  23. OCR_NG1,
  24. OCR_NG2,
  25. OCR_NG3
  26. };
  27. enum DetStatus
  28. {
  29. Det_Undifne = -1,
  30. Det_Success,
  31. Det_NG1,
  32. Det_NG2,
  33. Det_NG3
  34. };
  35. typedef struct
  36. {
  37. float x;
  38. float y;
  39. float w;
  40. float h;
  41. float score;
  42. int classes;
  43. }Bbox;
  44. typedef struct
  45. {
  46. float x;
  47. float y;
  48. float w;
  49. float h;
  50. float score;
  51. cv::String rstChar;
  52. }OCRChar;
  53. typedef struct
  54. {
  55. int x;
  56. int y;
  57. int w;
  58. int h;
  59. int classes;
  60. cv::Mat resultMask;
  61. }SegResult;
  62. enum CutType
  63. {
  64. RegularRect = 0,
  65. SlantRect = 1,
  66. Contour = 2,
  67. Default = 3
  68. };
  69. //cutType: Default:按照中心点与固定大小切,其他按照轮廓边缘切
  70. //DstW:目标图片宽
  71. //DstH:目标图片高
  72. //fillorresize: cutType为Default时:指示超出原图区域时是否填充像素,false为不填充,自动移入原图区域内; cutType为其他时:True直接resize到目标大小,False保持宽高比填充
  73. //Color:若填充,则使用给定像素值进行填充,若不填充则无效
  74. typedef struct
  75. {
  76. CutType cutType;
  77. int DstW;
  78. int DstH;
  79. bool fillorresize;
  80. int color;
  81. }CutParam;
  82. using namespace std;
  83. class pSegmentation
  84. {
  85. public:
  86. virtual void Release() = 0;
  87. virtual cv::Mat Evaluate(cv::Mat srcImg) = 0;
  88. virtual cv::Mat Evaluate(const char* imgPath) = 0;
  89. virtual void Evaluate(cv::Mat srcImg, std::vector<SegResult> &result, CutParam param) = 0;
  90. virtual void Evaluate(const char* imgPath, std::vector<SegResult> &result, CutParam param) = 0;
  91. virtual SegStatus getStatus() = 0;
  92. virtual void setStride(float stride) = 0;
  93. const int patchSizeNet = 0;
  94. const int batchSizeNet = 0;
  95. const int maxbatchSizeNet = 0;
  96. const float strideNet = 0.9;
  97. const int m_classes = 0;
  98. const int m_gpuID = 0;
  99. };
  100. extern "C" __declspec(dllexport) pSegmentation* _stdcall CreateSegObj(char* modelPath, int batchSize = 256, float stride = 0.9, int patchSize = 256, int deviceId = 0, int classes = 2);
  101. extern "C" __declspec(dllexport) pSegmentation* _stdcall CreateSegObjS(char* modelPath, int batchSize = 256, int deviceId = 0);
  102. extern "C" __declspec(dllexport) pSegmentation* _stdcall CreateSegObjF(char* modelPath, char* calib,int batchSize = 256, int deviceId = 0);
  103. extern "C" __declspec(dllexport) void _stdcall DestroySegObj(pSegmentation* pExport);
  104. extern "C" __declspec(dllexport) int _stdcall GetMaxBatchsize(int gpuId, int width,int height);
  105. extern "C" __declspec(dllexport) char* _stdcall GetCurrentVersion();
  106. //extern "C" __declspec(dllexport) cv::Mat _stdcall CutImage(cv::Mat src, int CenterX, int CenterY, int &DstW, int &DstH, bool Fill = false, int Color = 0);
  107. //extern "C" __declspec(dllexport) cv::Mat _stdcall CutImageByContour(cv::Mat src, int DstW, int DstH, vector<cv::Point> ContourPt, CutType CutType = CutType::RegularRect, bool Resize = false, int color = 0);
  108. extern "C" __declspec(dllexport) bool IDecode(const char* orifolder, const char* rstfolder);
  109. class pClassification
  110. {
  111. public:
  112. virtual int Evaluate(cv::Mat srcImg) = 0;
  113. //virtual int EvaluateTest(cv::Mat srcImg) = 0;
  114. virtual int Evaluate(const char* imgPath) = 0;
  115. virtual int Evaluate(vector<cv::Mat> imgList, vector<int> & rstClassList, vector<float> & rstProbList) = 0;
  116. virtual float getProbability() = 0;
  117. virtual float* getProbabilityList () = 0;
  118. virtual ClsStatus getStatus() = 0;
  119. virtual void Release() = 0;
  120. const int m_imageWidth = 0;
  121. const int m_imageHeight = 0;
  122. const int m_classNum = 0;
  123. const int m_inGpuID = 0;
  124. };
  125. extern "C" __declspec(dllexport) pClassification* _stdcall CreateClsObj(char* inputModelPath, char* inputJsonPath, int in_gpuID, int in_width, int in_height, int classNum, int batchsize=1);
  126. extern "C" __declspec(dllexport) pClassification* _stdcall CreateClsObjS(char* inputModelPath, char* inputJsonPath, int in_gpuID, int batchsize = 1);
  127. extern "C" __declspec(dllexport) pClassification* _stdcall CreateClsObjV3(char* inputModelPath, int in_gpuID, int batchsize);
  128. extern "C" __declspec(dllexport) pClassification* _stdcall CreateClsObjF(char* inputModelPath, char* calib, int in_gpuID, int batchsize);
  129. extern "C" __declspec(dllexport) void _stdcall DestroyClsObj(pClassification* pExport);
  130. class pOCREvaluator
  131. {
  132. public:
  133. //virtual std::vector<OCRChar> Evaluate(cv::Mat srcImg) = 0;
  134. //virtual std::vector<OCRChar> Evaluate(const char* imgPath) = 0;
  135. virtual char* Evaluate(cv::Mat srcImg, std::vector<OCRChar>& resultOcrBox) = 0;
  136. virtual char* Evaluate(const char* imgPath, std::vector<OCRChar>& resultOcrBox)=0;
  137. virtual OCRStatus getStatus() = 0;
  138. virtual void Release() = 0;
  139. const int m_imageWidth = 0;
  140. const int m_imageHeight = 0;
  141. const int m_classNum = 0;
  142. const int m_inGpuID = 0;
  143. };
  144. //extern "C" __declspec(dllexport) pOCREvaluator* _stdcall CreateOCRObj(char* inputModelPath, char* inputJsonPath, int in_gpuID, int in_width, int in_height, int classNum);
  145. //extern "C" __declspec(dllexport) pOCREvaluator* _stdcall CreateOCRObjS(char* inputModelPath, char* inputJsonPath, int in_gpuID);
  146. extern "C" __declspec(dllexport) pOCREvaluator* _stdcall CreateOCRObjV3(char* inputModelPath, int in_gpuID);
  147. extern "C" __declspec(dllexport) pOCREvaluator* _stdcall CreateOCRObjF(char* inputModelPath,char* calib, int in_gpuID);
  148. extern "C" __declspec(dllexport) void _stdcall DestroyOCRObj(pOCREvaluator* pExport);
  149. class pDetection
  150. {
  151. public:
  152. virtual std::vector<Bbox> Evaluate(cv::Mat srcImg) = 0;
  153. virtual std::vector<Bbox> Evaluate(const char* imgPath) = 0;
  154. virtual DetStatus getStatus() = 0;
  155. virtual void setStride(float stride) = 0;
  156. virtual void setScore(float score) = 0;
  157. virtual void setNms(float nms) = 0;
  158. virtual void Release() = 0;
  159. const int m_gpuID = 0;
  160. const int batchSizeNet = 0;
  161. const float m_score = 0;
  162. const float m_nms = 0;
  163. const int patchSizeNet = 0;
  164. const float strideNet = 0;
  165. };
  166. extern "C" __declspec(dllexport) pDetection* _stdcall CreateDetObj(char* modelPath, int batchSize = 32, float stride = 0.9, float score = 0.5, float nms = 0.5, int deviceId = 0);
  167. extern "C" __declspec(dllexport) pDetection* _stdcall CreateDetObjS(char* modelPath, int batchSize = 32, int deviceId = 0);
  168. extern "C" __declspec(dllexport) void _stdcall DestroyDetObj(pDetection* pExport);