From c69f28ca41e1863b6ae4289c8543fbdb5eb84c9d Mon Sep 17 00:00:00 2001 From: jerryzeng Date: Sun, 11 Jan 2026 21:19:52 +0800 Subject: [PATCH] rodAndBarDetection code update: fix bugs for compile errors --- SG_Algorithm.sln | 7 +++++++ sourceCode/SG_baseAlgo_Export.h | 2 +- sourceCode/SG_baseFunc.cpp | 9 ++++++--- sourceCode/rodAndBarDetection.cpp | 3 +-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/SG_Algorithm.sln b/SG_Algorithm.sln index a1120dc..923c8a3 100644 --- a/SG_Algorithm.sln +++ b/SG_Algorithm.sln @@ -184,8 +184,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HC_channelSpaceMeasure_test EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rodAndBarDetection_test", "rodAndBarDetection_test\rodAndBarDetection_test.vcxproj", "{59F9508A-4295-4A7D-858C-7B4F0A7F8C82}" + ProjectSection(ProjectDependencies) = postProject + {95DC3F1A-902A-490E-BD3B-B10463CF0EBD} = {95DC3F1A-902A-490E-BD3B-B10463CF0EBD} + {AEC22DC1-FBE0-4D9C-B090-D4821A9D846B} = {AEC22DC1-FBE0-4D9C-B090-D4821A9D846B} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rodAndBarDetection", "rodAndBarDetection\rodAndBarDetection.vcxproj", "{AEC22DC1-FBE0-4D9C-B090-D4821A9D846B}" + ProjectSection(ProjectDependencies) = postProject + {95DC3F1A-902A-490E-BD3B-B10463CF0EBD} = {95DC3F1A-902A-490E-BD3B-B10463CF0EBD} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/sourceCode/SG_baseAlgo_Export.h b/sourceCode/SG_baseAlgo_Export.h index 268131a..eb7de69 100644 --- a/sourceCode/SG_baseAlgo_Export.h +++ b/sourceCode/SG_baseAlgo_Export.h @@ -554,7 +554,7 @@ SG_APISHARED_EXPORT SSG_planeCalibPara sg_getPlaneCalibPara2_ROI( SVzNL3DRangeD roi); //根据两个向量计算旋转矩阵 -SG_APISHARED_EXPORT SSG_planeCalibPara wd_conputeRTMatrix( +SG_APISHARED_EXPORT SSG_planeCalibPara wd_computeRTMatrix( SVzNL3DPoint& vector1, SVzNL3DPoint& vector2); diff --git a/sourceCode/SG_baseFunc.cpp b/sourceCode/SG_baseFunc.cpp index e1d9638..1b61b45 100644 --- a/sourceCode/SG_baseFunc.cpp +++ b/sourceCode/SG_baseFunc.cpp @@ -2417,7 +2417,7 @@ SSG_planeCalibPara sg_HCameraVScan_getGroundCalibPara( return planePara; } -SSG_planeCalibPara wd_conputeRTMatrix(SVzNL3DPoint& vector1, SVzNL3DPoint& vector2) +SSG_planeCalibPara wd_computeRTMatrix(SVzNL3DPoint& vector1, SVzNL3DPoint& vector2) { Vector3 a = Vector3(vector1.x, vector1.y, vector1.z); Vector3 b = Vector3(vector2.x, vector2.y, vector2.z); @@ -3107,9 +3107,12 @@ bool fitLine3DLeastSquares(const std::vector& points, SVzNL3DPoint center = { cx, cy, cz }; // 2. 构造去中心化的协方差矩阵(3x3) - Eigen::MatrixXd centered = A.rowwise() - Eigen::Vector3d(cx, cy, cz); - Eigen::Matrix3d cov = centered.transpose() * centered / (points.size() - 1); + // 关键修复:使用RowVector3d(行向量)做rowwise减法,匹配维度 + Eigen::RowVector3d centroid_row(cx, cy, cz); + Eigen::MatrixXd centered = A.rowwise() - centroid_row; // 维度匹配,无报错 + // 协方差矩阵计算(n-1为无偏估计,工程中也可直接用n) + Eigen::Matrix3d cov = centered.transpose() * centered / (points.size() - 1); // 3. 特征值分解:求协方差矩阵的特征值和特征向量 Eigen::SelfAdjointEigenSolver eigensolver(cov); if (eigensolver.info() != Eigen::Success) { diff --git a/sourceCode/rodAndBarDetection.cpp b/sourceCode/rodAndBarDetection.cpp index c60a96f..1eabc5f 100644 --- a/sourceCode/rodAndBarDetection.cpp +++ b/sourceCode/rodAndBarDetection.cpp @@ -124,7 +124,6 @@ SVzNL3DPoint _ptRotate(SVzNL3DPoint pt3D, double matrix3d[9]) int* errCode) { *errCode = 0; - SSX_hexHeadScrewInfo screwInfo; memset(&screwInfo, 0, sizeof(SSX_hexHeadScrewInfo)); int lineNum = (int)scanLines.size(); if (lineNum == 0) @@ -250,7 +249,7 @@ SVzNL3DPoint _ptRotate(SVzNL3DPoint pt3D, double matrix3d[9]) //计算旋转向量 SVzNL3DPoint vector1 = P1_dir; SVzNL3DPoint vector2 = { 0, 0, -1.0 }; - SSG_planeCalibPara rotatePara = wd_conputeRTMatrix( vector1, vector2); + SSG_planeCalibPara rotatePara = wd_computeRTMatrix( vector1, vector2); // SSG_ROIRectD roi_xoy; roi_xoy.left = P0_center.x - rodRidius * 4; //2D范围