分析一則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')

 

結果:工具

 

步驟分析:spa

① 圖像三角形主要由3根直線構成;設計

閾值化、skeleton提取骨架、將骨架(region)轉爲xld、將xld打散分割、篩選xld獲得3條主xld、將這3條xld擬合成3條直線code

 

效果分析:blog

這種算法雖然步驟簡單,可是其實魯棒性並很差。主要風險在「篩選xld獲得3條主xld」這一步,有時候,它沒辦法準確篩選到咱們想要的xld,這樣後面的準確擬合也就無從談起。圖片

用過VisionPro的都知道,VisionPro它有抓邊的卡尺工具,它直接做用於圖像,簡單分析就知道魯棒性好得多。惋惜的是halcon並無直接提供相似工具,不過網上有大神作了個halcon本身的卡尺工具——rake函數。ci

 

除非線條特徵特別明顯的圖片,否則不建議使用本例的算法去抓邊,相似於rake的抓邊工具魯棒性更好,抓邊能力也更強。it

固然,若是你足夠有耐心,也能夠根據本例以及halcon的測量(Measure)助手設計本身的抓邊工具(函數)。

相關文章
相關標籤/搜索