欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Halcon学习——边缘提取

程序员文章站 2022-07-04 16:04:08
...

提取下图中的边缘

Halcon学习——边缘提取
提取方法:

*读入图片
read_image(Image,'D:/halcon/cicle.bmp')

*计算图片大小,并以原尺寸显示
get_image_size(Image,Width,Height)
dev_close_window()
dev_open_window_fit_size(0,0,Width,Width,-1, -1, WindowHandle)
dev_display(Image)

*设置ROI感兴趣区域
gen_rectangle1(ROI,50,50,470,470)
reduce_domain(Image,ROI,ImageReduced)

*二值化处理,并打散连接区域,选取目标区域
threshold(ImageReduced,Regions,23,255)
connection(Regions, ConnectedRegions)
select_shape(ConnectedRegions,SelectedRegions,'area','and',57706.4,86146.8)

*将目标区域进行膨胀处理
dilation_circle(SelectedRegions,RegionDilation,10)

*将目标区域进行腐蚀处理
erosion_circle(SelectedRegions,RegionErosion,4)

*填充孔洞
fill_up(RegionErosion, RegionFillUp)

*将膨胀后的区域和腐蚀后的区域进行减操作,并进行抠图处理,目的是为了得到有边缘的真实图像
difference(RegionDilation,RegionFillUp, RegionDifference)
union1(RegionDifference, RegionUnion)
reduce_domain(ImageReduced,RegionUnion,ImageReduced1)

*使用canny算子提取亚像素轮廓
edges_sub_pix(ImageReduced1,Edges,'canny',1,20,40)

*07. 根据得到的真实边缘,进步处理和计算所需的线、弧、圆等
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 2)
select_contours_xld (ContoursSplit, SelectedContours, 'contour_length', 8, 1000, -0.5, 0.5)
union_adjacent_contours_xld (SelectedContours, UnionContours3, 10, 1, 'attr_keep')
fit_circle_contour_xld (UnionContours3, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius1, StartPhi, EndPhi, PointOrder)
gen_circle (Circle, Row1, Column1, Radius1)

*显示结果
dev_set_line_width (2)
dev_set_draw ('margin')
dev_display (Image)
dev_display (Circle)

处理后的图片:
Halcon学习——边缘提取

相关标签: Halcon