搜档网
当前位置:搜档网 › Halcon测量长度

Halcon测量长度

dev_close_window()
read_image(Image,'C:/Users/dell/Desktop/halcon/Lenth.png')
dev_open_window_fit_image(Image, 0, 0, -1, -1, WindowHandle)
dev_display(Image)
access_channel(Image, Image3, 3)
dev_display(Image3)
median_rect(Image3, ImageMedian, 15, 15)
sub_image(Image3, ImageMedian, ImageSub, 7, 50)
threshold(ImageSub, Region, 88, 255)
connection(Region, ConnectedRegions)
select_shape(ConnectedRegions, SelectedRegions, 'area', 'and', 300, 2999)
union1(SelectedRegions, RegionUnion)
reduce_domain(Image3,RegionUnion, ImageReduced)

lines_gauss(ImageReduced, Lines, 1.5, 3, 8, 'light', 'true', 'bar-shaped', 'true')
dev_display(Image)
dev_display(Lines)

stop()
count_obj(Lines, Number)
for Index := 1 to Number by 1
select_obj(Lines, Line, Index)
length_xld(Line, Length)
convexity_xld(Line, Convexity)
if(Convexity>0.9 and Length>100)
break
endif
endfor
dev_set_color('green')
dev_display(Image)
dev_display(Line)
get_contour_xld(Line,Row, Col)
set_tposition(WindowHandle, min(Row)-20, min(Col))
write_string(WindowHandle, 'XLD Length= '+Length)

相关主题