阅读背景:

分析一则halcon抓边拟合直线的小案例

来源:互联网 

例图:

完整算法:

1 read_image (Image, 'C:/Users/Administrator/Desktop/1.png') 2 threshold (Image, Regions, 0, 112) 3 4 skeleton(Regions,TriangleSkeleton) 5 6 gen_contours_skeleton_xld(TriangleSkeleton,TriangleContours,1,'filter') 7 8 segment_contours_xld(TriangleContours,ContoursSplit,'lines_circles', 5, 4, 2) 9 10 select_contours_xld(ContoursSplit,SelectedContours, 'contour_length',100, 999, -0.5, 0.5) 11 12 fit_line_contour_xld (SelectedContours, 'tukey', -1, 10, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist) 13 14 *计算三个夹角 15 angle_ll (RowBegin[0], ColBegin[0], RowEnd[0], ColEnd[0], RowBegin[1], ColBegin[1], RowEnd[1], ColEnd[1], Angle1) 16 angle_ll (RowBegin[0], ColBegin[0], RowEnd[0], ColEnd[0], RowBegin[2], ColBegin[2], RowEnd[2], ColEnd[2], Angle2) 17 angle_ll (RowBegin[1], ColBegin[1], RowEnd[1], ColEnd[1], RowBegin[2], ColBegin[2], RowEnd[2], ColEnd[2], Angle3) 18 19 Angle1:=abs(deg(Angle1)) 20 Angle2:=abs(deg(Angle2)) 21 Angle3:=abs(deg(Angle3)) 22 23 dev_display (Image) 24 dev_display (SelectedContours) 25 disp_message (3600, '角度:' + Angle1 + '°、 ' + Angle2 + '°、 ' + Angle3 + '°', 'image', 20, 20, 'red', 'true') 1 read_image (Image, 'C:/Users/Administra



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: