您当前的位置: 首页 >  图像处理

Better Bench

暂无认证

  • 2浏览

    0关注

    695博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【图像处理】 Halcon 实现图像亚像素边缘检测

Better Bench 发布时间:2021-11-30 09:20:03 ,浏览量:2

目录
  • 相关链接
  • 1 Halcon软件使用简要指导
  • 3 实现

相关链接

(1)【2021 亚太杯数学建模】赛题A-Image Edge Analysis and application图像边缘分析与应用 赛题思路解析及实现 (2)代码看这儿:betterbench.top/#/46/detail 请添加图片描述

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)

检测效果如下 在这里插入图片描述

关注
打赏
1665674626
查看更多评论
立即登录/注册

微信扫码登录

0.0377s