孔检测更新算法

This commit is contained in:
yiyi 2026-04-08 00:05:43 +08:00
parent 807df6c110
commit 7725f9ce8d
20 changed files with 130 additions and 132 deletions

View File

@ -205,14 +205,15 @@ int HoleDetectionPresenter::InitAlgoParams()
const VrAlgorithmParams& xmlParams = configResult.algorithmParams;
LOG_INFO("Loaded XML params - Ransac: distanceThreshold=%.2f, maxIterations=%d, minPlanePoints=%d, maxPlanes=%d, growthZThreshold=%.2f, minPlaneRatio=%.2f, maxNormalAngleDeg=%.1f\n",
LOG_INFO("Loaded XML params - Ransac: distanceThreshold=%.2f, maxIterations=%d, minPlanePoints=%d, maxPlanes=%d, growthZThreshold=%.2f, minPlaneRatio=%.2f, maxNormalAngleDeg=%.1f, maxDistFromPlane=%.2f\n",
xmlParams.ransacParam.distanceThreshold,
xmlParams.ransacParam.maxIterations,
xmlParams.ransacParam.minPlanePoints,
xmlParams.ransacParam.maxPlanes,
xmlParams.ransacParam.growthZThreshold,
xmlParams.ransacParam.minPlaneRatio,
xmlParams.ransacParam.maxNormalAngleDeg);
xmlParams.ransacParam.maxNormalAngleDeg,
xmlParams.ransacParam.maxDistFromPlane);
LOG_INFO("Loaded XML params - Detection: angleThresholdPos=%.1f, angleThresholdNeg=%.1f, angleSearchDistance=%.2f, minPitDepth=%.2f\n",
xmlParams.detectionParam.angleThresholdPos,

View File

@ -5,7 +5,7 @@
#define HOLEDETECTION_APP_NAME "孔洞检测"
// 版本字符串
#define HOLEDETECTION_VERSION_STRING "1.1.5"
#define HOLEDETECTION_VERSION_STRING "1.1.6"
#define HOLEDETECTION_BUILD_STRING "1"
#define HOLEDETECTION_FULL_VERSION_STRING "V" HOLEDETECTION_VERSION_STRING "_" HOLEDETECTION_BUILD_STRING

View File

@ -1,3 +1,7 @@
## 1.1.6 2026-04-07
* build_1
1. 更新算法 1.0.3
## 1.1.5 2026-04-05
* build_1
1. 更新算法 1.0.2

View File

@ -301,6 +301,7 @@ void DialogAlgoarg::LoadRansacParamToUI(const VrRansacPlaneSegmentationParam& pa
ui->lineEdit_growthZThreshold->setText(QString::number(param.growthZThreshold));
ui->lineEdit_minPlaneRatio->setText(QString::number(param.minPlaneRatio));
ui->lineEdit_maxNormalAngleDeg->setText(QString::number(param.maxNormalAngleDeg));
ui->lineEdit_maxDistFromPlane->setText(QString::number(param.maxDistFromPlane));
}
void DialogAlgoarg::LoadDetectionParamToUI(const VrHoleDetectionParam& param)
@ -381,6 +382,9 @@ bool DialogAlgoarg::SaveRansacParamFromUI(VrRansacPlaneSegmentationParam& param)
param.maxNormalAngleDeg = ui->lineEdit_maxNormalAngleDeg->text().toDouble(&ok);
if (!ok) return false;
param.maxDistFromPlane = ui->lineEdit_maxDistFromPlane->text().toDouble(&ok);
if (!ok) return false;
return true;
}

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>920</width>
<height>584</height>
<height>613</height>
</rect>
</property>
<property name="windowTitle">
@ -84,7 +84,7 @@ QScrollArea { border: none; }</string>
<x>0</x>
<y>0</y>
<width>860</width>
<height>412</height>
<height>441</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_ransac">
@ -178,6 +178,16 @@ QScrollArea { border: none; }</string>
<item row="6" column="1">
<widget class="QLineEdit" name="lineEdit_maxNormalAngleDeg"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_maxDistFromPlane">
<property name="text">
<string>点到平面最大允许距离 (mm):</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="lineEdit_maxDistFromPlane"/>
</item>
</layout>
</widget>
</item>
@ -216,7 +226,7 @@ QScrollArea { border: none; }</string>
<x>0</x>
<y>0</y>
<width>860</width>
<height>412</height>
<height>441</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_detection">
@ -435,7 +445,7 @@ QScrollArea { border: none; }</string>
<x>0</x>
<y>0</y>
<width>860</width>
<height>412</height>
<height>441</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_filter">

