diff --git a/bagPositioning_test/bagPositioning_test.cpp b/bagPositioning_test/bagPositioning_test.cpp index 3258ec0..94404a2 100644 --- a/bagPositioning_test/bagPositioning_test.cpp +++ b/bagPositioning_test/bagPositioning_test.cpp @@ -3101,7 +3101,8 @@ int main() lineV, maxTimeStamp, clockPerSecond); #endif std::vector objOps; - sg_getBagPosition(laser3DPoints, lineNum, algoParam, poseCalibPara, objOps); + int errCode = 0; + sg_getBagPosition(laser3DPoints, lineNum, algoParam, poseCalibPara, objOps, &errCode); #endif long t2 = GetTickCount64(); diff --git a/sourceCode/SG_bagPositioning.cpp b/sourceCode/SG_bagPositioning.cpp index b017ce0..9f128fa 100644 --- a/sourceCode/SG_bagPositioning.cpp +++ b/sourceCode/SG_bagPositioning.cpp @@ -6,7 +6,8 @@ #include //version 1.1.0 : 基准版本基础上添加了(1)版本号(2)输出模式,支持按序输出和按大输出 -std::string m_strVersion = "1.1.0"; +//version 1.1.1 : 增加了错误代码。当托盘为空时,错误代码为 SX_BAG_TRAY_EMPTY,指示托盘为空 +std::string m_strVersion = "1.1.1"; const char* sg_bagPositioningVersion(void) { return m_strVersion.c_str(); @@ -2237,8 +2238,10 @@ void sg_getBagPosition( //std::vector>& noisePts, const SG_bagPositionParam algoParam, const SSG_planeCalibPara poseCalibPara, - std::vector& objOps) + std::vector& objOps, + int* errCode) { + *errCode = 0; ///噪点过滤 //垂直方向过滤 for (int i = 0; i < lineNum; i++) @@ -2299,7 +2302,10 @@ void sg_getBagPosition( if (maskY % 2 > 0) maskY++; if ((maskX < 16) || (maskY < 16)) + { + *errCode = SX_BAG_TRAY_EMPTY; return; + } const int x_skip = 2; const int y_skip = 2; maskY = maskY + y_skip * 2; @@ -2382,6 +2388,8 @@ void sg_getBagPosition( #endif int vldRgnSize = (int)((algoParam.bagParam.bagL * algoParam.bagParam.bagW / 2) / (scale * scale)); + //统计有效目标数 + int vldRgnNum = 0; for (int rgnid = 0, rgn_max = (int)labelRgns.size(); rgnid < rgn_max; rgnid++) { SSG_Region* a_rgn = &labelRgns[rgnid]; @@ -2397,7 +2405,16 @@ void sg_getBagPosition( } } } + else + vldRgnNum++; } + + if(vldRgnNum == 0) + { + *errCode = SX_BAG_TRAY_EMPTY; + return; + } + //将无效rgn的点无效 for (int line = 0; line < lineNum; line++) { @@ -2414,6 +2431,7 @@ void sg_getBagPosition( pt3D->pt3D.z = 0; } } + #if OUTPUT_DEBUG cv::Mat filterMaskImage; //cv::normalize(distTranformMask, maskImage, 0, 255, cv::NORM_MINMAX, CV_8U); @@ -2750,7 +2768,10 @@ if (hLine == 14) maskX = (int)(x_range.max - x_range.min) + 1; maskY = (int)(y_range.max - y_range.min) + 1; if ((maskX < 16) || (maskY < 16)) + { + *errCode = SX_BAG_TRAY_EMPTY; return; + } maskY = maskY + y_skip * 2; maskX = maskX + x_skip * 2; cv::Mat distTranformMask(maskY, maskX, CV_32FC1, 0.0f); //距离变换Mask,初始化为一个极大值1e+6 @@ -4138,7 +4159,8 @@ void sg_getBagPositionAndOrientation( (int)cloudPts.size(), algoParam, poseCalibPara, - peakRgn); + peakRgn, + errCode); //释放内存 for (int i = 0, i_max = (int)cloudPts.size(); i < i_max; i++) diff --git a/sourceCode/SG_bagPositioning_Export.h b/sourceCode/SG_bagPositioning_Export.h index 6b63432..4ce68db 100644 --- a/sourceCode/SG_bagPositioning_Export.h +++ b/sourceCode/SG_bagPositioning_Export.h @@ -71,7 +71,8 @@ SG_APISHARED_EXPORT void sg_getBagPosition( //std::vector>& noisePts, const SG_bagPositionParam algoParam, const SSG_planeCalibPara poseCalibPara, - std::vector& objOps); + std::vector& objOps, + int* errCode); SG_APISHARED_EXPORT void sg_getBagPositionAndOrientation( SVzNLXYZRGBDLaserLine* laser3DPoints, diff --git a/sourceCode/SG_errCode.h b/sourceCode/SG_errCode.h index e13228f..0d2767c 100644 --- a/sourceCode/SG_errCode.h +++ b/sourceCode/SG_errCode.h @@ -19,4 +19,7 @@ //定子抓取 #define SX_ERR_INVLID_CUTTING_Z -2101 -#define SX_ERR_ZERO_OBJ -2102 \ No newline at end of file +#define SX_ERR_ZERO_OBJ -2102 + +//拆包 +#define SX_BAG_TRAY_EMPTY -2201