#ifndef __COMMON_UTILS_H__ #define __COMMON_UTILS_H__ // ***************************************************************************** // 版权所有(C)2023~2099 上海骄成超声波技术有限公司 // 保留所有权利 // ***************************************************************************** // 作者 : 陆蕴凡 // 版本 : 1.0 // 代码创建日期:2025/01/10 // 版本更新日期:2025/01/10 // 功能说明:公共工具 // ***************************************************************************** #include "TypeDef.h" #include "Figure.h" class BaseItem; namespace JVision { /** @brief 权限等级的枚举体 */ enum class JVision_API E_PERMISSION_LEVEL : int { E_PERMISSION_USER = 0, /**< 用户 */ E_PERMISSION_ADMIN, /**< 管理员 */ E_PERMISSION_SUPER_ADMIN, /**< 超级管理员 */ }; /** @brief 定位算法的枚举体 */ enum class JVision_API E_LOCALIZATION_TYPE : int { E_LOCALIZATION_INVALID = 0, /**< 无效值 */ E_MODEL_LOCATION, /**< 模板定位 */ E_DOUBLE_MODEL_LOCATION, /**< 双模板定位 */ E_LINE_LOCATION, /**< 直线定位 */ E_CORNER_LOCATION, /**< 角点定位 */ E_CIRCLE_LOCATION, /**< 圆定位 */ E_DOUBLE_CIRCLE_LOCATION, /**< 双圆定位 */ E_CIRCLE_LINE_LOCATION, /**< 圆直线定位 */ E_RRECTANGLE_LOCATION, /**< 矩形定位 */ E_NINESQUARE_LOCATION, /**< 九宫格搜索 */ E_GLUE_DETECT, /**< 胶量检测 */ E_LOCATION_MAX, /**< 最大值 */ }; /** @brief 算法参数ID的枚举体 */ enum class JVision_API E_LOCALIZATION_PARAM : ParamID { E_LOCALIZATION_PARAM_INVALID = 0, /**< 无效参数 */ E_LOCALIZATION_PARAM_MARK, /**< Mark */ E_LOCALIZATION_PARAM_SEARCH, /**< 搜索区域 */ E_LOCALIZATION_PARAM_CIRCLE, /**< 圆区域 */ E_LOCALIZATION_PARAM_LINE, /**< 直线区域 */ E_LOCALIZATION_PARAM_RECTANGLE, /**< 矩形区域 */ E_LOCALIZATION_PARAM_GLUE, /**< 胶量检测 */ E_LOCALIZATION_PARAM_SCALED_IMG, /**< 图像预处理--亮度调节 */ E_LOCALIZATION_PARAM_BINARY_IMG, /**< 图像预处理--二值化分割 */ E_LOCALIZATION_PARAM_MAX, /**< 参数最大值 */ }; // ===================================================== // 参数类型, 根据 E_LOCALIZATION_PARAM 对应 // ===================================================== /** @brief Mark 参数 */ struct JVision_API MarkParameter { BaseFigure* figure; /** @brief Mark区域 */ BaseFigure* mask; /** @brief Mask */ Line* referencePoint; /** @brief 参考点 */ int start; /** @brief 起始角度 */ int end; /** @brief 搜索角度 */ std::string pyrimid; /** @brief 图形金字塔层数 */ std::string searchPo; /** @brief 匹配指标 */ bool UseContour; /** @brief 是否使用轮廓匹配*/ }; /** @brief 搜索参数 */ struct JVision_API SearchParameter { BaseFigure* figure; /** @brief 搜索区域 */ int start; /** @brief 起始角度 */ int end; /** @brief 搜索角度 */ int pyrimid; /** @brief 图像金字塔层数 */ int matchCount; /** @brief 匹配个数 */ double minScore; /** @brief 最低分数 */ double overlap; /** @brief 最大重叠比例 */ bool isSubPix; /** @brief 是否使用亚像素精确 */ bool isDetect; /** @brief 是否使用墨点检测 */ }; /** @brief 胶量检测参数 */ struct JVision_API GlueParameter { BaseFigure* figure; int methodIndex; int threshMin; int threshMax; int areaMin; int areaMax; }; /** @brief 同心圆参数 */ struct JVision_API CCircleParameter { CCircle* figure; /** @brief 同心圆区域 */ std::string grayDirection; /** @brief 灰度方向 */ std::string scanDirection; /** @brief 采集点顺序 */ int threshold; /** @brief 边缘强度 */ int cullDistance; /** @brief 滤波强度 */ int SegNums; /** @brief 寻找的数量 */ int UnitWidth; /** @brief 卡尺宽度 */ int UnitLength; /** @brief 卡尺高度 */ }; /** @brief 圆参数 */ struct JVision_API CircleParameter { Circle* figure; /** @brief 同心圆区域 */ std::string grayDirection; /** @brief 灰度方向 */ std::string scanDirection; /** @brief 采集点顺序 */ int threshold; /** @brief 边缘强度 */ int cullDistance; /** @brief 滤波强度 */ int SegNums; /** @brief 寻找的数量 */ int UnitWidth; /** @brief 卡尺宽度 */ int UnitLength; /** @brief 卡尺高度 */ }; /** @brief 直线参数 */ struct JVision_API LineParameter { Caliper* figure; /** @brief 卡尺区域 */ std::string grayDirection; /** @brief 灰度方向 */ std::string scanDirection; /** @brief 采集点顺序 */ int threshold; /** @brief 边缘强度 */ int cullDistance; /** @brief 滤波强度 */ int CaliperHeight; /** @brief 卡尺高度 */ int CaliperWidth; /** @brief 卡尺宽度 */ }; /** @brief 矩形参数 */ struct JVision_API RectangleParameter { CRectangle* figure; /** @brief 同心矩形 区域 */ std::string grayDirection; /** @brief 灰度方向 */ std::string scanDirection; /** @brief 采集点顺序 */ int threshold; /** @brief 边缘强度 */ int cullDistance; /** @brief 滤波强度 */ int segNums; /** @brief 寻找的数量 */ int width; /** @brief 卡尺宽度 */ int height; /** @brief 卡尺高度 */ }; /** @brief 照明矫正 */ struct JVision_API IlluminateImgParameter { int cameraID; // 相机 id int min; // 最低阈值 int max; // 最大阈值 }; /** @brief 图像预处理--亮度调节 */ struct JVision_API ScaledImgParameter { int imgIdx; // 选择的图片标识 int scaledAdd; // 相加系数 double scaledMulti; // 相乘系数 }; /** @brief 图像预处理--亮度调节 */ struct JVision_API ThresholdImgParameter { int imgIdx; // 选择的图片标识 int thresholdMin; // 二值化分割最小值 int thresholdMax; // 二值化分割最大值 }; // ===================================================== // 返回值类型, 根据 E_LOCALIZATION_TYPE 对应 // ===================================================== /** @brief 模板定位算法返回的结果结构体 */ struct JVision_API ModelLocalization_Result { Point RefPoint; /** @brief 参考点坐标 */ Point ActualPoint[9]; /** @brief 结果坐标 */ double Score[9]; /** @brief 模板匹配的得分 */ double UsedTime; /** @brief 算法的总共耗时 */ }; /** @brief 双模板定位算法返回的结果结构体 */ struct JVision_API DoubleModelLocalization_Result { ModelLocalization_Result resArr[2]; /** @brief 两个模板匹配的数组 */ }; /** @brief 角点定位算法返回的结果结构体 */ struct JVision_API Corner_ModelLocalization_Result { bool isMark; /** @brief 是否启用模板跟随功能 */ Point ModelPoint; /** @brief 模板匹配结果坐标 */ Point2D RefPoint; /** @brief 参考点坐标 */ Point2D CrossPoint; /** @brief 两直线角点 */ Point2D Line1Start; /** @brief 直线1的起始点坐标 */ Point2D Line1End; /** @brief 直线1的终止点坐标 */ Point2D Line2Start; /** @brief 直线1的起始点坐标 */ Point2D Line2End; /** @brief 直线1的终止点坐标 */ double Score; /** @brief 启用模板匹配时的得分 */ double UsedTime; /** @brief 执行角点定位算法的总耗时 */ }; /** @brief 圆定位算法返回的结果结构体 */ struct JVision_API Circle_ModelLocalization_Result { bool isMark; /** @brief 是否启用模板跟随功能 */ Point ModelPoint; /** @brief 模板匹配结果坐标 */ Point2D RefPoint; /** @brief 参考点坐标 */ CircleResult CirclePoint; /** @brief 圆心的坐标 */ double Score; /** @brief 模板匹配的得分 */ double UsedTime; /** @brief 圆定位算法的总耗时 */ }; /** @brief 直线定位算法返回的结果结构体 */ struct JVision_API Line_ModelLocalization_Result { bool isMark; /** @brief 是否启用模板跟随功能 */ Point ModelPoint; /** @brief 模板匹配结果坐标 */ Point2D RefPoint; /** @brief 参考点坐标 */ Point2D LineStart; /** @brief 直线的起始点坐标 */ Point2D LineEnd; /** @brief 直线的终止点坐标 */ double Score; /** @brief 模板匹配的得分 */ double UsedTime; /** @brief 直线定位的总耗时 */ }; /** @brief 双圆定位算法返回的结果结构体 */ struct JVision_API Circles_ModelLocalization_Result { bool isMark; /** @brief 是否启用模板跟随功能 */ Point ModelPoint; /** @brief 模板匹配结果坐标 */ Point2D RefPoint; /** @brief 参考点坐标 */ double Score; /** @brief 模板匹配的得分 */ double UsedTime; /** @brief 双圆定位的总耗时 */ CircleResult CirclePointArr[2]; /** @brief 圆心坐标的数组 */ }; /** @brief 圆直线定位算法返回的结果结构体 */ struct JVision_API CirCleLine_ModelLocalization_Result { bool isMark; /** @brief 是否启用模板跟随功能 */ Point ModelPoint; /** @brief 模板匹配结果坐标 */ Point2D RefPoint; /** @brief 参考点坐标 */ double Score; /** @brief 模板匹配得分 */ double UsedTime; /** @brief 圆直线定位算法耗时 */ // 圆形坐标 CircleResult CirclePoint; /** @brief 圆心坐标 */ // 直线坐标 Point2D LineStart; /** @brief 直线的起始点坐标 */ Point2D LineEnd; /** @brief 直线的终止点坐标 */ }; /** @brief 旋转矩形定位算法返回的结果结构体 */ struct JVision_API RRectangle_ModelLocalization_Result { bool isMark; /** @brief 是否启用模板跟随功能 */ Point ModelPoint; /** @brief 模板匹配结果坐标 */ Point2D RefPoint; /** @brief 参考点坐标 */ double Score; /** @brief 模板匹配得分 */ double UsedTime; /** @brief 旋转矩形定位算法耗时 */ Point RectangleCenter; /** @brief 旋转矩形中心点 */ Point2D CornerPointArr[4]; /** @brief 旋转矩形角点坐标的数组 */ }; /** @brief 胶量检测算法返回的结果结构体 */ struct JVision_API Glue_Detection_Result { bool isMark; /** @brief 是否启用模板跟随功能 */ Point ModelPoint; /** @brief 模板匹配结果坐标 */ Point2D RefPoint; /** @brief 参考点坐标 */ double Score; /** @brief 模板匹配得分 */ double UsedTime; /** @brief 胶量检测算法耗时 */ Point2D CornerPointArr[2]; /** @brief 矩形角点坐标的数组 */ double area; /** @brief 胶体面积 */ double roundness; /** @brief 圆度 */ }; } #endif