CommonUtils.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #ifndef __COMMON_UTILS_H__
  2. #define __COMMON_UTILS_H__
  3. // *****************************************************************************
  4. // 版权所有(C)2023~2099 上海骄成超声波技术有限公司
  5. // 保留所有权利
  6. // *****************************************************************************
  7. // 作者 : 陆蕴凡
  8. // 版本 : 1.0
  9. // 代码创建日期:2025/01/10
  10. // 版本更新日期:2025/01/10
  11. // 功能说明:公共工具
  12. // *****************************************************************************
  13. #include "TypeDef.h"
  14. #include "Figure.h"
  15. class BaseItem;
  16. namespace JVision
  17. {
  18. /** @brief 权限等级的枚举体 */
  19. enum class JVision_API E_PERMISSION_LEVEL : int
  20. {
  21. E_PERMISSION_USER = 0, /**< 用户 */
  22. E_PERMISSION_ADMIN, /**< 管理员 */
  23. E_PERMISSION_SUPER_ADMIN, /**< 超级管理员 */
  24. };
  25. /** @brief 定位算法的枚举体 */
  26. enum class JVision_API E_LOCALIZATION_TYPE : int
  27. {
  28. E_LOCALIZATION_INVALID = 0, /**< 无效值 */
  29. E_MODEL_LOCATION, /**< 模板定位 */
  30. E_DOUBLE_MODEL_LOCATION, /**< 双模板定位 */
  31. E_LINE_LOCATION, /**< 直线定位 */
  32. E_CORNER_LOCATION, /**< 角点定位 */
  33. E_CIRCLE_LOCATION, /**< 圆定位 */
  34. E_DOUBLE_CIRCLE_LOCATION, /**< 双圆定位 */
  35. E_CIRCLE_LINE_LOCATION, /**< 圆直线定位 */
  36. E_RRECTANGLE_LOCATION, /**< 矩形定位 */
  37. E_NINESQUARE_LOCATION, /**< 九宫格搜索 */
  38. E_GLUE_DETECT, /**< 胶量检测 */
  39. E_LOCATION_MAX, /**< 最大值 */
  40. };
  41. /** @brief 算法参数ID的枚举体 */
  42. enum class JVision_API E_LOCALIZATION_PARAM : ParamID
  43. {
  44. E_LOCALIZATION_PARAM_INVALID = 0, /**< 无效参数 */
  45. E_LOCALIZATION_PARAM_MARK, /**< Mark */
  46. E_LOCALIZATION_PARAM_SEARCH, /**< 搜索区域 */
  47. E_LOCALIZATION_PARAM_CIRCLE, /**< 圆区域 */
  48. E_LOCALIZATION_PARAM_LINE, /**< 直线区域 */
  49. E_LOCALIZATION_PARAM_RECTANGLE, /**< 矩形区域 */
  50. E_LOCALIZATION_PARAM_GLUE, /**< 胶量检测 */
  51. E_LOCALIZATION_PARAM_SCALED_IMG, /**< 图像预处理--亮度调节 */
  52. E_LOCALIZATION_PARAM_BINARY_IMG, /**< 图像预处理--二值化分割 */
  53. E_LOCALIZATION_PARAM_OPENING_IMG, /**< 图像预处理--开运算 */
  54. E_LOCALIZATION_PARAM_REGION_GROWING, /**< 图像预处理--区域增长 */
  55. E_LOCALIZATION_PARAM_FILL_UP, /**< 图像预处理--孔洞填充 */
  56. E_LOCALIZATION_PARAM_MAX, /**< 参数最大值 */
  57. };
  58. // =====================================================
  59. // 参数类型, 根据 E_LOCALIZATION_PARAM 对应
  60. // =====================================================
  61. /** @brief Mark 参数 */
  62. struct JVision_API MarkParameter
  63. {
  64. BaseFigure* figure; /** @brief Mark区域 */
  65. BaseFigure* mask; /** @brief Mask */
  66. Line* referencePoint; /** @brief 参考点 */
  67. int start; /** @brief 起始角度 */
  68. int end; /** @brief 搜索角度 */
  69. std::string pyrimid; /** @brief 图形金字塔层数 */
  70. std::string searchPo; /** @brief 匹配指标 */
  71. bool UseContour; /** @brief 是否使用轮廓匹配*/
  72. };
  73. /** @brief 搜索参数 */
  74. struct JVision_API SearchParameter
  75. {
  76. BaseFigure* figure; /** @brief 搜索区域 */
  77. int start; /** @brief 起始角度 */
  78. int end; /** @brief 搜索角度 */
  79. int pyrimid; /** @brief 图像金字塔层数 */
  80. int matchCount; /** @brief 匹配个数 */
  81. double minScore; /** @brief 最低分数 */
  82. double overlap; /** @brief 最大重叠比例 */
  83. bool isSubPix; /** @brief 是否使用亚像素精确 */
  84. bool isDetect; /** @brief 是否使用墨点检测 */
  85. };
  86. /** @brief 胶量检测参数 */
  87. struct JVision_API GlueParameter
  88. {
  89. BaseFigure* figure;
  90. int methodIndex;
  91. int threshMin;
  92. int threshMax;
  93. int areaMin;
  94. int areaMax;
  95. };
  96. /** @brief 同心圆参数 */
  97. struct JVision_API CCircleParameter
  98. {
  99. CCircle* figure; /** @brief 同心圆区域 */
  100. std::string grayDirection; /** @brief 灰度方向 */
  101. std::string scanDirection; /** @brief 采集点顺序 */
  102. int threshold; /** @brief 边缘强度 */
  103. int cullDistance; /** @brief 滤波强度 */
  104. int SegNums; /** @brief 寻找的数量 */
  105. int UnitWidth; /** @brief 卡尺宽度 */
  106. int UnitLength; /** @brief 卡尺高度 */
  107. };
  108. /** @brief 圆参数 */
  109. struct JVision_API CircleParameter
  110. {
  111. Circle* figure; /** @brief 同心圆区域 */
  112. std::string grayDirection; /** @brief 灰度方向 */
  113. std::string scanDirection; /** @brief 采集点顺序 */
  114. int threshold; /** @brief 边缘强度 */
  115. int cullDistance; /** @brief 滤波强度 */
  116. int SegNums; /** @brief 寻找的数量 */
  117. int UnitWidth; /** @brief 卡尺宽度 */
  118. int UnitLength; /** @brief 卡尺高度 */
  119. };
  120. /** @brief 直线参数 */
  121. struct JVision_API LineParameter
  122. {
  123. Caliper* figure; /** @brief 卡尺区域 */
  124. std::string grayDirection; /** @brief 灰度方向 */
  125. std::string scanDirection; /** @brief 采集点顺序 */
  126. int threshold; /** @brief 边缘强度 */
  127. int cullDistance; /** @brief 滤波强度 */
  128. int CaliperHeight; /** @brief 卡尺高度 */
  129. int CaliperWidth; /** @brief 卡尺宽度 */
  130. };
  131. /** @brief 矩形参数 */
  132. struct JVision_API RectangleParameter
  133. {
  134. CRectangle* figure; /** @brief 同心矩形 区域 */
  135. std::string grayDirection; /** @brief 灰度方向 */
  136. std::string scanDirection; /** @brief 采集点顺序 */
  137. int threshold; /** @brief 边缘强度 */
  138. int cullDistance; /** @brief 滤波强度 */
  139. int segNums; /** @brief 寻找的数量 */
  140. int width; /** @brief 卡尺宽度 */
  141. int height; /** @brief 卡尺高度 */
  142. };
  143. /** @brief 照明矫正 */
  144. struct JVision_API IlluminateImgParameter
  145. {
  146. int cameraID; // 相机 id
  147. int min; // 最低阈值
  148. int max; // 最大阈值
  149. };
  150. /** @brief 图像预处理--亮度调节 */
  151. struct JVision_API ScaledImgParameter
  152. {
  153. int imgIdx; // 选择的图片标识
  154. int scaledAdd; // 相加系数
  155. double scaledMulti; // 相乘系数
  156. };
  157. /** @brief 图像预处理--二值化调节 */
  158. struct JVision_API ThresholdImgParameter
  159. {
  160. int imgIdx; // 选择的图片标识
  161. int thresholdMin; // 二值化分割最小值
  162. int thresholdMax; // 二值化分割最大值
  163. };
  164. /** @brief 图像预处理--开运算条件 */
  165. struct JVision_API OpeningImgParameter
  166. {
  167. int imgIdx; // 选择的图片标识
  168. int ksize; // 开运算核大小
  169. };
  170. /** @brief 图像预处理--区域增长 */
  171. struct JVision_API RegionGrowingParameter
  172. {
  173. int imgIdx; // 选择的图片标识
  174. int ksize; // 区域增长核大小
  175. int tolerance; // 灰度差异值
  176. int min_size; // 最小像素数
  177. };
  178. /** @brief 图像预处理--孔洞填充 */
  179. struct JVision_API FillUpParameter
  180. {
  181. int imgIdx; // 选择的图片标识
  182. };
  183. // =====================================================
  184. // 返回值类型, 根据 E_LOCALIZATION_TYPE 对应
  185. // =====================================================
  186. /** @brief 模板定位算法返回的结果结构体 */
  187. struct JVision_API ModelLocalization_Result
  188. {
  189. Point RefPoint; /** @brief 参考点坐标 */
  190. Point ActualPoint[9]; /** @brief 结果坐标 */
  191. double Score[9]; /** @brief 模板匹配的得分 */
  192. double UsedTime; /** @brief 算法的总共耗时 */
  193. };
  194. /** @brief 双模板定位算法返回的结果结构体 */
  195. struct JVision_API DoubleModelLocalization_Result
  196. {
  197. ModelLocalization_Result resArr[2]; /** @brief 两个模板匹配的数组 */
  198. };
  199. /** @brief 角点定位算法返回的结果结构体 */
  200. struct JVision_API Corner_ModelLocalization_Result
  201. {
  202. bool isMark; /** @brief 是否启用模板跟随功能 */
  203. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  204. Point2D RefPoint; /** @brief 参考点坐标 */
  205. Point2D CrossPoint; /** @brief 两直线角点 */
  206. Point2D Line1Start; /** @brief 直线1的起始点坐标 */
  207. Point2D Line1End; /** @brief 直线1的终止点坐标 */
  208. Point2D Line2Start; /** @brief 直线2的起始点坐标 */
  209. Point2D Line2End; /** @brief 直线2的终止点坐标 */
  210. double Line1Angle; /** @brief 直线1的倾斜角度 */
  211. double Line2Angle; /** @brief 直线2的倾斜角度 */
  212. double Score; /** @brief 启用模板匹配时的得分 */
  213. double UsedTime; /** @brief 执行角点定位算法的总耗时 */
  214. };
  215. /** @brief 圆定位算法返回的结果结构体 */
  216. struct JVision_API Circle_ModelLocalization_Result
  217. {
  218. bool isMark; /** @brief 是否启用模板跟随功能 */
  219. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  220. Point2D RefPoint; /** @brief 参考点坐标 */
  221. CircleResult CirclePoint; /** @brief 圆心的坐标 */
  222. double Score; /** @brief 模板匹配的得分 */
  223. double UsedTime; /** @brief 圆定位算法的总耗时 */
  224. };
  225. /** @brief 直线定位算法返回的结果结构体 */
  226. struct JVision_API Line_ModelLocalization_Result
  227. {
  228. bool isMark; /** @brief 是否启用模板跟随功能 */
  229. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  230. Point2D RefPoint; /** @brief 参考点坐标 */
  231. Point2D LineStart; /** @brief 直线的起始点坐标 */
  232. Point2D LineEnd; /** @brief 直线的终止点坐标 */
  233. double Score; /** @brief 模板匹配的得分 */
  234. double Angle; /** @brief 当前直线的角度 */
  235. double UsedTime; /** @brief 直线定位的总耗时 */
  236. };
  237. /** @brief 双圆定位算法返回的结果结构体 */
  238. struct JVision_API Circles_ModelLocalization_Result
  239. {
  240. bool isMark; /** @brief 是否启用模板跟随功能 */
  241. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  242. Point2D RefPoint; /** @brief 参考点坐标 */
  243. double Score; /** @brief 模板匹配的得分 */
  244. double UsedTime; /** @brief 双圆定位的总耗时 */
  245. CircleResult CirclePointArr[2]; /** @brief 圆心坐标的数组 */
  246. };
  247. /** @brief 圆直线定位算法返回的结果结构体 */
  248. struct JVision_API CirCleLine_ModelLocalization_Result
  249. {
  250. bool isMark; /** @brief 是否启用模板跟随功能 */
  251. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  252. Point2D RefPoint; /** @brief 参考点坐标 */
  253. double Score; /** @brief 模板匹配得分 */
  254. double UsedTime; /** @brief 圆直线定位算法耗时 */
  255. // 圆形坐标
  256. CircleResult CirclePoint; /** @brief 圆心坐标 */
  257. // 直线坐标
  258. Point2D LineStart; /** @brief 直线的起始点坐标 */
  259. Point2D LineEnd; /** @brief 直线的终止点坐标 */
  260. };
  261. /** @brief 旋转矩形定位算法返回的结果结构体 */
  262. struct JVision_API RRectangle_ModelLocalization_Result
  263. {
  264. bool isMark; /** @brief 是否启用模板跟随功能 */
  265. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  266. Point2D RefPoint; /** @brief 参考点坐标 */
  267. double Score; /** @brief 模板匹配得分 */
  268. double UsedTime; /** @brief 旋转矩形定位算法耗时 */
  269. Point RectangleCenter; /** @brief 旋转矩形中心点 */
  270. Point2D CornerPointArr[4]; /** @brief 旋转矩形角点坐标的数组 */
  271. };
  272. /** @brief 胶量检测算法返回的结果结构体 */
  273. struct JVision_API Glue_Detection_Result
  274. {
  275. bool isMark; /** @brief 是否启用模板跟随功能 */
  276. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  277. Point2D RefPoint; /** @brief 参考点坐标 */
  278. double Score; /** @brief 模板匹配得分 */
  279. double UsedTime; /** @brief 胶量检测算法耗时 */
  280. Point2D CornerPointArr[2]; /** @brief 矩形角点坐标的数组 */
  281. double area; /** @brief 胶体面积 */
  282. double roundness; /** @brief 圆度 */
  283. };
  284. }
  285. #endif