1. 程式人生 > >Halcon擬合直線

Halcon擬合直線

nbsp lec end save [] cross use color rect

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擬合直線