CommonUtils.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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_MAX, /**< 参数最大值 */
  54. };
  55. // =====================================================
  56. // 参数类型, 根据 E_LOCALIZATION_PARAM 对应
  57. // =====================================================
  58. /** @brief Mark 参数 */
  59. struct JVision_API MarkParameter
  60. {
  61. BaseFigure* figure; /** @brief Mark区域 */
  62. BaseFigure* mask; /** @brief Mask */
  63. Line* referencePoint; /** @brief 参考点 */
  64. int start; /** @brief 起始角度 */
  65. int end; /** @brief 搜索角度 */
  66. std::string pyrimid; /** @brief 图形金字塔层数 */
  67. std::string searchPo; /** @brief 匹配指标 */
  68. bool UseContour; /** @brief 是否使用轮廓匹配*/
  69. };
  70. /** @brief 搜索参数 */
  71. struct JVision_API SearchParameter
  72. {
  73. BaseFigure* figure; /** @brief 搜索区域 */
  74. int start; /** @brief 起始角度 */
  75. int end; /** @brief 搜索角度 */
  76. int pyrimid; /** @brief 图像金字塔层数 */
  77. int matchCount; /** @brief 匹配个数 */
  78. double minScore; /** @brief 最低分数 */
  79. double overlap; /** @brief 最大重叠比例 */
  80. bool isSubPix; /** @brief 是否使用亚像素精确 */
  81. bool isDetect; /** @brief 是否使用墨点检测 */
  82. };
  83. /** @brief 胶量检测参数 */
  84. struct JVision_API GlueParameter
  85. {
  86. BaseFigure* figure;
  87. int methodIndex;
  88. int threshMin;
  89. int threshMax;
  90. int areaMin;
  91. int areaMax;
  92. };
  93. /** @brief 同心圆参数 */
  94. struct JVision_API CCircleParameter
  95. {
  96. CCircle* figure; /** @brief 同心圆区域 */
  97. std::string grayDirection; /** @brief 灰度方向 */
  98. std::string scanDirection; /** @brief 采集点顺序 */
  99. int threshold; /** @brief 边缘强度 */
  100. int cullDistance; /** @brief 滤波强度 */
  101. int SegNums; /** @brief 寻找的数量 */
  102. int UnitWidth; /** @brief 卡尺宽度 */
  103. int UnitLength; /** @brief 卡尺高度 */
  104. };
  105. /** @brief 圆参数 */
  106. struct JVision_API CircleParameter
  107. {
  108. Circle* figure; /** @brief 同心圆区域 */
  109. std::string grayDirection; /** @brief 灰度方向 */
  110. std::string scanDirection; /** @brief 采集点顺序 */
  111. int threshold; /** @brief 边缘强度 */
  112. int cullDistance; /** @brief 滤波强度 */
  113. int SegNums; /** @brief 寻找的数量 */
  114. int UnitWidth; /** @brief 卡尺宽度 */
  115. int UnitLength; /** @brief 卡尺高度 */
  116. };
  117. /** @brief 直线参数 */
  118. struct JVision_API LineParameter
  119. {
  120. Caliper* figure; /** @brief 卡尺区域 */
  121. std::string grayDirection; /** @brief 灰度方向 */
  122. std::string scanDirection; /** @brief 采集点顺序 */
  123. int threshold; /** @brief 边缘强度 */
  124. int cullDistance; /** @brief 滤波强度 */
  125. int CaliperHeight; /** @brief 卡尺高度 */
  126. int CaliperWidth; /** @brief 卡尺宽度 */
  127. };
  128. /** @brief 矩形参数 */
  129. struct JVision_API RectangleParameter
  130. {
  131. CRectangle* figure; /** @brief 同心矩形 区域 */
  132. std::string grayDirection; /** @brief 灰度方向 */
  133. std::string scanDirection; /** @brief 采集点顺序 */
  134. int threshold; /** @brief 边缘强度 */
  135. int cullDistance; /** @brief 滤波强度 */
  136. int segNums; /** @brief 寻找的数量 */
  137. int width; /** @brief 卡尺宽度 */
  138. int height; /** @brief 卡尺高度 */
  139. };
  140. /** @brief 照明矫正 */
  141. struct JVision_API IlluminateImgParameter
  142. {
  143. int cameraID; // 相机 id
  144. int min; // 最低阈值
  145. int max; // 最大阈值
  146. };
  147. /** @brief 图像预处理--亮度调节 */
  148. struct JVision_API ScaledImgParameter
  149. {
  150. int imgIdx; // 选择的图片标识
  151. int scaledAdd; // 相加系数
  152. double scaledMulti; // 相乘系数
  153. };
  154. /** @brief 图像预处理--亮度调节 */
  155. struct JVision_API ThresholdImgParameter
  156. {
  157. int imgIdx; // 选择的图片标识
  158. int thresholdMin; // 二值化分割最小值
  159. int thresholdMax; // 二值化分割最大值
  160. };
  161. // =====================================================
  162. // 返回值类型, 根据 E_LOCALIZATION_TYPE 对应
  163. // =====================================================
  164. /** @brief 模板定位算法返回的结果结构体 */
  165. struct JVision_API ModelLocalization_Result
  166. {
  167. Point RefPoint; /** @brief 参考点坐标 */
  168. Point ActualPoint[9]; /** @brief 结果坐标 */
  169. double Score[9]; /** @brief 模板匹配的得分 */
  170. double UsedTime; /** @brief 算法的总共耗时 */
  171. };
  172. /** @brief 双模板定位算法返回的结果结构体 */
  173. struct JVision_API DoubleModelLocalization_Result
  174. {
  175. ModelLocalization_Result resArr[2]; /** @brief 两个模板匹配的数组 */
  176. };
  177. /** @brief 角点定位算法返回的结果结构体 */
  178. struct JVision_API Corner_ModelLocalization_Result
  179. {
  180. bool isMark; /** @brief 是否启用模板跟随功能 */
  181. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  182. Point2D RefPoint; /** @brief 参考点坐标 */
  183. Point2D CrossPoint; /** @brief 两直线角点 */
  184. Point2D Line1Start; /** @brief 直线1的起始点坐标 */
  185. Point2D Line1End; /** @brief 直线1的终止点坐标 */
  186. Point2D Line2Start; /** @brief 直线1的起始点坐标 */
  187. Point2D Line2End; /** @brief 直线1的终止点坐标 */
  188. double Score; /** @brief 启用模板匹配时的得分 */
  189. double UsedTime; /** @brief 执行角点定位算法的总耗时 */
  190. };
  191. /** @brief 圆定位算法返回的结果结构体 */
  192. struct JVision_API Circle_ModelLocalization_Result
  193. {
  194. bool isMark; /** @brief 是否启用模板跟随功能 */
  195. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  196. Point2D RefPoint; /** @brief 参考点坐标 */
  197. CircleResult CirclePoint; /** @brief 圆心的坐标 */
  198. double Score; /** @brief 模板匹配的得分 */
  199. double UsedTime; /** @brief 圆定位算法的总耗时 */
  200. };
  201. /** @brief 直线定位算法返回的结果结构体 */
  202. struct JVision_API Line_ModelLocalization_Result
  203. {
  204. bool isMark; /** @brief 是否启用模板跟随功能 */
  205. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  206. Point2D RefPoint; /** @brief 参考点坐标 */
  207. Point2D LineStart; /** @brief 直线的起始点坐标 */
  208. Point2D LineEnd; /** @brief 直线的终止点坐标 */
  209. double Score; /** @brief 模板匹配的得分 */
  210. double UsedTime; /** @brief 直线定位的总耗时 */
  211. };
  212. /** @brief 双圆定位算法返回的结果结构体 */
  213. struct JVision_API Circles_ModelLocalization_Result
  214. {
  215. bool isMark; /** @brief 是否启用模板跟随功能 */
  216. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  217. Point2D RefPoint; /** @brief 参考点坐标 */
  218. double Score; /** @brief 模板匹配的得分 */
  219. double UsedTime; /** @brief 双圆定位的总耗时 */
  220. CircleResult CirclePointArr[2]; /** @brief 圆心坐标的数组 */
  221. };
  222. /** @brief 圆直线定位算法返回的结果结构体 */
  223. struct JVision_API CirCleLine_ModelLocalization_Result
  224. {
  225. bool isMark; /** @brief 是否启用模板跟随功能 */
  226. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  227. Point2D RefPoint; /** @brief 参考点坐标 */
  228. double Score; /** @brief 模板匹配得分 */
  229. double UsedTime; /** @brief 圆直线定位算法耗时 */
  230. // 圆形坐标
  231. CircleResult CirclePoint; /** @brief 圆心坐标 */
  232. // 直线坐标
  233. Point2D LineStart; /** @brief 直线的起始点坐标 */
  234. Point2D LineEnd; /** @brief 直线的终止点坐标 */
  235. };
  236. /** @brief 旋转矩形定位算法返回的结果结构体 */
  237. struct JVision_API RRectangle_ModelLocalization_Result
  238. {
  239. bool isMark; /** @brief 是否启用模板跟随功能 */
  240. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  241. Point2D RefPoint; /** @brief 参考点坐标 */
  242. double Score; /** @brief 模板匹配得分 */
  243. double UsedTime; /** @brief 旋转矩形定位算法耗时 */
  244. Point RectangleCenter; /** @brief 旋转矩形中心点 */
  245. Point2D CornerPointArr[4]; /** @brief 旋转矩形角点坐标的数组 */
  246. };
  247. /** @brief 胶量检测算法返回的结果结构体 */
  248. struct JVision_API Glue_Detection_Result
  249. {
  250. bool isMark; /** @brief 是否启用模板跟随功能 */
  251. Point ModelPoint; /** @brief 模板匹配结果坐标 */
  252. Point2D RefPoint; /** @brief 参考点坐标 */
  253. double Score; /** @brief 模板匹配得分 */
  254. double UsedTime; /** @brief 胶量检测算法耗时 */
  255. Point2D CornerPointArr[2]; /** @brief 矩形角点坐标的数组 */
  256. double area; /** @brief 胶体面积 */
  257. double roundness; /** @brief 圆度 */
  258. };
  259. }
  260. #endif