workpieceHolePositioning v1.0.0
初始版本提交
This commit is contained in:
parent
2d7bb92410
commit
a70fd41084
@ -205,6 +205,17 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bagThreadPositioning_test",
|
|||||||
{F371FCBC-0AD6-4546-8785-1C05CD0C5B57} = {F371FCBC-0AD6-4546-8785-1C05CD0C5B57}
|
{F371FCBC-0AD6-4546-8785-1C05CD0C5B57} = {F371FCBC-0AD6-4546-8785-1C05CD0C5B57}
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "workpieceHolePositioning_test", "workpieceHolePositioning_test\workpieceHolePositioning_test.vcxproj", "{CA8CBA7F-4D72-4630-AF6D-BF872306502C}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{95DC3F1A-902A-490E-BD3B-B10463CF0EBD} = {95DC3F1A-902A-490E-BD3B-B10463CF0EBD}
|
||||||
|
{C65F7F4B-B77A-4D65-9490-5304B760B607} = {C65F7F4B-B77A-4D65-9490-5304B760B607}
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "workpieceHolePositioning", "workpieceHolePositioning\workpieceHolePositioning.vcxproj", "{C65F7F4B-B77A-4D65-9490-5304B760B607}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{95DC3F1A-902A-490E-BD3B-B10463CF0EBD} = {95DC3F1A-902A-490E-BD3B-B10463CF0EBD}
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|x64 = Debug|x64
|
Debug|x64 = Debug|x64
|
||||||
@ -525,6 +536,22 @@ Global
|
|||||||
{831F7635-98DB-45BB-9815-5334DA70BFE8}.Release|x64.Build.0 = Release|x64
|
{831F7635-98DB-45BB-9815-5334DA70BFE8}.Release|x64.Build.0 = Release|x64
|
||||||
{831F7635-98DB-45BB-9815-5334DA70BFE8}.Release|x86.ActiveCfg = Release|Win32
|
{831F7635-98DB-45BB-9815-5334DA70BFE8}.Release|x86.ActiveCfg = Release|Win32
|
||||||
{831F7635-98DB-45BB-9815-5334DA70BFE8}.Release|x86.Build.0 = Release|Win32
|
{831F7635-98DB-45BB-9815-5334DA70BFE8}.Release|x86.Build.0 = Release|Win32
|
||||||
|
{CA8CBA7F-4D72-4630-AF6D-BF872306502C}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{CA8CBA7F-4D72-4630-AF6D-BF872306502C}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{CA8CBA7F-4D72-4630-AF6D-BF872306502C}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{CA8CBA7F-4D72-4630-AF6D-BF872306502C}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{CA8CBA7F-4D72-4630-AF6D-BF872306502C}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{CA8CBA7F-4D72-4630-AF6D-BF872306502C}.Release|x64.Build.0 = Release|x64
|
||||||
|
{CA8CBA7F-4D72-4630-AF6D-BF872306502C}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{CA8CBA7F-4D72-4630-AF6D-BF872306502C}.Release|x86.Build.0 = Release|Win32
|
||||||
|
{C65F7F4B-B77A-4D65-9490-5304B760B607}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{C65F7F4B-B77A-4D65-9490-5304B760B607}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{C65F7F4B-B77A-4D65-9490-5304B760B607}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{C65F7F4B-B77A-4D65-9490-5304B760B607}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{C65F7F4B-B77A-4D65-9490-5304B760B607}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{C65F7F4B-B77A-4D65-9490-5304B760B607}.Release|x64.Build.0 = Release|x64
|
||||||
|
{C65F7F4B-B77A-4D65-9490-5304B760B607}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{C65F7F4B-B77A-4D65-9490-5304B760B607}.Release|x86.Build.0 = Release|Win32
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -201,6 +201,16 @@ SG_APISHARED_EXPORT void wd_surfaceLineSegment(
|
|||||||
std::vector<SSG_featureSemiCircle>& lineSegs,
|
std::vector<SSG_featureSemiCircle>& lineSegs,
|
||||||
std::vector<SSG_featureSemiCircle>& invlaidLineSegs);
|
std::vector<SSG_featureSemiCircle>& invlaidLineSegs);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
//对一个面的边缘特征进行提取。
|
||||||
|
//此算法首先获取扫描线上各个段,然后对段的端点进行处理,得到边缘特征
|
||||||
|
void wd_getSurfaceEdgeFeatures(
|
||||||
|
std::vector< SVzNL3DPosition>& lineData,
|
||||||
|
int lineIdx,
|
||||||
|
const SSG_lineSegParam lineSegPara,
|
||||||
|
std::vector<SWDIndexing3DPoint>& edgeFeatures);
|
||||||
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 提取激光线上的Jumping特征
|
/// 提取激光线上的Jumping特征
|
||||||
/// nPointIdx被重新定义成Feature类型
|
/// nPointIdx被重新定义成Feature类型
|
||||||
@ -521,6 +531,9 @@ SG_APISHARED_EXPORT double getLineAngle(const double _a, const double _b, const
|
|||||||
//计算两点的2D距离
|
//计算两点的2D距离
|
||||||
SG_APISHARED_EXPORT double compute2DLen(SVzNL3DPoint pt1, SVzNL3DPoint pt2);
|
SG_APISHARED_EXPORT double compute2DLen(SVzNL3DPoint pt1, SVzNL3DPoint pt2);
|
||||||
|
|
||||||
|
//计算XY平面面的三角形顶角(p0的张角)
|
||||||
|
SG_APISHARED_EXPORT double computeXOYVertexAngle(SVzNL3DPoint p0, SVzNL3DPoint p1, SVzNL3DPoint p2);
|
||||||
|
|
||||||
//计算点到直线距离
|
//计算点到直线距离
|
||||||
SG_APISHARED_EXPORT double computePtDistToLine(double x0, double y0, double a, double b, double c);
|
SG_APISHARED_EXPORT double computePtDistToLine(double x0, double y0, double a, double b, double c);
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,20 @@ typedef struct
|
|||||||
double yawAngle; //偏转角:绕Z轴的偏转, 弧度
|
double yawAngle; //偏转角:绕Z轴的偏转, 弧度
|
||||||
}SSG_6AxisAttitude;
|
}SSG_6AxisAttitude;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
double z;
|
||||||
|
}SWD3DPoint;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int lineIdx;
|
||||||
|
int ptIdx;
|
||||||
|
SWD3DPoint point;
|
||||||
|
}SWDIndexing3DPoint;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool validFlag; //指示结果是否有效
|
bool validFlag; //指示结果是否有效
|
||||||
@ -67,6 +81,12 @@ typedef struct
|
|||||||
double bottom;
|
double bottom;
|
||||||
}SSG_ROIRectD;
|
}SSG_ROIRectD;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
SVzNL3DPoint center;
|
||||||
|
double radius;
|
||||||
|
}SWD_HoleInfo;
|
||||||
|
|
||||||
struct HSV {
|
struct HSV {
|
||||||
double h; // 色相 (0-360)
|
double h; // 色相 (0-360)
|
||||||
double s; // 饱和度 (0-1)
|
double s; // 饱和度 (0-1)
|
||||||
@ -172,7 +192,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
double segGapTh_y; //y方向连续段门限。大于此门限,为不连续
|
double segGapTh_y; //y方向连续段门限。大于此门限,为不连续
|
||||||
double segGapTh_z; //z方向连续段门限。大于此门限,为不连续
|
double segGapTh_z; //z方向连续段门限。大于此门限,为不连续
|
||||||
double maxDist; //计算方向角的窗口比例尺
|
double distScale; //计算方向角的窗口比例尺
|
||||||
}SSG_lineSegParam;
|
}SSG_lineSegParam;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|||||||
@ -639,6 +639,20 @@ double compute2DLen(SVzNL3DPoint pt1, SVzNL3DPoint pt2)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//计算XY平面面的三角形顶角(p0的张角)
|
||||||
|
double computeXOYVertexAngle(SVzNL3DPoint p0, SVzNL3DPoint p1, SVzNL3DPoint p2)
|
||||||
|
{
|
||||||
|
double len_c = compute2DLen(p1, p2);
|
||||||
|
double len_a = compute2DLen(p0, p1);
|
||||||
|
double len_b = compute2DLen(p0, p2);
|
||||||
|
double cosAngle = (pow(len_a, 2) + pow(len_b, 2) - pow(len_c, 2)) / (2 * len_a * len_b);
|
||||||
|
double angle = acos(cosAngle);
|
||||||
|
angle = angle * 180 / M_PI;
|
||||||
|
if (angle < 0)
|
||||||
|
angle = angle + 180;
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
double computePtDistToLine(double x0, double y0, double a, double b, double c)
|
double computePtDistToLine(double x0, double y0, double a, double b, double c)
|
||||||
{
|
{
|
||||||
double tmp = sqrt(pow(a, 2) + pow(b, 2));
|
double tmp = sqrt(pow(a, 2) + pow(b, 2));
|
||||||
@ -2287,7 +2301,7 @@ SSG_planeCalibPara sg_HCameraVScan_getGroundCalibPara(
|
|||||||
|
|
||||||
//提取地面直线段
|
//提取地面直线段
|
||||||
SSG_lineSegParam lineSegPara;
|
SSG_lineSegParam lineSegPara;
|
||||||
lineSegPara.maxDist = 2.0;
|
lineSegPara.distScale = 2.0;
|
||||||
lineSegPara.segGapTh_y = 5.0; //y方向间隔大于5mm认为是分段
|
lineSegPara.segGapTh_y = 5.0; //y方向间隔大于5mm认为是分段
|
||||||
lineSegPara.segGapTh_z = 10.0; //z方向间隔大于10mm认为是分段
|
lineSegPara.segGapTh_z = 10.0; //z方向间隔大于10mm认为是分段
|
||||||
|
|
||||||
@ -2307,7 +2321,7 @@ SSG_planeCalibPara sg_HCameraVScan_getGroundCalibPara(
|
|||||||
SSG_RUN lastSeg = segs.back();
|
SSG_RUN lastSeg = segs.back();
|
||||||
//直线分割
|
//直线分割
|
||||||
std::vector< SSG_RUN> segmentationLines;
|
std::vector< SSG_RUN> segmentationLines;
|
||||||
split(lastSeg, lineData, lineSegPara.maxDist, segmentationLines);
|
split(lastSeg, lineData, lineSegPara.distScale, segmentationLines);
|
||||||
//检查最后一段的直线段的斜率
|
//检查最后一段的直线段的斜率
|
||||||
SSG_RUN lastLine = segmentationLines.back();
|
SSG_RUN lastLine = segmentationLines.back();
|
||||||
//计算斜率
|
//计算斜率
|
||||||
|
|||||||
@ -80,6 +80,7 @@ void wd_gridPointClustering(
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
int lineNum = (int)featureMask.size();
|
int lineNum = (int)featureMask.size();
|
||||||
int linePtNum = (int)featureMask[0].size();
|
int linePtNum = (int)featureMask[0].size();
|
||||||
|
featureMask[a_cluster[0].x][a_cluster[0].y].flag = 1; //防止第一个被重复添加
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (i >= a_cluster.size())
|
if (i >= a_cluster.size())
|
||||||
|
|||||||
@ -4270,6 +4270,238 @@ void wd_getLineCorerFeature_accelerate(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SSG_pntDirAngle _computeCornerAngle(int ptIdx, int startIdx, int endIdx, double scale, std::vector< SVzNL3DPosition>& lineData)
|
||||||
|
{
|
||||||
|
SSG_pntDirAngle a_corner;
|
||||||
|
memset(&a_corner, 0, sizeof(SSG_pntDirAngle));
|
||||||
|
if (lineData[ptIdx].pt3D.z < 1e-4)
|
||||||
|
{
|
||||||
|
a_corner.pntIdx = -1;
|
||||||
|
a_corner.forwardAngle = 0;
|
||||||
|
a_corner.backwardAngle = 0;
|
||||||
|
a_corner.corner = 0;
|
||||||
|
a_corner.forwardDiffZ = 0;
|
||||||
|
a_corner.backwardDiffZ = 0;
|
||||||
|
return a_corner;
|
||||||
|
}
|
||||||
|
//前向寻找
|
||||||
|
int pre_i = -1;
|
||||||
|
for (int j = ptIdx-1; j >= startIdx; j--)
|
||||||
|
{
|
||||||
|
if (lineData[j].pt3D.z > 1e-4)
|
||||||
|
{
|
||||||
|
double dist = sqrt(pow(lineData[ptIdx].pt3D.y - lineData[j].pt3D.y, 2) +
|
||||||
|
pow(lineData[ptIdx].pt3D.z - lineData[j].pt3D.z, 2));
|
||||||
|
if (dist >= scale)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
pre_i = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//后向寻找
|
||||||
|
int post_i = -1;
|
||||||
|
for (int j = ptIdx+1; j < endIdx; j++)
|
||||||
|
{
|
||||||
|
if (lineData[j].pt3D.z > 1e-4)
|
||||||
|
{
|
||||||
|
double dist = sqrt(pow(lineData[ptIdx].pt3D.y - lineData[j].pt3D.y, 2) +
|
||||||
|
pow(lineData[ptIdx].pt3D.z - lineData[j].pt3D.z, 2));
|
||||||
|
if (dist >= scale)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
post_i = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//计算拐角
|
||||||
|
if ((pre_i < 0) || (post_i < 0))
|
||||||
|
{
|
||||||
|
a_corner.pntIdx = -1;
|
||||||
|
a_corner.forwardAngle = 0;
|
||||||
|
a_corner.backwardAngle = 0;
|
||||||
|
a_corner.corner = 0;
|
||||||
|
a_corner.forwardDiffZ = 0;
|
||||||
|
a_corner.backwardDiffZ = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double tanValue_pre = (lineData[ptIdx].pt3D.z - lineData[pre_i].pt3D.z) / abs(lineData[ptIdx].pt3D.y - lineData[pre_i].pt3D.y);
|
||||||
|
double tanValue_post = (lineData[post_i].pt3D.z - lineData[ptIdx].pt3D.z) / abs(lineData[post_i].pt3D.y - lineData[ptIdx].pt3D.y);
|
||||||
|
double forwardAngle = atan(tanValue_post) * 180.0 / PI;
|
||||||
|
double backwardAngle = atan(tanValue_pre) * 180.0 / PI;
|
||||||
|
a_corner.pntIdx = ptIdx;
|
||||||
|
a_corner.forwardAngle = forwardAngle;
|
||||||
|
a_corner.backwardAngle = backwardAngle;
|
||||||
|
a_corner.corner = -(forwardAngle - backwardAngle); //图像坐标系与正常坐标系y方向相反,所以有“-”号
|
||||||
|
a_corner.forwardDiffZ = lineData[post_i].pt3D.z - lineData[ptIdx].pt3D.z;
|
||||||
|
a_corner.backwardDiffZ = lineData[ptIdx].pt3D.z - lineData[pre_i].pt3D.z;
|
||||||
|
}
|
||||||
|
return a_corner;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
//对一个面的边缘特征进行提取。
|
||||||
|
//此算法首先获取扫描线上各个段,然后对段的端点进行处理,得到边缘特征
|
||||||
|
void wd_getSurfaceEdgeFeatures(
|
||||||
|
std::vector< SVzNL3DPosition>& lineData,
|
||||||
|
int lineIdx,
|
||||||
|
const SSG_lineSegParam lineSegPara,
|
||||||
|
const SSG_cornerParam cornerPara,
|
||||||
|
double edgeAngleTh, //边缘的判断角度。当一个端点的前向角或后向角大于此门限,将拐点最大点视为边缘,反之,端点是边缘点
|
||||||
|
std::vector<SWDIndexing3DPoint>& edgeFeatures)
|
||||||
|
{
|
||||||
|
int dataSize = (int)lineData.size();
|
||||||
|
//去除零点
|
||||||
|
std::vector<SSG_RUN> segs;
|
||||||
|
wd_getLineDataIntervals(lineData, lineSegPara, segs);
|
||||||
|
|
||||||
|
//逐段处理,对端点进行处理
|
||||||
|
int segSize = (int)segs.size();
|
||||||
|
for (int si = 0; si < segSize; si++)
|
||||||
|
{
|
||||||
|
int endingIdx_s = segs[si].start;
|
||||||
|
int endingIdx_e = segs[si].start + segs[si].len - 1;
|
||||||
|
//后向寻找
|
||||||
|
int post_i = -1;
|
||||||
|
for (int j = endingIdx_s + 1; j <= endingIdx_e; j++)
|
||||||
|
{
|
||||||
|
if (lineData[j].pt3D.z > 1e-4)
|
||||||
|
{
|
||||||
|
double dist = sqrt(pow(lineData[endingIdx_s].pt3D.y - lineData[j].pt3D.y, 2) +
|
||||||
|
pow(lineData[endingIdx_s].pt3D.z - lineData[j].pt3D.z, 2));
|
||||||
|
if (dist >= lineSegPara.distScale)
|
||||||
|
{
|
||||||
|
post_i = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
double tanValue_post = (lineData[post_i].pt3D.z - lineData[endingIdx_s].pt3D.z) / abs(lineData[post_i].pt3D.y - lineData[endingIdx_s].pt3D.y);
|
||||||
|
double forwardAngle = atan(tanValue_post) * 180.0 / PI;
|
||||||
|
if (forwardAngle > edgeAngleTh)
|
||||||
|
{
|
||||||
|
//需要寻找拐点,作为端点
|
||||||
|
std::vector<SSG_pntDirAngle> corners;
|
||||||
|
for (int j = endingIdx_s + 1; j < endingIdx_e; j++)
|
||||||
|
{
|
||||||
|
SSG_pntDirAngle a_corner = _computeCornerAngle(j, endingIdx_s, endingIdx_e, lineSegPara.distScale, lineData);
|
||||||
|
corners.push_back(a_corner);
|
||||||
|
double cornerMergeScale = cornerPara.scale * 2;
|
||||||
|
std::vector< SSG_pntDirAngle> cornerPeakP;
|
||||||
|
std::vector< SSG_pntDirAngle> cornerPeakM;
|
||||||
|
_searchCornerPeaks(
|
||||||
|
corners,
|
||||||
|
lineData,
|
||||||
|
cornerPara,
|
||||||
|
cornerMergeScale,
|
||||||
|
cornerPeakP,
|
||||||
|
cornerPeakM
|
||||||
|
);
|
||||||
|
//取cornerPeakM的第一个极值点
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::vector< SSG_RUN> segmentationLines;
|
||||||
|
split(segs[si], lineData, lineSegPara.maxDist, segmentationLines);
|
||||||
|
|
||||||
|
//对于每个分段,只能有一个合格的直线段
|
||||||
|
std::vector< SSG_featureSemiCircle> candiLines;
|
||||||
|
for (int m = 0, m_max = (int)segmentationLines.size(); m < m_max; m++)
|
||||||
|
{
|
||||||
|
SSG_featureSemiCircle a_seg;
|
||||||
|
a_seg.lineIdx = lineIdx;
|
||||||
|
a_seg.startPtIdx = segmentationLines[m].start;
|
||||||
|
a_seg.endPtIdx = segmentationLines[m].start + segmentationLines[m].len - 1;
|
||||||
|
|
||||||
|
SVzNL3DPoint ptStart = lineData[a_seg.startPtIdx].pt3D;
|
||||||
|
SVzNL3DPoint ptEnd = lineData[a_seg.endPtIdx].pt3D;
|
||||||
|
double len = sqrt(pow(ptStart.x - ptEnd.x, 2) + pow(ptStart.y - ptEnd.y, 2) + pow(ptStart.z - ptEnd.z, 2));
|
||||||
|
if ((len >= lineLenRange.min) && (len <= lineLenRange.max))
|
||||||
|
{
|
||||||
|
int midPtIdx = (a_seg.startPtIdx + a_seg.endPtIdx) / 2;
|
||||||
|
bool validMid = true;
|
||||||
|
if (lineData[midPtIdx].pt3D.z < 1e-4)
|
||||||
|
{
|
||||||
|
validMid = false;
|
||||||
|
int chkWin = 1;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
int idx = midPtIdx + chkWin;
|
||||||
|
if (idx >= a_seg.endPtIdx)
|
||||||
|
break;
|
||||||
|
if (lineData[idx].pt3D.z > 1e-4)
|
||||||
|
{
|
||||||
|
midPtIdx = idx;
|
||||||
|
validMid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
idx = midPtIdx - chkWin;
|
||||||
|
if (idx <= a_seg.startPtIdx)
|
||||||
|
break;
|
||||||
|
if (lineData[idx].pt3D.z > 1e-4)
|
||||||
|
{
|
||||||
|
midPtIdx = idx;
|
||||||
|
validMid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
chkWin++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (true == validMid)
|
||||||
|
{
|
||||||
|
a_seg.midPtIdx = midPtIdx;
|
||||||
|
a_seg.midPt = lineData[midPtIdx].pt3D;
|
||||||
|
candiLines.push_back(a_seg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//转成SSG_featureSemiCircle格式
|
||||||
|
if (candiLines.size() > 0)
|
||||||
|
{
|
||||||
|
//选择一个水平角度更小的
|
||||||
|
double minTan = 0;
|
||||||
|
int bestIdx = -1;
|
||||||
|
for (int m = 0, m_max = (int)candiLines.size(); m < m_max; m++)
|
||||||
|
{
|
||||||
|
SSG_featureSemiCircle& a_seg = candiLines[m];
|
||||||
|
SVzNL3DPoint ptStart = lineData[a_seg.startPtIdx].pt3D;
|
||||||
|
SVzNL3DPoint ptEnd = lineData[a_seg.endPtIdx].pt3D;
|
||||||
|
double tank = abs((ptEnd.z - ptStart.z) / (ptEnd.y - ptStart.y));
|
||||||
|
if (bestIdx < 0)
|
||||||
|
{
|
||||||
|
minTan = tank;
|
||||||
|
bestIdx = m;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (minTan > tank)
|
||||||
|
{
|
||||||
|
minTan = tank;
|
||||||
|
bestIdx = m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lineSegs.push_back(candiLines[bestIdx]);
|
||||||
|
for (int m = 0, m_max = (int)candiLines.size(); m < m_max; m++)
|
||||||
|
{
|
||||||
|
if (m != bestIdx)
|
||||||
|
invlaidLineSegs.push_back(candiLines[m]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (candiLines.size() == 1)
|
||||||
|
lineSegs.push_back(candiLines[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//提取凸起段
|
//提取凸起段
|
||||||
void wd_getLineRaisedFeature(
|
void wd_getLineRaisedFeature(
|
||||||
std::vector< SVzNL3DPosition>& lineData,
|
std::vector< SVzNL3DPosition>& lineData,
|
||||||
@ -4417,7 +4649,7 @@ void wd_surfaceLineSegment(
|
|||||||
for (int si = 0; si < segSize; si++)
|
for (int si = 0; si < segSize; si++)
|
||||||
{
|
{
|
||||||
std::vector< SSG_RUN> segmentationLines;
|
std::vector< SSG_RUN> segmentationLines;
|
||||||
split(segs[si], lineData, lineSegPara.maxDist, segmentationLines);
|
split(segs[si], lineData, lineSegPara.distScale, segmentationLines);
|
||||||
|
|
||||||
//对于每个分段,只能有一个合格的直线段
|
//对于每个分段,只能有一个合格的直线段
|
||||||
std::vector< SSG_featureSemiCircle> candiLines;
|
std::vector< SSG_featureSemiCircle> candiLines;
|
||||||
|
|||||||
445
sourceCode/workpieceHolePositioning.cpp
Normal file
445
sourceCode/workpieceHolePositioning.cpp
Normal file
@ -0,0 +1,445 @@
|
|||||||
|
#include <vector>
|
||||||
|
#include "SG_baseDataType.h"
|
||||||
|
#include "SG_baseAlgo_Export.h"
|
||||||
|
#include "workpieceHolePositioning_Export.h"
|
||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
//version 1.0.0 : base version release to customer
|
||||||
|
std::string m_strVersion = "1.0.0";
|
||||||
|
const char* wd_workpieceHolePositioningVersion(void)
|
||||||
|
{
|
||||||
|
return m_strVersion.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
//相机水平安装计算地面调平参数。
|
||||||
|
//相机Z轴基本平行地面时,需要以地面为参照,将相机调水平
|
||||||
|
//旋转矩阵为调平参数,即将平面法向调整为垂直向量的参数
|
||||||
|
SSG_planeCalibPara wd_getGroundCalibPara(
|
||||||
|
std::vector< std::vector<SVzNL3DPosition>>& scanLines)
|
||||||
|
{
|
||||||
|
return sg_getPlaneCalibPara2(scanLines);
|
||||||
|
}
|
||||||
|
|
||||||
|
//相机水平时姿态调平,并去除地面
|
||||||
|
void wd_lineDataR(
|
||||||
|
std::vector< SVzNL3DPosition>& a_line,
|
||||||
|
const double* camPoseR,
|
||||||
|
double groundH)
|
||||||
|
{
|
||||||
|
lineDataRT_vector(a_line, camPoseR, groundH);
|
||||||
|
}
|
||||||
|
|
||||||
|
SVzNL3DPoint _ptRotate(SVzNL3DPoint pt3D, const double matrix3d[9])
|
||||||
|
{
|
||||||
|
SVzNL3DPoint _r_pt;
|
||||||
|
_r_pt.x = pt3D.x * matrix3d[0] + pt3D.y * matrix3d[1] + pt3D.z * matrix3d[2];
|
||||||
|
_r_pt.y = pt3D.x * matrix3d[3] + pt3D.y * matrix3d[4] + pt3D.z * matrix3d[5];
|
||||||
|
_r_pt.z = pt3D.x * matrix3d[6] + pt3D.y * matrix3d[7] + pt3D.z * matrix3d[8];
|
||||||
|
return _r_pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
//搜索最接近distance的目标
|
||||||
|
int distanceSearchObject(SVzNL3DPoint seed, std::vector<SWD_HoleInfo>& holes, double distance, double distDeviation)
|
||||||
|
{
|
||||||
|
int result = -1;
|
||||||
|
int holeSize = (int)holes.size();
|
||||||
|
double minDistDiff = DBL_MAX;
|
||||||
|
int minDistIndex = -1;
|
||||||
|
for (int i = 0; i < holeSize; i++)
|
||||||
|
{
|
||||||
|
if (holes[i].radius < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
double dist = sqrt(pow(seed.x - holes[i].center.x, 2) + pow(seed.y - holes[i].center.y, 2));
|
||||||
|
double distDiff = abs(dist - distance);
|
||||||
|
if (minDistDiff > distDiff)
|
||||||
|
{
|
||||||
|
minDistDiff = distDiff;
|
||||||
|
minDistIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((minDistIndex >= 0) && (minDistDiff < distDeviation))
|
||||||
|
result = minDistIndex;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//搜索最接近distance且角度为angle的目标, 以角度为优先
|
||||||
|
int angleConditionDistanceSearch(
|
||||||
|
SVzNL3DPoint seed, SVzNL3DPoint angleSide,
|
||||||
|
std::vector<SWD_HoleInfo>& holes,
|
||||||
|
double distance, double distDeviation,
|
||||||
|
SVzNLRangeD angleRange)
|
||||||
|
{
|
||||||
|
int result = -1;
|
||||||
|
int holeSize = (int)holes.size();
|
||||||
|
std::vector< int> distValidHoleIndex;
|
||||||
|
for (int i = 0; i < holeSize; i++)
|
||||||
|
{
|
||||||
|
if (holes[i].radius < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
double dist = sqrt(pow(seed.x - holes[i].center.x, 2) + pow(seed.y - holes[i].center.y, 2));
|
||||||
|
double distDiff = abs(dist - distance);
|
||||||
|
if (distDiff < distDeviation)
|
||||||
|
{
|
||||||
|
distValidHoleIndex.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (distValidHoleIndex.size() == 1)
|
||||||
|
{
|
||||||
|
int idx = distValidHoleIndex[0];
|
||||||
|
double angle = computeXOYVertexAngle(seed, angleSide, holes[idx].center);
|
||||||
|
if( (angle >= angleRange.min) &&(angle <= angleRange.max))
|
||||||
|
result = idx;
|
||||||
|
}
|
||||||
|
else if (distValidHoleIndex.size() > 1)
|
||||||
|
{
|
||||||
|
double bestAngle = (angleRange.min + angleRange.max) / 2;
|
||||||
|
double minAngleDeviateion = DBL_MAX;
|
||||||
|
int minAngleIdx = -1;
|
||||||
|
for (int i = 0, i_max = (int)distValidHoleIndex.size(); i < i_max; i++)
|
||||||
|
{
|
||||||
|
int idx = distValidHoleIndex[i];
|
||||||
|
double angle = computeXOYVertexAngle(seed, angleSide, holes[idx].center);
|
||||||
|
if ((angle >= angleRange.min) && (angle <= angleRange.max))
|
||||||
|
{
|
||||||
|
double angleDiff = abs(angle - bestAngle);
|
||||||
|
if (minAngleDeviateion > angleDiff)
|
||||||
|
{
|
||||||
|
minAngleDeviateion = angleDiff;
|
||||||
|
minAngleIdx = idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = minAngleIdx;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//工件孔定位
|
||||||
|
void wd_workpieceHolePositioning(
|
||||||
|
std::vector< std::vector<SVzNL3DPosition>>& scanLinesInput,
|
||||||
|
const WD_workpieceHoleParam workpiecePara,
|
||||||
|
const SSG_lineSegParam lineSegPara,
|
||||||
|
const SSG_outlierFilterParam filterParam,
|
||||||
|
const SSG_treeGrowParam growParam,
|
||||||
|
const SSG_planeCalibPara groundCalibPara,
|
||||||
|
std::vector< WD_workpieceInfo>& workpiecePositioning,
|
||||||
|
int* errCode)
|
||||||
|
{
|
||||||
|
*errCode = 0;
|
||||||
|
|
||||||
|
int lineNum = (int)scanLinesInput.size();
|
||||||
|
std::vector< std::vector<SVzNL3DPosition>> scanLines;
|
||||||
|
scanLines.resize(lineNum);
|
||||||
|
int linePtNum = (int)scanLinesInput[0].size();
|
||||||
|
bool isGridData = true;
|
||||||
|
for (int i = 0; i < lineNum; i++)
|
||||||
|
{
|
||||||
|
if (linePtNum != (int)scanLinesInput[i].size())
|
||||||
|
isGridData = false;
|
||||||
|
|
||||||
|
scanLines[i].resize(scanLinesInput[i].size());
|
||||||
|
std::copy(scanLinesInput[i].begin(), scanLinesInput[i].end(), scanLines[i].begin()); // 使用std::copy算法
|
||||||
|
}
|
||||||
|
if (false == isGridData)//数据不是网格格式
|
||||||
|
{
|
||||||
|
*errCode = SG_ERR_NOT_GRID_FORMAT;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < lineNum; i++)
|
||||||
|
{ //行处理
|
||||||
|
//调平,去除地面
|
||||||
|
wd_lineDataR(scanLines[i], groundCalibPara.planeCalib, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//生成量化数据,以1mm为量化尺度,用于确定工件表面高度
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::vector<int>> pointMask;
|
||||||
|
pointMask.resize(lineNum);
|
||||||
|
|
||||||
|
std::vector<SVzNL3DPoint> endingPoints;
|
||||||
|
//提取线段端点特征
|
||||||
|
for (int line = 0; line < lineNum; line++)
|
||||||
|
{
|
||||||
|
if (line == 1677)
|
||||||
|
int kkk = 1;
|
||||||
|
|
||||||
|
std::vector<SVzNL3DPosition>& lineData = scanLines[line];
|
||||||
|
pointMask[line].resize(lineData.size());
|
||||||
|
std::fill(pointMask[line].begin(), pointMask[line].end(), 0);//初始化为0
|
||||||
|
//滤波,滤除异常点
|
||||||
|
sg_lineDataRemoveOutlier_changeOriginData(&lineData[0], linePtNum, filterParam);
|
||||||
|
|
||||||
|
std::vector<SSG_RUN> segs;
|
||||||
|
wd_getLineDataIntervals(
|
||||||
|
lineData,
|
||||||
|
lineSegPara,
|
||||||
|
segs);
|
||||||
|
//将seg端点作为边缘点。做了地面调平后,垂直孔的内侧在XY平面上均为边缘点。
|
||||||
|
for (int i = 0, i_max = (int)segs.size(); i < i_max; i++)
|
||||||
|
{
|
||||||
|
int ptIdx = segs[i].start;
|
||||||
|
endingPoints.push_back(lineData[ptIdx].pt3D);
|
||||||
|
pointMask[line][ptIdx] = 1; //防止重复
|
||||||
|
ptIdx = segs[i].start + segs[i].len - 1;
|
||||||
|
endingPoints.push_back(lineData[ptIdx].pt3D);
|
||||||
|
pointMask[line][ptIdx] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//生成水平扫描
|
||||||
|
std::vector<std::vector<SVzNL3DPosition>> hLines_raw;
|
||||||
|
hLines_raw.resize(linePtNum);
|
||||||
|
for (int i = 0; i < linePtNum; i++)
|
||||||
|
hLines_raw[i].resize(lineNum);
|
||||||
|
for (int line = 0; line < lineNum; line++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < linePtNum; j++)
|
||||||
|
{
|
||||||
|
scanLines[line][j].nPointIdx = 0; //将原始数据的序列清0(会转义使用)
|
||||||
|
hLines_raw[j][line] = scanLines[line][j];
|
||||||
|
hLines_raw[j][line].pt3D.x = scanLines[line][j].pt3D.y;
|
||||||
|
hLines_raw[j][line].pt3D.y = scanLines[line][j].pt3D.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//水平arc特征提取
|
||||||
|
int lineNum_h_raw = (int)hLines_raw.size();
|
||||||
|
for (int line = 0; line < lineNum_h_raw; line++)
|
||||||
|
{
|
||||||
|
if (line == 974)
|
||||||
|
int kkk = 1;
|
||||||
|
std::vector<SVzNL3DPosition>& lineData = hLines_raw[line];
|
||||||
|
//滤波,滤除异常点
|
||||||
|
int ptNum = (int)lineData.size();
|
||||||
|
sg_lineDataRemoveOutlier_changeOriginData(&lineData[0], ptNum, filterParam);
|
||||||
|
|
||||||
|
std::vector<SSG_RUN> segs;
|
||||||
|
wd_getLineDataIntervals(
|
||||||
|
lineData,
|
||||||
|
lineSegPara,
|
||||||
|
segs);
|
||||||
|
//将seg端点作为边缘点。做了地面调平后,垂直孔的内侧在XY平面上均为边缘点。
|
||||||
|
for (int i = 0, i_max = (int)segs.size(); i < i_max; i++)
|
||||||
|
{
|
||||||
|
int ptIdx = segs[i].start;
|
||||||
|
if (pointMask[ptIdx][line] == 0) //防止点重复
|
||||||
|
{
|
||||||
|
SVzNL3DPoint an_ending;
|
||||||
|
an_ending.x = lineData[ptIdx].pt3D.y;
|
||||||
|
an_ending.y = lineData[ptIdx].pt3D.x;
|
||||||
|
an_ending.z = lineData[ptIdx].pt3D.z;
|
||||||
|
endingPoints.push_back(an_ending);
|
||||||
|
pointMask[ptIdx][line] = 1;
|
||||||
|
}
|
||||||
|
ptIdx = segs[i].start + segs[i].len - 1;
|
||||||
|
if (pointMask[ptIdx][line] == 0) //防止点重复
|
||||||
|
{
|
||||||
|
SVzNL3DPoint an_ending;
|
||||||
|
an_ending.x = lineData[ptIdx].pt3D.y;
|
||||||
|
an_ending.y = lineData[ptIdx].pt3D.x;
|
||||||
|
an_ending.z = lineData[ptIdx].pt3D.z;
|
||||||
|
endingPoints.push_back(an_ending);
|
||||||
|
pointMask[ptIdx][line] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//标注
|
||||||
|
std::vector<std::vector<SSG_featureClusteringInfo>> featureInfoMask;
|
||||||
|
std::vector<std::vector<SVzNL3DPoint>> feature3DInfo;
|
||||||
|
featureInfoMask.resize(lineNum);
|
||||||
|
feature3DInfo.resize(lineNum);
|
||||||
|
for (int i = 0; i < lineNum; i++)
|
||||||
|
{
|
||||||
|
featureInfoMask[i].resize(lineNum_h_raw);
|
||||||
|
feature3DInfo[i].resize(lineNum_h_raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
//标注
|
||||||
|
for (int line = 0; line < lineNum; line++)
|
||||||
|
{
|
||||||
|
std::vector<int>& a_lineMask = pointMask[line];
|
||||||
|
for (int m = 0; m < lineNum_h_raw; m++)
|
||||||
|
{
|
||||||
|
if (a_lineMask[m] > 0)
|
||||||
|
{
|
||||||
|
SSG_featureClusteringInfo& a_featureInfo = featureInfoMask[line][m];
|
||||||
|
a_featureInfo.clusterID = 0;
|
||||||
|
a_featureInfo.featurType = 1;
|
||||||
|
a_featureInfo.featureIdx_v = 0;
|
||||||
|
a_featureInfo.featureIdx_h = 0;
|
||||||
|
a_featureInfo.lineIdx = line;
|
||||||
|
a_featureInfo.ptIdx = m;
|
||||||
|
a_featureInfo.flag = 0;
|
||||||
|
feature3DInfo[line][m] = scanLines[line][m].pt3D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//聚类
|
||||||
|
//采用迭代思想,回归思路进行高效聚类
|
||||||
|
std::vector<std::vector< SVzNL2DPoint>> clusters; //只记录位置
|
||||||
|
std::vector<SVzNL3DRangeD> clustersRoi3D;
|
||||||
|
int clusterID = 1;
|
||||||
|
int clusterCheckWin = 5;
|
||||||
|
for (int y = 0; y < lineNum_h_raw; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < lineNum; x++)
|
||||||
|
{
|
||||||
|
SSG_featureClusteringInfo& a_featureInfo = featureInfoMask[x][y];
|
||||||
|
if ((0 == a_featureInfo.featurType) || (a_featureInfo.clusterID > 0)) //非特征或已经处理
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SVzNL3DPoint& a_feature3DValue = feature3DInfo[x][y];
|
||||||
|
SVzNL3DRangeD a_clusterRoi;
|
||||||
|
a_clusterRoi.xRange.min = a_feature3DValue.x;
|
||||||
|
a_clusterRoi.xRange.max = a_feature3DValue.x;
|
||||||
|
a_clusterRoi.yRange.min = a_feature3DValue.y;
|
||||||
|
a_clusterRoi.yRange.max = a_feature3DValue.y;
|
||||||
|
a_clusterRoi.zRange.min = a_feature3DValue.z;
|
||||||
|
a_clusterRoi.zRange.max = a_feature3DValue.z;
|
||||||
|
|
||||||
|
SVzNL2DPoint a_seedPos = { x, y };
|
||||||
|
std::vector< SVzNL2DPoint> a_cluster;
|
||||||
|
a_cluster.push_back(a_seedPos);
|
||||||
|
wd_gridPointClustering(
|
||||||
|
featureInfoMask,//int,记录特征标记和clusterID,附加一个flag
|
||||||
|
feature3DInfo,//double,记录坐标信息
|
||||||
|
clusterCheckWin, //搜索窗口
|
||||||
|
growParam,//聚类条件
|
||||||
|
clusterID, //当前Cluster的ID
|
||||||
|
a_cluster, //result
|
||||||
|
a_clusterRoi
|
||||||
|
);
|
||||||
|
clusters.push_back(a_cluster);
|
||||||
|
clustersRoi3D.push_back(a_clusterRoi);
|
||||||
|
clusterID++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//聚类结果分析
|
||||||
|
std::vector<int> validCluserIndexing;
|
||||||
|
int clusterSize = (int)clusters.size();
|
||||||
|
for (int i = 0; i < clusterSize; i++)
|
||||||
|
{
|
||||||
|
SVzNL3DRangeD& a_roi = clustersRoi3D[i];
|
||||||
|
double L = a_roi.xRange.max - a_roi.xRange.min;
|
||||||
|
double W = a_roi.yRange.max - a_roi.yRange.min;
|
||||||
|
if ((L > workpiecePara.holeDiameter * 0.5) && (L < workpiecePara.holeDiameter * 2) &&
|
||||||
|
(W > workpiecePara.holeDiameter * 0.5) && (W < workpiecePara.holeDiameter * 2))
|
||||||
|
validCluserIndexing.push_back(i);
|
||||||
|
}
|
||||||
|
//生成结果
|
||||||
|
std::vector< SWD_HoleInfo> holes;
|
||||||
|
int objectSize = (int)validCluserIndexing.size();
|
||||||
|
for (int objIdx = 0; objIdx < objectSize; objIdx++)
|
||||||
|
{
|
||||||
|
std::vector<SVzNL3DPoint> pointArray;
|
||||||
|
int clusterIdx = validCluserIndexing[objIdx];
|
||||||
|
//取cluster上的点
|
||||||
|
int clusterPtSize = (int)clusters[clusterIdx].size();
|
||||||
|
double minZ = DBL_MAX;
|
||||||
|
for (int i = 0; i < clusterPtSize; i++)
|
||||||
|
{
|
||||||
|
SVzNL2DPoint a_pos = clusters[clusterIdx][i];
|
||||||
|
SSG_featureClusteringInfo& a_featureInfo = featureInfoMask[a_pos.x][a_pos.y];
|
||||||
|
int lineIdx = a_featureInfo.lineIdx;
|
||||||
|
int ptIdx = a_featureInfo.ptIdx;
|
||||||
|
SVzNL3DPoint a_pt3d = scanLines[lineIdx][ptIdx].pt3D;
|
||||||
|
if (minZ > a_pt3d.z)
|
||||||
|
minZ = a_pt3d.z;
|
||||||
|
pointArray.push_back(a_pt3d);
|
||||||
|
}
|
||||||
|
//圆拟合
|
||||||
|
SVzNL3DPoint center;
|
||||||
|
double radius;
|
||||||
|
double err = fitCircleByLeastSquare(pointArray, center, radius);
|
||||||
|
center.z = minZ;
|
||||||
|
SWD_HoleInfo a_hole;
|
||||||
|
a_hole.center = { center.x, center.y, center.z };
|
||||||
|
a_hole.radius = radius;
|
||||||
|
holes.push_back(a_hole);
|
||||||
|
}
|
||||||
|
//分割
|
||||||
|
//方法:先搜索与W最接近的点,然后条件搜索(垂直)与L最接近的点
|
||||||
|
double distDeviation = 5.0; //距离搜索的合格门限。小于此距离,认为搜索到的目标为有效
|
||||||
|
for (int objIdx = 0; objIdx < objectSize; objIdx++)
|
||||||
|
{
|
||||||
|
if (holes[objIdx].radius < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
holes[objIdx].radius = -1;
|
||||||
|
SWD_HoleInfo& p0 = holes[objIdx];
|
||||||
|
int idx1 = distanceSearchObject(p0.center, holes, workpiecePara.holeDist_W, distDeviation);
|
||||||
|
if (idx1 < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SVzNLRangeD angleRange = { 85, 95 }; //垂直,5度范围
|
||||||
|
SWD_HoleInfo& p1 = holes[idx1];
|
||||||
|
//搜索最接近distance且角度为angle的目标, 以角度为优先
|
||||||
|
int idx2 = angleConditionDistanceSearch(
|
||||||
|
p0.center, p1.center,
|
||||||
|
holes,
|
||||||
|
workpiecePara.holeDist_L, distDeviation,
|
||||||
|
angleRange);
|
||||||
|
if (idx2 < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SWD_HoleInfo& p2 = holes[idx2];
|
||||||
|
//搜索最接近distance且角度为angle的目标, 以角度为优先
|
||||||
|
int idx3 = angleConditionDistanceSearch(
|
||||||
|
p1.center, p0.center,
|
||||||
|
holes,
|
||||||
|
workpiecePara.holeDist_L, distDeviation,
|
||||||
|
angleRange);
|
||||||
|
if (idx3 < 0)
|
||||||
|
continue;
|
||||||
|
SWD_HoleInfo& p3 = holes[idx3];
|
||||||
|
p1.radius = -1;
|
||||||
|
p2.radius = -1;
|
||||||
|
p3.radius = -1;
|
||||||
|
|
||||||
|
//重新计算Z值。因为沉孔的原因,Z值会不准确。取四条边的中点处的Z值的均值作为整个的Z值
|
||||||
|
|
||||||
|
WD_workpieceInfo a_workpiece;
|
||||||
|
a_workpiece.workpieceType = workpiecePara.workpieceType;
|
||||||
|
a_workpiece.holes.push_back(p0.center);
|
||||||
|
a_workpiece.holes.push_back(p1.center);
|
||||||
|
a_workpiece.holes.push_back(p2.center);
|
||||||
|
a_workpiece.holes.push_back(p3.center);
|
||||||
|
a_workpiece.center = { (p0.center.x + p1.center.x + p2.center.x + p3.center.x) / 4,
|
||||||
|
(p0.center.y + p1.center.y + p2.center.y + p3.center.y) / 4,
|
||||||
|
(p0.center.z + p1.center.z + p2.center.z + p3.center.z) / 4 };
|
||||||
|
|
||||||
|
SVzNL3DPoint y_dir;
|
||||||
|
if (p0.center.y < p2.center.y)
|
||||||
|
y_dir = { p0.center.x - p2.center.x, p0.center.y - p2.center.y, a_workpiece.center.z };
|
||||||
|
else
|
||||||
|
y_dir = { p2.center.x - p0.center.x, p2.center.y - p0.center.y, a_workpiece.center.z };
|
||||||
|
a_workpiece.y_dir = { y_dir.x + a_workpiece.center.x, y_dir.y + a_workpiece.center.y, y_dir.z };
|
||||||
|
a_workpiece.z_dir = { a_workpiece.center.x, a_workpiece.center.y, a_workpiece.center.z - 10 };
|
||||||
|
workpiecePositioning.push_back(a_workpiece);
|
||||||
|
}
|
||||||
|
|
||||||
|
int workpieceNum = (int)workpiecePositioning.size();
|
||||||
|
//旋转回去
|
||||||
|
for (int i = 0; i < workpieceNum; i++)
|
||||||
|
{
|
||||||
|
SVzNL3DPoint rpt;
|
||||||
|
rpt = _ptRotate(workpiecePositioning[i].center, groundCalibPara.invRMatrix);
|
||||||
|
workpiecePositioning[i].center = rpt;
|
||||||
|
rpt = _ptRotate(workpiecePositioning[i].y_dir, groundCalibPara.invRMatrix);
|
||||||
|
workpiecePositioning[i].y_dir = rpt;
|
||||||
|
rpt = _ptRotate(workpiecePositioning[i].z_dir, groundCalibPara.invRMatrix);
|
||||||
|
workpiecePositioning[i].z_dir = rpt;
|
||||||
|
for (int j = 0, j_max = (int)workpiecePositioning[i].holes.size(); j < j_max; j++)
|
||||||
|
{
|
||||||
|
rpt = _ptRotate(workpiecePositioning[i].holes[j], groundCalibPara.invRMatrix);
|
||||||
|
workpiecePositioning[i].holes[j] = rpt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
48
sourceCode/workpieceHolePositioning_Export.h
Normal file
48
sourceCode/workpieceHolePositioning_Export.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "SG_algo_Export.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define _OUTPUT_DEBUG_DATA 1
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int workpieceType;
|
||||||
|
double holeDiameter; //孔直径
|
||||||
|
double holeDist_L; //孔间距_长
|
||||||
|
double holeDist_W; //孔间距_宽
|
||||||
|
}WD_workpieceHoleParam;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int workpieceType;
|
||||||
|
std::vector<SVzNL3DPoint> holes;
|
||||||
|
SVzNL3DPoint center;
|
||||||
|
SVzNL3DPoint z_dir;
|
||||||
|
SVzNL3DPoint y_dir;
|
||||||
|
}WD_workpieceInfo;
|
||||||
|
|
||||||
|
//读版本号
|
||||||
|
SG_APISHARED_EXPORT const char* wd_workpieceHolePositioningVersion(void);
|
||||||
|
|
||||||
|
//相机水平安装计算地面调平参数。。
|
||||||
|
//旋转矩阵为调平参数,即将平面法向调整为垂直向量的参数
|
||||||
|
SG_APISHARED_EXPORT SSG_planeCalibPara wd_getGroundCalibPara(
|
||||||
|
std::vector< std::vector<SVzNL3DPosition>>& scanLines);
|
||||||
|
|
||||||
|
//相机水平时姿态调平,并去除地面
|
||||||
|
SG_APISHARED_EXPORT void wd_lineDataR(
|
||||||
|
std::vector< SVzNL3DPosition>& a_line,
|
||||||
|
const double* camPoseR,
|
||||||
|
double groundH);
|
||||||
|
|
||||||
|
//工件孔定位
|
||||||
|
SG_APISHARED_EXPORT void wd_workpieceHolePositioning(
|
||||||
|
std::vector< std::vector<SVzNL3DPosition>>& scanLinesInput,
|
||||||
|
const WD_workpieceHoleParam workpiecePara,
|
||||||
|
const SSG_lineSegParam lineSegPara,
|
||||||
|
const SSG_outlierFilterParam filterParam,
|
||||||
|
const SSG_treeGrowParam growParam,
|
||||||
|
const SSG_planeCalibPara groundCalibPara,
|
||||||
|
std::vector< WD_workpieceInfo>& workpiecePositioning,
|
||||||
|
int* errCode);
|
||||||
172
workpieceHolePositioning/workpieceHolePositioning.vcxproj
Normal file
172
workpieceHolePositioning/workpieceHolePositioning.vcxproj
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\sourceCode\workpieceHolePositioning.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\sourceCode\workpieceHolePositioning_Export.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>16.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{c65f7f4b-b77a-4d65-9490-5304b760b607}</ProjectGuid>
|
||||||
|
<RootNamespace>workpieceHolePositioning</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
<OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
|
||||||
|
<IncludePath>..\..\thirdParty\VzNLSDK\Inc;..\..\thirdParty\opencv320\build\include;..\sourceCode;..\sourceCode\inc;$(IncludePath)</IncludePath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
<OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
|
||||||
|
<IncludePath>..\..\thirdParty\VzNLSDK\Inc;..\..\thirdParty\opencv320\build\include;..\sourceCode;..\sourceCode\inc;$(IncludePath)</IncludePath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;WORKPIECEHOLEPOSITIONING_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableUAC>false</EnableUAC>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;WORKPIECEHOLEPOSITIONING_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableUAC>false</EnableUAC>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;WORKPIECEHOLEPOSITIONING_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
<AdditionalIncludeDirectories>..\..\thirdParty\opencv320\build\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableUAC>false</EnableUAC>
|
||||||
|
<AdditionalLibraryDirectories>..\..\thirdParty\opencv320\build\x64\vc14\lib;..\build\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>opencv_world320d.lib;baseAlgorithm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;WORKPIECEHOLEPOSITIONING_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
<AdditionalIncludeDirectories>..\..\thirdParty\opencv320\build\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableUAC>false</EnableUAC>
|
||||||
|
<AdditionalLibraryDirectories>..\..\thirdParty\opencv320\build\x64\vc14\lib;..\build\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>opencv_world320.lib;baseAlgorithm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
531
workpieceHolePositioning_test/workpieceHolePositioning_test.cpp
Normal file
531
workpieceHolePositioning_test/workpieceHolePositioning_test.cpp
Normal file
@ -0,0 +1,531 @@
|
|||||||
|
// BQ_workpieceCornerExtract_test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <VZNL_Types.h>
|
||||||
|
#include "direct.h"
|
||||||
|
#include <string>
|
||||||
|
#include "workpieceHolePositioning_Export.h"
|
||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
int g;
|
||||||
|
int b;
|
||||||
|
}SG_color;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int nPointIdx;
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
double z;
|
||||||
|
float r;
|
||||||
|
float g;
|
||||||
|
float b;
|
||||||
|
} SPointXYZRGB;
|
||||||
|
|
||||||
|
void vzReadLaserScanPointFromFile_XYZ_vector(const char* fileName, std::vector<std::vector< SVzNL3DPosition>>& scanData)
|
||||||
|
{
|
||||||
|
std::ifstream inputFile(fileName);
|
||||||
|
std::string linedata;
|
||||||
|
|
||||||
|
if (inputFile.is_open() == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::vector< SVzNL3DPosition> a_line;
|
||||||
|
int ptIdx = 0;
|
||||||
|
while (getline(inputFile, linedata))
|
||||||
|
{
|
||||||
|
if (0 == strncmp("Line_", linedata.c_str(), 5))
|
||||||
|
{
|
||||||
|
int ptSize = (int)a_line.size();
|
||||||
|
if (ptSize > 0)
|
||||||
|
{
|
||||||
|
scanData.push_back(a_line);
|
||||||
|
}
|
||||||
|
a_line.clear();
|
||||||
|
ptIdx = 0;
|
||||||
|
}
|
||||||
|
else if (0 == strncmp("{", linedata.c_str(), 1))
|
||||||
|
{
|
||||||
|
float X, Y, Z;
|
||||||
|
int imageY = 0;
|
||||||
|
float leftX, leftY;
|
||||||
|
float rightX, rightY;
|
||||||
|
sscanf_s(linedata.c_str(), "{%f,%f,%f}-{%f,%f}-{%f,%f}", &X, &Y, &Z, &leftX, &leftY, &rightX, &rightY);
|
||||||
|
SVzNL3DPosition a_pt;
|
||||||
|
a_pt.pt3D.x = X;
|
||||||
|
a_pt.pt3D.y = Y;
|
||||||
|
a_pt.pt3D.z = Z;
|
||||||
|
a_pt.nPointIdx = ptIdx;
|
||||||
|
ptIdx++;
|
||||||
|
a_line.push_back(a_pt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//last line
|
||||||
|
int ptSize = (int)a_line.size();
|
||||||
|
if (ptSize > 0)
|
||||||
|
{
|
||||||
|
scanData.push_back(a_line);
|
||||||
|
a_line.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
inputFile.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _outputScanDataFile_XYZ_vector(char* fileName, std::vector<std::vector< SVzNL3DPosition>>& scanData)
|
||||||
|
{
|
||||||
|
std::ofstream sw(fileName);
|
||||||
|
int lineNum = scanData.size();
|
||||||
|
sw << "LineNum:" << lineNum << std::endl;
|
||||||
|
sw << "DataType: 0" << std::endl;
|
||||||
|
sw << "ScanSpeed: 0" << std::endl;
|
||||||
|
sw << "PointAdjust: 1" << std::endl;
|
||||||
|
sw << "MaxTimeStamp: 0_0" << std::endl;
|
||||||
|
|
||||||
|
for (int line = 0; line < lineNum; line++)
|
||||||
|
{
|
||||||
|
int nPositionCnt = scanData[line].size();
|
||||||
|
sw << "Line_" << line << "_0_" << nPositionCnt << std::endl;
|
||||||
|
for (int i = 0; i < nPositionCnt; i++)
|
||||||
|
{
|
||||||
|
SVzNL3DPosition* pt3D = &scanData[line][i];
|
||||||
|
float x = (float)pt3D->pt3D.x;
|
||||||
|
float y = (float)pt3D->pt3D.y;
|
||||||
|
float z = (float)pt3D->pt3D.z;
|
||||||
|
char str[250];
|
||||||
|
sprintf_s(str, "{ %f, %f, %f } - { 0, 0 } - { 0, 0 }", x, y, z);
|
||||||
|
|
||||||
|
sw << str << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _outputCalibPara(char* fileName, SSG_planeCalibPara calibPara)
|
||||||
|
{
|
||||||
|
std::ofstream sw(fileName);
|
||||||
|
char dataStr[250];
|
||||||
|
//调平矩阵
|
||||||
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.planeCalib[0], calibPara.planeCalib[1], calibPara.planeCalib[2]);
|
||||||
|
sw << dataStr << std::endl;
|
||||||
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.planeCalib[3], calibPara.planeCalib[4], calibPara.planeCalib[5]);
|
||||||
|
sw << dataStr << std::endl;
|
||||||
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.planeCalib[6], calibPara.planeCalib[7], calibPara.planeCalib[8]);
|
||||||
|
sw << dataStr << std::endl;
|
||||||
|
//地面高度
|
||||||
|
sprintf_s(dataStr, 250, "%g", calibPara.planeHeight);
|
||||||
|
sw << dataStr << std::endl;
|
||||||
|
//反向旋转矩阵
|
||||||
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.invRMatrix[0], calibPara.invRMatrix[1], calibPara.invRMatrix[2]);
|
||||||
|
sw << dataStr << std::endl;
|
||||||
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.invRMatrix[3], calibPara.invRMatrix[4], calibPara.invRMatrix[5]);
|
||||||
|
sw << dataStr << std::endl;
|
||||||
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.invRMatrix[6], calibPara.invRMatrix[7], calibPara.invRMatrix[8]);
|
||||||
|
sw << dataStr << std::endl;
|
||||||
|
|
||||||
|
sw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _outputWorkpieceInfo(char* fileName, std::vector< WD_workpieceInfo>& workpiecePositioning)
|
||||||
|
{
|
||||||
|
std::ofstream sw(fileName);
|
||||||
|
char dataStr[250];
|
||||||
|
|
||||||
|
int number = (int)workpiecePositioning.size();
|
||||||
|
for (int i = 0; i < number; i++)
|
||||||
|
{
|
||||||
|
sprintf_s(dataStr, 250, "工件_%d", i + 1);
|
||||||
|
sw << dataStr << std::endl;
|
||||||
|
int holeNumber = (int)workpiecePositioning[i].holes.size();
|
||||||
|
for (int j = 0; j < holeNumber; j++)
|
||||||
|
{
|
||||||
|
sprintf_s(dataStr, 250, " 孔%d: (%g, %g, %g)", (j+1), workpiecePositioning[i].holes[j].x, workpiecePositioning[i].holes[j].y, workpiecePositioning[i].holes[j].z);
|
||||||
|
sw << dataStr << std::endl;
|
||||||
|
}
|
||||||
|
sprintf_s(dataStr, 50, " center: (%g, %g, %g)", workpiecePositioning[i].center.x, workpiecePositioning[i].center.y, workpiecePositioning[i].center.z);
|
||||||
|
sw << dataStr << std::endl;
|
||||||
|
}
|
||||||
|
sw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _outputScanDataFile_vector(char* fileName, std::vector<std::vector<SVzNL3DPosition>>& scanLines, bool removeZeros, int* headNullLines)
|
||||||
|
{
|
||||||
|
std::ofstream sw(fileName);
|
||||||
|
int lineNum = (int)scanLines.size();
|
||||||
|
if (lineNum == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sw << "LineNum:" << lineNum << std::endl;
|
||||||
|
sw << "DataType: 0" << std::endl;
|
||||||
|
sw << "ScanSpeed: 0" << std::endl;
|
||||||
|
sw << "PointAdjust: 1" << std::endl;
|
||||||
|
sw << "MaxTimeStamp: 0_0" << std::endl;
|
||||||
|
|
||||||
|
int lineIdx = 0;
|
||||||
|
int null_lines = 0;
|
||||||
|
bool counterNull = true;
|
||||||
|
for (int line = 0; line < lineNum; line++)
|
||||||
|
{
|
||||||
|
int linePtNum = (int)scanLines[line].size();
|
||||||
|
if (linePtNum == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (true == removeZeros)
|
||||||
|
{
|
||||||
|
int vldPtNum = 0;
|
||||||
|
for (int i = 0; i < linePtNum; i++)
|
||||||
|
{
|
||||||
|
if (scanLines[line][i].pt3D.z > 1e-4)
|
||||||
|
vldPtNum++;
|
||||||
|
}
|
||||||
|
linePtNum = vldPtNum;
|
||||||
|
}
|
||||||
|
sw << "Line_" << lineIdx << "_0_" << linePtNum << std::endl;
|
||||||
|
lineIdx++;
|
||||||
|
bool isNull = true;
|
||||||
|
for (int i = 0; i < linePtNum; i++)
|
||||||
|
{
|
||||||
|
SVzNL3DPoint* pt3D = &scanLines[line][i].pt3D;
|
||||||
|
if ((pt3D->z > 1e-4) && (isNull == true))
|
||||||
|
isNull = false;
|
||||||
|
if ((true == removeZeros) && (pt3D->z < 1e-4))
|
||||||
|
continue;
|
||||||
|
float x = (float)pt3D->x;
|
||||||
|
float y = (float)pt3D->y;
|
||||||
|
float z = (float)pt3D->z;
|
||||||
|
sw << "{ " << x << "," << y << "," << z << " }-";
|
||||||
|
sw << "{0,0}-{0,0}" << std::endl;
|
||||||
|
}
|
||||||
|
if (true == counterNull)
|
||||||
|
{
|
||||||
|
if (true == isNull)
|
||||||
|
null_lines++;
|
||||||
|
else
|
||||||
|
counterNull = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*headNullLines = null_lines;
|
||||||
|
sw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
SSG_planeCalibPara _readCalibPara(char* fileName)
|
||||||
|
{
|
||||||
|
//设置初始结果
|
||||||
|
double initCalib[9] = {
|
||||||
|
1.0, 0.0, 0.0,
|
||||||
|
0.0, 1.0, 0.0,
|
||||||
|
0.0, 0.0, 1.0 };
|
||||||
|
SSG_planeCalibPara planePara;
|
||||||
|
for (int i = 0; i < 9; i++)
|
||||||
|
planePara.planeCalib[i] = initCalib[i];
|
||||||
|
planePara.planeHeight = -1.0;
|
||||||
|
for (int i = 0; i < 9; i++)
|
||||||
|
planePara.invRMatrix[i] = initCalib[i];
|
||||||
|
|
||||||
|
std::ifstream inputFile(fileName);
|
||||||
|
std::string linedata;
|
||||||
|
|
||||||
|
if (inputFile.is_open() == false)
|
||||||
|
return planePara;
|
||||||
|
|
||||||
|
//调平矩阵
|
||||||
|
std::getline(inputFile, linedata);
|
||||||
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.planeCalib[0], &planePara.planeCalib[1], &planePara.planeCalib[2]);
|
||||||
|
std::getline(inputFile, linedata);
|
||||||
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.planeCalib[3], &planePara.planeCalib[4], &planePara.planeCalib[5]);
|
||||||
|
std::getline(inputFile, linedata);
|
||||||
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.planeCalib[6], &planePara.planeCalib[7], &planePara.planeCalib[8]);
|
||||||
|
//地面高度
|
||||||
|
std::getline(inputFile, linedata);
|
||||||
|
sscanf_s(linedata.c_str(), "%lf", &planePara.planeHeight);
|
||||||
|
//反向旋转矩阵
|
||||||
|
std::getline(inputFile, linedata);
|
||||||
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.invRMatrix[0], &planePara.invRMatrix[1], &planePara.invRMatrix[2]);
|
||||||
|
std::getline(inputFile, linedata);
|
||||||
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.invRMatrix[3], &planePara.invRMatrix[4], &planePara.invRMatrix[5]);
|
||||||
|
std::getline(inputFile, linedata);
|
||||||
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.invRMatrix[6], &planePara.invRMatrix[7], &planePara.invRMatrix[8]);
|
||||||
|
|
||||||
|
inputFile.close();
|
||||||
|
return planePara;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _outputRGBDResult_RGBD(
|
||||||
|
char* fileName,
|
||||||
|
std::vector<std::vector<SVzNL3DPosition>>& scanLines,
|
||||||
|
std::vector< WD_workpieceInfo>& workpiecePositioning)
|
||||||
|
{
|
||||||
|
std::vector<SVzNL3DPosition> objects;
|
||||||
|
int objNumber = (int)workpiecePositioning.size();
|
||||||
|
for (int i = 0; i < objNumber; i++)
|
||||||
|
{
|
||||||
|
SVzNL3DPosition a_objPt;
|
||||||
|
int holeNumber = (int)workpiecePositioning[i].holes.size();
|
||||||
|
for (int j = 0; j < holeNumber; j++)
|
||||||
|
{
|
||||||
|
a_objPt.nPointIdx = i + 1;
|
||||||
|
a_objPt.pt3D = workpiecePositioning[i].holes[j];
|
||||||
|
objects.push_back(a_objPt);
|
||||||
|
}
|
||||||
|
objects.push_back(a_objPt);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lineNum = (int)scanLines.size();
|
||||||
|
std::ofstream sw(fileName);
|
||||||
|
int realLines = (objNumber == 0) ? lineNum : (lineNum + 1);
|
||||||
|
sw << "LineNum:" << realLines << std::endl;
|
||||||
|
sw << "DataType: 0" << std::endl;
|
||||||
|
sw << "ScanSpeed: 0" << std::endl;
|
||||||
|
sw << "PointAdjust: 1" << std::endl;
|
||||||
|
sw << "MaxTimeStamp: 0_0" << std::endl;
|
||||||
|
|
||||||
|
int maxLineIndex = 0;
|
||||||
|
int max_stamp = 0;
|
||||||
|
SG_color rgb = { 0, 0, 0 };
|
||||||
|
SG_color objColor[8] = {
|
||||||
|
{245,222,179},//淡黄色
|
||||||
|
{210,105, 30},//巧克力色
|
||||||
|
{240,230,140},//黄褐色
|
||||||
|
{135,206,235},//天蓝色
|
||||||
|
{250,235,215},//古董白
|
||||||
|
{189,252,201},//薄荷色
|
||||||
|
{221,160,221},//梅红色
|
||||||
|
{188,143,143},//玫瑰红色
|
||||||
|
};
|
||||||
|
int size = 1;
|
||||||
|
int lineIdx = 0;
|
||||||
|
for (int line = 0; line < lineNum; line++)
|
||||||
|
{
|
||||||
|
int linePtNum = (int)scanLines[line].size();
|
||||||
|
if (linePtNum == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sw << "Line_" << lineIdx << "_0_" << linePtNum << std::endl;
|
||||||
|
lineIdx++;
|
||||||
|
for (int i = 0; i < linePtNum; i++)
|
||||||
|
{
|
||||||
|
SVzNL3DPosition* pt3D = &scanLines[line][i];
|
||||||
|
if (pt3D->nPointIdx > 0)
|
||||||
|
int kkk = 1;
|
||||||
|
int featureType_v = pt3D->nPointIdx & 0xff;
|
||||||
|
int featureType_h = featureType_v >> 4;
|
||||||
|
featureType_v &= 0x0f;
|
||||||
|
|
||||||
|
if (pt3D->nPointIdx == 1)
|
||||||
|
{
|
||||||
|
rgb = { 255, 97, 0 };
|
||||||
|
size = 5;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rgb = { 200, 200, 200 };
|
||||||
|
size = 1;
|
||||||
|
}
|
||||||
|
float x = (float)pt3D->pt3D.x;
|
||||||
|
float y = (float)pt3D->pt3D.y;
|
||||||
|
float z = (float)pt3D->pt3D.z;
|
||||||
|
sw << "{" << x << "," << y << "," << z << "}-";
|
||||||
|
sw << "{0,0}-{0,0}-";
|
||||||
|
sw << "{" << rgb.r << "," << rgb.g << "," << rgb.b << "," << size << " }" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int linePtNum = (int)objects.size();
|
||||||
|
sw << "Line_" << lineNum << "_0_" << linePtNum + 1 << std::endl;
|
||||||
|
lineNum++;
|
||||||
|
for (int i = 0; i < linePtNum; i++)
|
||||||
|
{
|
||||||
|
int colorIdx = objects[i].nPointIdx % 8;
|
||||||
|
rgb = objColor[colorIdx];
|
||||||
|
size = 10;
|
||||||
|
float x = (float)objects[i].pt3D.x;
|
||||||
|
float y = (float)objects[i].pt3D.y;
|
||||||
|
float z = (float)objects[i].pt3D.z;
|
||||||
|
sw << "{" << x << "," << y << "," << z << "}-";
|
||||||
|
sw << "{0,0}-{0,0}-";
|
||||||
|
sw << "{" << rgb.r << "," << rgb.g << "," << rgb.b << "," << size << " }" << std::endl;
|
||||||
|
}
|
||||||
|
//输出方向线条
|
||||||
|
|
||||||
|
sw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
SVzNL3DPoint _pointRT(SVzNL3DPoint& origin, const double* R, const double* T)
|
||||||
|
{
|
||||||
|
SVzNL3DPoint result;
|
||||||
|
result.x = origin.x * R[0] + origin.y * R[1] + origin.z * R[2];
|
||||||
|
result.y = origin.x * R[3] + origin.y * R[4] + origin.z * R[5];
|
||||||
|
result.z = origin.x * R[6] + origin.y * R[7] + origin.z * R[8];
|
||||||
|
result.x += T[0];
|
||||||
|
result.y += T[1];
|
||||||
|
result.z += T[2];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_COMPUTE_CALIB_PARA 0
|
||||||
|
#define TEST_COMPUTE_HOLE 1
|
||||||
|
#define TEST_GROUP 1
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
const char* dataPath[TEST_GROUP] = {
|
||||||
|
|
||||||
|
"F:/ShangGu/项目/冠钦项目/拓普发工件孔定位/拓普发点云/", //0
|
||||||
|
};
|
||||||
|
|
||||||
|
SVzNLRange fileIdx[TEST_GROUP] = {
|
||||||
|
{1,4},
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* ver = wd_workpieceHolePositioningVersion();
|
||||||
|
printf("ver:%s\n", ver);
|
||||||
|
|
||||||
|
#if TEST_COMPUTE_CALIB_PARA
|
||||||
|
char _calib_datafile[256];
|
||||||
|
sprintf_s(_calib_datafile, "%sLaserData_ground.txt", dataPath[0]);
|
||||||
|
int lineNum = 0;
|
||||||
|
float lineV = 0.0f;
|
||||||
|
int dataCalib = 0;
|
||||||
|
int maxTimeStamp = 0;
|
||||||
|
int clockPerSecond = 0;
|
||||||
|
std::vector<std::vector< SVzNL3DPosition>> scanData;
|
||||||
|
vzReadLaserScanPointFromFile_XYZ_vector(_calib_datafile, scanData);
|
||||||
|
|
||||||
|
lineNum = (int)scanData.size();
|
||||||
|
if (scanData.size() > 0)
|
||||||
|
{
|
||||||
|
SSG_planeCalibPara calibPara = wd_getGroundCalibPara(scanData);
|
||||||
|
//结果进行验证
|
||||||
|
for (int i = 0; i < lineNum; i++)
|
||||||
|
{
|
||||||
|
if (i == 14)
|
||||||
|
int kkk = 1;
|
||||||
|
//行处理
|
||||||
|
//调平,去除地面
|
||||||
|
wd_lineDataR(scanData[i], calibPara.planeCalib, -1);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
char calibFile[250];
|
||||||
|
sprintf_s(calibFile, "%sground_calib_para.txt", dataPath[0]);
|
||||||
|
_outputCalibPara(calibFile, calibPara);
|
||||||
|
char _out_file[256];
|
||||||
|
sprintf_s(_out_file, "%sscanData_ground_calib_verify.txt", dataPath[0]);
|
||||||
|
int headNullLines = 0;
|
||||||
|
_outputScanDataFile_vector(_out_file, scanData, false, &headNullLines);
|
||||||
|
|
||||||
|
for (int fidx = fileIdx[0].nMin; fidx <= fileIdx[0].nMax; fidx++)
|
||||||
|
{
|
||||||
|
//fidx =4;
|
||||||
|
char _scan_file[256];
|
||||||
|
sprintf_s(_scan_file, "%sLaserData_%d.txt", dataPath[0], fidx);
|
||||||
|
std::vector<std::vector< SVzNL3DPosition>> scanLines;
|
||||||
|
vzReadLaserScanPointFromFile_XYZ_vector(_scan_file, scanLines);
|
||||||
|
if (scanLines.size() == 0)
|
||||||
|
continue;
|
||||||
|
lineNum = (int)scanLines.size();
|
||||||
|
for (int i = 0; i < lineNum; i++)
|
||||||
|
{
|
||||||
|
//调平,去除地面
|
||||||
|
wd_lineDataR(scanLines[i], calibPara.planeCalib, -1);
|
||||||
|
}
|
||||||
|
sprintf_s(_scan_file, "%sLaserData_%d_calib_verify.txt", dataPath[0], fidx);
|
||||||
|
int headNullLines = 0;
|
||||||
|
_outputScanDataFile_vector(_scan_file, scanLines, false, &headNullLines);
|
||||||
|
}
|
||||||
|
printf("%s: calib done!\n", _calib_datafile);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TEST_COMPUTE_HOLE
|
||||||
|
for (int grp = 0; grp <= 0; grp++)
|
||||||
|
{
|
||||||
|
SSG_planeCalibPara groundCalibPara;
|
||||||
|
//初始化成单位阵
|
||||||
|
groundCalibPara.planeCalib[0] = 1.0;
|
||||||
|
groundCalibPara.planeCalib[1] = 0.0;
|
||||||
|
groundCalibPara.planeCalib[2] = 0.0;
|
||||||
|
groundCalibPara.planeCalib[3] = 0.0;
|
||||||
|
groundCalibPara.planeCalib[4] = 1.0;
|
||||||
|
groundCalibPara.planeCalib[5] = 0.0;
|
||||||
|
groundCalibPara.planeCalib[6] = 0.0;
|
||||||
|
groundCalibPara.planeCalib[7] = 0.0;
|
||||||
|
groundCalibPara.planeCalib[8] = 1.0;
|
||||||
|
groundCalibPara.planeHeight = -1.0;
|
||||||
|
for (int i = 0; i < 9; i++)
|
||||||
|
groundCalibPara.invRMatrix[i] = groundCalibPara.planeCalib[i];
|
||||||
|
char calibFile[250];
|
||||||
|
sprintf_s(calibFile, "%sground_calib_para.txt", dataPath[grp]);
|
||||||
|
groundCalibPara = _readCalibPara(calibFile);
|
||||||
|
|
||||||
|
for (int fidx = fileIdx[grp].nMin; fidx <= fileIdx[grp].nMax; fidx++)
|
||||||
|
{
|
||||||
|
//fidx =4;
|
||||||
|
char _scan_file[256];
|
||||||
|
sprintf_s(_scan_file, "%sLaserData_%d.txt", dataPath[grp], fidx);
|
||||||
|
std::vector<std::vector< SVzNL3DPosition>> scanLines;
|
||||||
|
vzReadLaserScanPointFromFile_XYZ_vector(_scan_file, scanLines);
|
||||||
|
if (scanLines.size() == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
long t1 = (long)GetTickCount64();//统计时间
|
||||||
|
|
||||||
|
SSG_lineSegParam lineSegPara;
|
||||||
|
lineSegPara.distScale = 3.0;
|
||||||
|
lineSegPara.segGapTh_y = 3.0; //y方向间隔大于5mm认为是分段
|
||||||
|
lineSegPara.segGapTh_z = 10.0; //z方向间隔大于10mm认为是分段
|
||||||
|
SSG_outlierFilterParam filterParam;
|
||||||
|
filterParam.continuityTh = 20.0; //噪声滤除。当相邻点的z跳变大于此门限时,检查是否为噪声。若长度小于outlierLen, 视为噪声
|
||||||
|
filterParam.outlierTh = 5;
|
||||||
|
SSG_treeGrowParam growParam;
|
||||||
|
growParam.maxLineSkipNum = 10;
|
||||||
|
growParam.yDeviation_max = 10.0;
|
||||||
|
growParam.maxSkipDistance = 10.0;
|
||||||
|
growParam.zDeviation_max = 10.0;// algoParam.bagParam.bagH / 2; //袋子高度1/2
|
||||||
|
growParam.minLTypeTreeLen = 100; //mm
|
||||||
|
growParam.minVTypeTreeLen = 100; //mm
|
||||||
|
WD_workpieceHoleParam workpiecePara;
|
||||||
|
workpiecePara.workpieceType = 0;
|
||||||
|
workpiecePara.holeDiameter = 6.0; //
|
||||||
|
workpiecePara.holeDist_W = 32.0;
|
||||||
|
workpiecePara.holeDist_L = 40.0;
|
||||||
|
int errCode = 0;
|
||||||
|
std::vector< WD_workpieceInfo> workpiecePositioning;
|
||||||
|
wd_workpieceHolePositioning(
|
||||||
|
scanLines,
|
||||||
|
workpiecePara,
|
||||||
|
lineSegPara,
|
||||||
|
filterParam,
|
||||||
|
growParam,
|
||||||
|
groundCalibPara,
|
||||||
|
workpiecePositioning,
|
||||||
|
&errCode);
|
||||||
|
long t2 = (long)GetTickCount64();
|
||||||
|
printf("%s: %d(ms)!\n", _scan_file, (int)(t2 - t1));
|
||||||
|
//输出测试结果
|
||||||
|
sprintf_s(_scan_file, "%sresult\\LaserLine%d_result.txt", dataPath[grp], fidx);
|
||||||
|
_outputRGBDResult_RGBD(_scan_file, scanLines, workpiecePositioning);
|
||||||
|
sprintf_s(calibFile, "%sresult\\LaserLine%d_corner_info.txt", dataPath[grp], fidx);
|
||||||
|
_outputWorkpieceInfo(calibFile, workpiecePositioning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
|
||||||
|
// 调试程序: F5 或调试 >“开始调试”菜单
|
||||||
|
|
||||||
|
// 入门使用技巧:
|
||||||
|
// 1. 使用解决方案资源管理器窗口添加/管理文件
|
||||||
|
// 2. 使用团队资源管理器窗口连接到源代码管理
|
||||||
|
// 3. 使用输出窗口查看生成输出和其他消息
|
||||||
|
// 4. 使用错误列表窗口查看错误
|
||||||
|
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
|
||||||
|
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
|
||||||
@ -0,0 +1,157 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>16.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{ca8cba7f-4d72-4630-af6d-bf872306502c}</ProjectGuid>
|
||||||
|
<RootNamespace>workpieceHolePositioningtest</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
<OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
|
||||||
|
<IncludePath>..\..\thirdParty\VzNLSDK\Inc;..\sourceCode;..\sourceCode\inc;$(IncludePath)</IncludePath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
<OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
|
||||||
|
<IncludePath>..\..\thirdParty\VzNLSDK\Inc;..\sourceCode;..\sourceCode\inc;$(IncludePath)</IncludePath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>..\..\thirdParty\opencv320\build\include;</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>..\..\thirdParty\opencv320\build\x64\vc14\lib;..\build\x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>opencv_world320d.lib;workpieceHolePositioning.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>..\..\thirdParty\opencv320\build\include;</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>..\..\thirdParty\opencv320\build\x64\vc14\lib;..\build\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>opencv_world320.lib;workpieceHolePositioning.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="workpieceHolePositioning_test.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
Loading…
x
Reference in New Issue
Block a user