Halcon拟合直线
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Halcon拟合直线相关的知识,希望对你有一定的参考价值。
read_image(Image,'C:/Users/研发/Pictures/Saved Pictures/qq.bmp')
dev_set_draw ('margin')
get_image_size(Image, Width, Height)
Row:=[479,479,479,479,479]
Col:=[450,455,460,465,470]
RowAfter:=[]
ColAfter:=[]
RowSelect:=[]
ColSelect:=[]
for Index:=0 to 4 by 1
gen_measure_rectangle2(Row[Index],Col[Index],rad(-90), 20, 2, Width, Height, 'nearest_neighbor', MeasureHandle)
gen_rectangle2(Rectangle,Row[Index],Col[Index],rad(-90), 20, 2)
measure_pos (Image, MeasureHandle, 3, 30, 'positive', 'first', RowEdge, ColumnEdge, Amplitude, Distance)
gen_cross_contour_xld(Cross, RowEdge, ColumnEdge, 6, 0.785398)
RowAfter[Index]:=RowEdge
ColAfter[Index]:=ColumnEdge
endfor
*所有点拟合直线
gen_contour_polygon_xld(Contour,RowAfter,ColAfter)
fit_line_contour_xld(Contour, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
gen_contour_polygon_xld (ContourD, [RowBegin,RowEnd], [ColBegin,ColEnd])
distance_pl(RowAfter,ColAfter,RowBegin,ColBegin,RowEnd,ColEnd,Distance1)
i:=0
for Index:=0 to 4 by 1
if(Distance1[Index]<0.4)
RowSelect[i]:=RowAfter[Index]
ColSelect[i]:=ColAfter[Index]
i:=i+1
endif
endfor
dev_set_color('green')
*筛选后的点再拟合直线
gen_contour_polygon_xld(Contour1,RowSelect,ColSelect)
fit_line_contour_xld(Contour1, 'tukey', -1, 0, 5, 2, RowBegin1, ColBegin1, RowEnd1, ColEnd1, Nr, Nc, Dist)
gen_contour_polygon_xld (ContourRet, [RowBegin1,RowEnd1], [ColBegin1,ColEnd1])
以上是关于Halcon拟合直线的主要内容,如果未能解决你的问题,请参考以下文章