From a582a10491f922c3275280a3753d250cf8ae67b4 Mon Sep 17 00:00:00 2001 From: jerryzeng Date: Tue, 9 Dec 2025 18:37:43 +0800 Subject: [PATCH] =?UTF-8?q?bagPosition=20version=201.1.0=20=EF=BC=881?= =?UTF-8?q?=EF=BC=89=E7=89=88=E6=9C=AC=E5=8F=B7=EF=BC=882=EF=BC=89?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=A8=A1=E5=BC=8F=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8C=89=E5=BA=8F=E8=BE=93=E5=87=BA=E5=92=8C=E6=8C=89=E5=A4=A7?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bagPositioning_test/bagPositioning_test.cpp | 4 + sourceCode/SG_bagPositioning.cpp | 86 +++++++++++++-------- sourceCode/SG_bagPositioning_Export.h | 4 + sourceCode/SG_baseAlgo_Export.h | 20 +++++ sourceCode/SG_baseFunc.cpp | 9 +++ 5 files changed, 91 insertions(+), 32 deletions(-) diff --git a/bagPositioning_test/bagPositioning_test.cpp b/bagPositioning_test/bagPositioning_test.cpp index 32af194..298a5d7 100644 --- a/bagPositioning_test/bagPositioning_test.cpp +++ b/bagPositioning_test/bagPositioning_test.cpp @@ -2707,9 +2707,13 @@ int main() for (int i = 0; i < 9; i++) poseCalibPara.invRMatrix[i] = poseCalibPara.planeCalib[i]; + const char* ver = sg_bagPositioningVersion(); + printf("ver:%s\n", ver); + char _scan_file[256]; SG_bagPositionParam algoParam; + algoParam.outputMode = 0; //0-按序输出(左上),1-按大小输出(最大) int endGroup = TEST_GROUP - 1; for (int grp = 0; grp <= 19; grp++) { diff --git a/sourceCode/SG_bagPositioning.cpp b/sourceCode/SG_bagPositioning.cpp index fd6a229..b017ce0 100644 --- a/sourceCode/SG_bagPositioning.cpp +++ b/sourceCode/SG_bagPositioning.cpp @@ -5,6 +5,13 @@ #include #include +//version 1.1.0 : ׼汾ˣ1汾ţ2ģʽְ֧Ͱ +std::string m_strVersion = "1.1.0"; +const char* sg_bagPositioningVersion(void) +{ + return m_strVersion.c_str(); +} + void sg_lineDataR(SVzNL3DLaserLine* a_line, const double* camPoseR, double groundH) @@ -61,14 +68,20 @@ cv::Point2f _rotate2D(cv::Point2f pt, double sinTheta, double cosTheta) return (cv::Point2f((float)(pt.x*cosTheta-pt.y*sinTheta), (float)(pt.x*sinTheta+pt.y*cosTheta))); } +//ӴС bool compareByHeight(const SSG_2DValueI& a, const SSG_2DValueI& b) { return a.valueD > b.valueD; } +// bool compareByXValue(const SSG_peakRgnInfo& a, const SSG_peakRgnInfo& b) { return a.centerPos.x < b.centerPos.x; } +bool compareBySize(const SSG_peakRgnInfo& a, const SSG_peakRgnInfo& b) +{ + return ((a.objSize.dWidth * a.objSize.dHeight) > (b.objSize.dWidth * b.objSize.dHeight)); +} //Ƿǹͻ bool _LRChkAbnormal(SVzNL3DLaserLine* laser3DPoints, int lineNum, int col, int y, int abnormalChkWin) { @@ -2212,6 +2225,7 @@ SSG_2DValueI _backIndexingPeakPos(SSG_2DValueI dt_pk, cv::Mat& distTranformIndex } return { 0 , 0 }; } + ///gridʽԽˮƽʹֱĴ ///1Ѱұ߽ ///2ߵ㿪ʼ @@ -3817,50 +3831,58 @@ if (i == 3) peakRgns.clear(); peakRgns.insert(peakRgns.end(), level0_objs.begin(), level0_objs.end()); int level0_size = (int)peakRgns.size(); - if (level0_size > 1) //һ򣬷 + if (algoParam.outputMode == 0) // { - //ȡYСĿ - double minY = 0; - double minY_idx = -1; - for (int i = 0; i < level0_size; i++) + if (level0_size > 1) //һ򣬷 { - if (minY_idx < 0) + //ȡYСĿ + double minY = 0; + double minY_idx = -1; + for (int i = 0; i < level0_size; i++) { - minY = peakRgns[i].centerPos.y; - minY_idx = i; - } - else - { - if (minY > peakRgns[i].centerPos.y) + if (minY_idx < 0) { minY = peakRgns[i].centerPos.y; minY_idx = i; } + else + { + if (minY > peakRgns[i].centerPos.y) + { + minY = peakRgns[i].centerPos.y; + minY_idx = i; + } + } } - } - std::vector row_0_outlier; - for (int i = 0; i < level0_size; i++) - { - double y_diff = peakRgns[i].centerPos.y - minY; - if (y_diff < algoParam.bagParam.bagW / 2) //һ - objOps.push_back(peakRgns[i]); - else - row_0_outlier.push_back(i); //еż¼ - } - //ԵһеĿ갴 - if (objOps.size() > 1) - { - std::sort(objOps.begin(), objOps.end(), compareByXValue); - } - for (int i = 0; i < row_0_outlier.size(); i++) - objOps.push_back(peakRgns[row_0_outlier[i]]); + std::vector row_0_outlier; + for (int i = 0; i < level0_size; i++) + { + double y_diff = peakRgns[i].centerPos.y - minY; + if (y_diff < algoParam.bagParam.bagW / 2) //һ + objOps.push_back(peakRgns[i]); + else + row_0_outlier.push_back(i); //еż¼ + } + //ԵһеĿ갴 + if (objOps.size() > 1) + { + std::sort(objOps.begin(), objOps.end(), compareByXValue); + } + for (int i = 0; i < row_0_outlier.size(); i++) + objOps.push_back(peakRgns[row_0_outlier[i]]); #if 0 - for (int i = level0_end + 1; i < peakRgns.size(); i++) - objOps.push_back(peakRgns[i]); + for (int i = level0_end + 1; i < peakRgns.size(); i++) + objOps.push_back(peakRgns[i]); #endif + } + else + objOps.insert(objOps.end(), peakRgns.begin(), peakRgns.end()); } - else + else //С,ڵС + { + std::sort(peakRgns.begin(), peakRgns.end(), compareBySize); objOps.insert(objOps.end(), peakRgns.begin(), peakRgns.end()); + } } //ײ if ((objOps.size() > 0) && (smallObjPeaks.size() > 0)) diff --git a/sourceCode/SG_bagPositioning_Export.h b/sourceCode/SG_bagPositioning_Export.h index d97ebb9..979f5a3 100644 --- a/sourceCode/SG_bagPositioning_Export.h +++ b/sourceCode/SG_bagPositioning_Export.h @@ -27,6 +27,7 @@ typedef struct //SSG_objSortParam sortParam; //SSG_polarScanParam polarScanParam; int supportRotate; + int outputMode; //0 - 1 - ӴС }SG_bagPositionParam; typedef struct @@ -46,6 +47,9 @@ typedef struct double baseHoleDist; //׶ľ }SSG_stackBaseParam; +//汾 +SG_APISHARED_EXPORT const char* sg_bagPositioningVersion(void); + //ݵƽ SG_APISHARED_EXPORT void sg_lineDataR( SVzNL3DLaserLine* a_line, diff --git a/sourceCode/SG_baseAlgo_Export.h b/sourceCode/SG_baseAlgo_Export.h index 511d5d4..c9b8c35 100644 --- a/sourceCode/SG_baseAlgo_Export.h +++ b/sourceCode/SG_baseAlgo_Export.h @@ -343,12 +343,32 @@ SG_APISHARED_EXPORT void lineFitting( double* _k, double* _b); +//ϳֱͨ߷ֱ̣ +SG_APISHARED_EXPORT void lineFitting_abc( + std::vector< SVzNL3DPoint>& inliers, + double* _a, + double* _b, + double* _c); + +SG_APISHARED_EXPORT SVzNL3DPoint computeLineCrossPt_abs( + double a1, double b1, double c1, + double a2, double b2, double c2); + +//㴹㣬ֱ߷̣y = kx + b SG_APISHARED_EXPORT SVzNL2DPointD sx_getFootPoint( double x0, double y0, double k, double b); +//㴹㣬ֱ߷̣ax+by+c = 0 +SG_APISHARED_EXPORT SVzNL2DPointD sx_getFootPoint_abc( + double x0, + double y0, + double A, + double B, + double C); + //Bresenham㷨 SG_APISHARED_EXPORT void drawLine( int x0, diff --git a/sourceCode/SG_baseFunc.cpp b/sourceCode/SG_baseFunc.cpp index 1dd952f..c20dbe5 100644 --- a/sourceCode/SG_baseFunc.cpp +++ b/sourceCode/SG_baseFunc.cpp @@ -234,6 +234,7 @@ void lineFitting(std::vector< SVzNL3DPoint>& inliers, double* _k, double* _b) *_b = (-x_sum * xy_sum + xx_sum * y_sum) / (num * xx_sum - x_sum * x_sum);//ݹʽb } +//㴹㣬ֱ߷̣y = kx + b SVzNL2DPointD sx_getFootPoint(double x0, double y0, double k, double b) { double A = k; @@ -245,6 +246,14 @@ SVzNL2DPointD sx_getFootPoint(double x0, double y0, double k, double b) return foot; } +//㴹㣬ֱ߷̣ax+by+c = 0 +SVzNL2DPointD sx_getFootPoint_abc(double x0, double y0, double A, double B, double C) +{ + SVzNL2DPointD foot; + foot.x = (B * B * x0 - A * B * y0 - A * C) / (A * A + B * B); + foot.y = (-A * B * x0 + A * A * y0 - B * C) / (A * A + B * B); + return foot; +} #if 0 void icvprCcaByTwoPass(const cv::Mat& binImg, cv::Mat& lableImg) {