【图像处理】 Halcon 实现亚像素边缘检测
作者:互联网
目录
1 Halcon软件使用简要指导
halcon的函数调用,返回值变量在()参数中去定义,比如我要初始化一个用Test(A,B)函数实现某个功能,A 是传入的参数,B是返回值参数。
3 实现
边缘检测,轮廓拟合,并对轮廓进行彩色绘图
*读取图片
read_image (Image, 'Pic1_1.bmp')
* 关闭窗口
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
*
* Segment a region containing the edges
*基于全局阈值的图像快速阈值化
fast_threshold (Image, Region, 0, 120, 7)
*获取一个边界区域
boundary (Region, RegionBorder, 'inner')
*用圆形结构元素扩张一个区域。
dilation_circle (RegionBorder, RegionDilation, 3.5)
*获得特定区域Region位置的图像
reduce_domain (Image, RegionDilation, ImageReduced)
*
* In the subdomain of the image containing the edges,
* extract subpixel precise edges.
*提取亚像素精密边缘轮廓
edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
*将一个XLD轮廓分割为直线段、圆(圆弧)、椭圆弧
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 3)
* dev_display (Edges)
*计算个数
count_obj (ContoursSplit, Number)
dev_display (Image)
*定义region填充模式
dev_set_draw ('margin')
dev_set_color ('white')
dev_update_window ('off')
for I := 1 to Number by 1
*选择一个元素
select_obj (ContoursSplit, ObjectSelected, I)
*返回XLD轮廓的全局属性值
get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
* Fit a circle to the line segment that are arcs of a circle
if (Attrib > 0)
*用圆近似XLD轮廓
fit_circle_contour_xld (ObjectSelected, 'ahuber', -1, 2, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
*创建对应于圆或圆弧的XLD轮廓
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, rad(360), 'positive', 1.0)
endif
endfor
dev_set_colored (12)
dev_set_line_width (3)
dev_display (ContoursSplit)
检测效果如下
标签:轮廓,set,Image,xld,dev,像素,图像处理,circle,Halcon 来源: https://blog.csdn.net/weixin_43935696/article/details/121624756