View File

@ -1,121 +1,91 @@
#ifndef IVRCONFIG_H
#define IVRCONFIG_H
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
// 包含公共配置结构体
#include "VrCommonConfig.h"
#include "VrHandEyeCalibConfig.h"
/**
* @brief RANSAC RansacPlaneSegmentationParams
*/
struct VrRansacPlaneSegmentationParam
{
double distanceThreshold = 0.5; // 点到平面距离阈值mm
int maxIterations = 500; // RANSAC 最大迭代次数
int minPlanePoints = 100; // 最小平面点数
int maxPlanes = 5; // 最大提取平面数量
double growthZThreshold = 1.0; // 区域生长时相邻点 Z 差阈值mm
double minPlaneRatio = 0.1; // 平面最小点数占比
double maxNormalAngleDeg = 30.0; // 平面法向量与Z轴最大夹角<=0 表示不过滤
double distanceThreshold = 0.5;
int maxIterations = 500;
int minPlanePoints = 100;
int maxPlanes = 5;
double growthZThreshold = 1.0;
double minPlaneRatio = 0.1;
double maxNormalAngleDeg = 30.0;
double maxDistFromPlane = 1.0;
};
/**
* @brief SHoleDetectionParams
*/
struct VrHoleDetectionParam
{
double angleThresholdPos = 50.0; // 正角度阈值(度)
double angleThresholdNeg = -50.0; // 负角度阈值(度)
double angleSearchDistance = 2.0; // 前后搜索距离 Amm
double minPitDepth = 1.0; // 最小凹坑深度mm
double minRadius = 2.0; // 最小孔半径mm
double maxRadius = 50.0; // 最大孔半径mm
int expansionSize1 = 5; // 第一环扩展大小
int expansionSize2 = 10; // 第二环扩展大小
int minVTransitionPoints = 1; // V 形端点间最小有效过渡点数
double jumpThresholdResidual = 0.0; // 相邻有效点残差跳变阈值
double gapJumpThresholdResidual = 0.0; // 跨无效点间隙残差跳变阈值
int maxGapPointsInLine = 12; // 允许跨越的最大无效点数
double minFeatureSpan = 2.0; // 特征点对最小弧长跨度mm
int residualSmoothWindow = 5; // 残差平滑窗口
double slopeAngleThreshold = 3.0; // 坡度补充判断阈值(度)
double edgeBoundaryFilterDist = 0.0; // 边缘过滤距离mm
double angleThresholdPos = 50.0;
double angleThresholdNeg = -50.0;
double angleSearchDistance = 2.0;
double minPitDepth = 1.0;
double minRadius = 2.0;
double maxRadius = 50.0;
int expansionSize1 = 5;
int expansionSize2 = 10;
int minVTransitionPoints = 1;
double jumpThresholdResidual = 0.0;
double gapJumpThresholdResidual = 0.0;
int maxGapPointsInLine = 12;
double minFeatureSpan = 2.0;
int residualSmoothWindow = 5;
double slopeAngleThreshold = 3.0;
double edgeBoundaryFilterDist = 0.0;
};
/**
* @brief SHoleFilterParams
*/
struct VrHoleFilterParam
{
double maxEccentricity = 0.99995; // 最大离心率
double minAngularCoverage = 10.0; // 最小角度覆盖(度)
double maxRadiusFitRatio = 1.0; // 最大半径拟合比率
double minQualityScore = 0.0; // 最小质量分数
double maxPlaneResidual = 10.0; // 最大平面残差mm
double maxAngularGap = 90.0; // 最大角度间隙(度)
double minInlierRatio = 0.0; // 最小内点比率
double minHoleDepth = 2.5; // 最小孔深mm
double maxEccentricity = 0.99995;
double minAngularCoverage = 10.0;
double maxRadiusFitRatio = 1.0;
double minQualityScore = 0.0;
double maxPlaneResidual = 10.0;
double maxAngularGap = 90.0;
double minInlierRatio = 0.0;
double minHoleDepth = 2.5;
};
/**
* @brief ESortMode
*/
enum VrHoleSortMode
{
HOLE_SORT_NONE = 0, // 不排序
HOLE_SORT_BY_RADIUS = 1, // 按半径排序(最大优先)
HOLE_SORT_BY_DEPTH = 2, // 按深度排序(最深优先)
HOLE_SORT_BY_QUALITY = 3 // 按质量分数排序(最高优先)
HOLE_SORT_NONE = 0,
HOLE_SORT_BY_RADIUS = 1,
HOLE_SORT_BY_DEPTH = 2,
HOLE_SORT_BY_QUALITY = 3
};
/**
* @brief 姿
*
* 姿
*/
enum VrPoseOutputOrder
{
POSE_ORDER_RPY = 0, // Roll, Pitch, Yaw默认
POSE_ORDER_RYP = 1, // Roll, Yaw, Pitch
POSE_ORDER_PRY = 2, // Pitch, Roll, Yaw
POSE_ORDER_PYR = 3, // Pitch, Yaw, Roll
POSE_ORDER_YRP = 4, // Yaw, Roll, Pitch
POSE_ORDER_YPR = 5 // Yaw, Pitch, Roll
POSE_ORDER_RPY = 0,
POSE_ORDER_RYP = 1,
POSE_ORDER_PRY = 2,
POSE_ORDER_PYR = 3,
POSE_ORDER_YRP = 4,
POSE_ORDER_YPR = 5
};
/**
* @brief
*
*
*
*/
enum VrDirVectorInvert
{
DIR_INVERT_NONE = 0, // 不反向
DIR_INVERT_XY = 1, // X 和 Y 方向反向
DIR_INVERT_XZ = 2, // X 和 Z 方向反向
DIR_INVERT_YZ = 3 // Y 和 Z 方向反向(默认,兼容原有行为)
DIR_INVERT_NONE = 0,
DIR_INVERT_XY = 1,
DIR_INVERT_XZ = 2,
DIR_INVERT_YZ = 3
};
/**
* @brief TCP
*
* Doc/porotol.jpg
* - PLC-easy320: 192.168.0.88:502
* - : 192.168.0.90:502
*/
struct VrPlcRobotServerConfig
{
int tcpServerPort = 7800; // TCP 协议服务端口
int poseOutputOrder = POSE_ORDER_RPY; // 姿态输出顺序,默认 RPY
int dirVectorInvert = DIR_INVERT_YZ; // 方向向量反向配置,默认 YZ 反向
int tcpServerPort = 7800;
int poseOutputOrder = POSE_ORDER_RPY;
int dirVectorInvert = DIR_INVERT_YZ;
VrPlcRobotServerConfig& operator=(const VrPlcRobotServerConfig& other) {
if (this != &other) {
@ -135,16 +105,13 @@ struct VrPlcRobotServerConfig
VrPlcRobotServerConfig() = default;
};
/**
* @brief
*/
struct VrAlgorithmParams
{
VrRansacPlaneSegmentationParam ransacParam; // RANSAC 平面分割参数
VrHoleDetectionParam detectionParam;// 孔洞检测参数
VrHoleFilterParam filterParam; // 孔洞过滤参数
int sortMode = HOLE_SORT_NONE; // 排序模式
VrPlaneCalibParam planeCalibParam; // 平面校准参数
VrRansacPlaneSegmentationParam ransacParam;
VrHoleDetectionParam detectionParam;
VrHoleFilterParam filterParam;
int sortMode = HOLE_SORT_NONE;
VrPlaneCalibParam planeCalibParam;
VrAlgorithmParams& operator=(const VrAlgorithmParams& other) {
if (this != &other) {
@ -168,18 +135,15 @@ struct VrAlgorithmParams
VrAlgorithmParams() = default;
};
/**
* @brief
*/
struct ConfigResult
{
std::vector<DeviceInfo> cameraList;
std::vector<DeviceInfo> deviceList;
VrAlgorithmParams algorithmParams; // 算法参数
std::vector<VrHandEyeCalibMatrix> handEyeCalibMatrixList; // 多相机手眼标定矩阵列表
VrDebugParam debugParam; // 调试参数
SerialConfig serialConfig; // 串口配置
VrPlcRobotServerConfig plcRobotServerConfig; // PLC 和机械臂服务端配置
std::vector<DeviceInfo> cameraList;
std::vector<DeviceInfo> deviceList;
VrAlgorithmParams algorithmParams;
std::vector<VrHandEyeCalibMatrix> handEyeCalibMatrixList;
VrDebugParam debugParam;
SerialConfig serialConfig;
VrPlcRobotServerConfig plcRobotServerConfig;
ConfigResult& operator=(const ConfigResult& other) {
if (this != &other) {
@ -207,21 +171,15 @@ struct ConfigResult
ConfigResult() = default;
};
/**
* @brief
*/
enum LoadConfigErrorCode
{
LOAD_CONFIG_SUCCESS = 0, // 加载成功
LOAD_CONFIG_FILE_NOT_FOUND = -1, // 配置文件不存在
LOAD_CONFIG_PARSE_ERROR = -2, // 配置文件解析错误
LOAD_CONFIG_INVALID_FORMAT = -3, // 配置文件格式无效
LOAD_CONFIG_UNKNOWN_ERROR = -99 // 未知错误
LOAD_CONFIG_SUCCESS = 0,
LOAD_CONFIG_FILE_NOT_FOUND = -1,
LOAD_CONFIG_PARSE_ERROR = -2,
LOAD_CONFIG_INVALID_FORMAT = -3,
LOAD_CONFIG_UNKNOWN_ERROR = -99
};
/**
* @brief VrConfig
*/
class IVrConfig
{
public:

View File

@ -14,6 +14,7 @@ RansacPlaneSegmentationParams ToAlgoParam(const VrRansacPlaneSegmentationParam&
algo.growthZThreshold = static_cast<float>(param.growthZThreshold);
algo.minPlaneRatio = static_cast<float>(param.minPlaneRatio);
algo.maxNormalAngleDeg = static_cast<float>(param.maxNormalAngleDeg);
algo.maxDistFromPlane = static_cast<float>(param.maxDistFromPlane);
return algo;
}
@ -66,7 +67,7 @@ void LogAlgoParams(const std::string& logTag,
clibMatrix[8], clibMatrix[9], clibMatrix[10], clibMatrix[11],
clibMatrix[12], clibMatrix[13], clibMatrix[14], clibMatrix[15]);
LOG_INFO("%s RansacParams: distanceThreshold=%.2f, maxIterations=%d, minPlanePoints=%d, maxPlanes=%d, growthZThreshold=%.2f, minPlaneRatio=%.2f, maxNormalAngleDeg=%.1f\n",
LOG_INFO("%s RansacParams: distanceThreshold=%.2f, maxIterations=%d, minPlanePoints=%d, maxPlanes=%d, growthZThreshold=%.2f, minPlaneRatio=%.2f, maxNormalAngleDeg=%.1f, maxDistFromPlane=%.2f\n",
logTag.c_str(),
ransacParams.distanceThreshold,
ransacParams.maxIterations,
@ -74,7 +75,8 @@ void LogAlgoParams(const std::string& logTag,
ransacParams.maxPlanes,
ransacParams.growthZThreshold,
ransacParams.minPlaneRatio,
ransacParams.maxNormalAngleDeg);
ransacParams.maxNormalAngleDeg,
ransacParams.maxDistFromPlane);
LOG_INFO("%s DetectionParams: angleThresholdPos=%.1f, angleThresholdNeg=%.1f, angleSearchDistance=%.2f, minPitDepth=%.2f\n",
logTag.c_str(),

View File

@ -78,6 +78,8 @@ int CVrConfig::LoadConfig(const std::string& filePath, ConfigResult& configResul
configResult.algorithmParams.ransacParam.minPlaneRatio = ransacParamElement->DoubleAttribute("minPlaneRatio");
if (ransacParamElement->Attribute("maxNormalAngleDeg"))
configResult.algorithmParams.ransacParam.maxNormalAngleDeg = ransacParamElement->DoubleAttribute("maxNormalAngleDeg");
if (ransacParamElement->Attribute("maxDistFromPlane"))
configResult.algorithmParams.ransacParam.maxDistFromPlane = ransacParamElement->DoubleAttribute("maxDistFromPlane");
}
XMLElement* detectionParamElement = algoParamsElement->FirstChildElement("DetectionParam");
@ -212,6 +214,7 @@ bool CVrConfig::SaveConfig(const std::string& filePath, ConfigResult& configResu
ransacParamElement->SetAttribute("growthZThreshold", configResult.algorithmParams.ransacParam.growthZThreshold);
ransacParamElement->SetAttribute("minPlaneRatio", configResult.algorithmParams.ransacParam.minPlaneRatio);
ransacParamElement->SetAttribute("maxNormalAngleDeg", configResult.algorithmParams.ransacParam.maxNormalAngleDeg);
ransacParamElement->SetAttribute("maxDistFromPlane", configResult.algorithmParams.ransacParam.maxDistFromPlane);
algoParamsElement->InsertEndChild(ransacParamElement);
// 检测参数 DetectionParam 需要覆盖算法库当前全部检测字段。

View File

@ -14,7 +14,9 @@
minPlanePoints="100"
maxPlanes="5"
growthZThreshold="1.0"
minPlaneRatio="0.1"/>
minPlaneRatio="0.1"
maxNormalAngleDeg="30.0"
maxDistFromPlane="1.0"/>
<DetectionParam
angleThresholdPos="50.0"
angleThresholdNeg="-50.0"

View File

@ -187,15 +187,20 @@ int DetectPresenter::DetectScrew(
double y_scale = (yMax - yMin) / y_rows;
// 使用统一的比例尺
if (x_scale < y_scale)
x_scale = y_scale;
else
y_scale = x_scale;
double scale = std::max(x_scale, y_scale);
x_scale = scale;
y_scale = scale;
// 计算居中偏移与GeneratePointCloudRetPointImage保持一致
double cloudWidth = (xMax - xMin) / scale;
double cloudHeight = (yMax - yMin) / scale;
int x_offset = x_skip + (int)((x_cols - cloudWidth) / 2);
int y_offset = y_skip + (int)((y_rows - cloudHeight) / 2);
// 转换3D坐标到图像坐标的lambda函数
auto toImageCoord = [&](const SVzNL3DPoint& pt) -> QPointF {
int px = (int)((pt.x - xMin) / x_scale + x_skip);
int py = (int)((pt.y - yMin) / y_scale + y_skip);
int px = (int)((pt.x - xMin) / x_scale + x_offset);
int py = (int)((pt.y - yMin) / y_scale + y_offset);
return QPointF(px, py);
};

View File

@ -2,7 +2,7 @@
#define VERSION_H
#define SCREWPOSITION_VERSION_STRING "1.0.0"
#define SCREWPOSITION_VERSION_STRING "1.1.0"
#define SCREWPOSITION_BUILD_STRING "1"
#define SCREWPOSITION_FULL_VERSION_STRING "V" SCREWPOSITION_VERSION_STRING "_" SCREWPOSITION_BUILD_STRING

View File

@ -16,6 +16,8 @@ struct RansacPlaneSegmentationParams {
float minPlaneRatio; // 平面最小点数占比 (相对最大平面), 建议 0.05-0.2
float maxNormalAngleDeg; // 平面法向量与Z轴最大夹角 (度), 超过则直接丢弃; <=0 表示不过滤
float maxDistFromPlane; // 点到平面的最大允许距离;超出则从 pointIndices 中移除;<=0 表示不过滤
RansacPlaneSegmentationParams()
: distanceThreshold(0.5f)
, maxIterations(500)
@ -24,6 +26,7 @@ struct RansacPlaneSegmentationParams {
, growthZThreshold(1.0f)
, minPlaneRatio(0.1f)
, maxNormalAngleDeg(30.0f)
, maxDistFromPlane(1.f)
{
}
};

View File

@ -6,7 +6,7 @@
|:---:|:--------|:---------|:------------|
| 1 | 自动拆包 | GrabBag | 1.3.6.2 |
| 2 | 皮带撕裂 | BeltTearingServer | 2.0.8.1 |
| 3 | 孔洞检测 | HoleDetection | 1.1.3.1 |
| 3 | 孔洞检测 | HoleDetection | 1.1.6.1 |
| 4 | 棒材定位 | RodAndBarPosition | 1.0.2.1 |
| 5 | 车轮拱高测量 | WheelMeasure | 1.0.2.1 |
| 6 | 定子定位 | StatorPosition | 1.0.0.1 |
@ -15,7 +15,7 @@
| 9 | 颗粒尺寸检测 | ParticleSize | 1.0.0.0 |
| 10 | 双目标记检测 | BinocularMarkServer | 1.0.0.4 |
| 11 | 铁路隧道槽道测量 | TunnelChannel | 1.0.0.3 |
| 12 | 螺杆定位 | ScrewPosition | 1.0.0.1 |
| 12 | 螺杆定位 | ScrewPosition | 1.1.0.1 |
| 13 | 包裹拆线位置定位 | BagThreadPosition | 1.0.0.4 |
| 14 | 工件孔定位 | WorkpieceHole | 1.0.3.0 |
| 16 | 坑孔定位 | HolePitPosition | 无 |

View File

@ -65,6 +65,12 @@ echo "复制 Qt 运行时环境..."
cp -rfd ${QT_PKG_PATH}/ext ${PKG_PATH}/opt/firefly_qt5.15
cp ${QT_PKG_PATH}/target_qtEnv.sh ${PKG_PATH}/etc/profile.d/
echo "清理不需要的 Qt WebEngine 库文件..."
rm -f ${PKG_PATH}/opt/firefly_qt5.15/lib/libQt5WebEngine*
rm -rf ${PKG_PATH}/opt/firefly_qt5.15/libexec/QtWebEngineProcess
rm -rf ${PKG_PATH}/opt/firefly_qt5.15/resources/qtwebengine*
rm -rf ${PKG_PATH}/opt/firefly_qt5.15/translations/qtwebengine*
# 复制 Qt 库文件
for libfile in ${QT_LIB_PATH}/*.so*; do
# 获取文件名用于比较

View File

@ -85,7 +85,7 @@ declare -A PROJECT_CHINESE_NAMES=(
)
# 应用列表文件路径
APP_LIST_FILE="应用列表及说明.md"
APP_LIST_FILE="AppList.md"
# 获取脚本所在目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"