【Halcon】Blob分析的形态学算子应用(count_pellets.hdev)

Halcon中 Blob分析 之count_pellets.hdev 示例



* This programs demonstrates the use of basic morphology
* operators.
* The aim of the program is to detect each single pellet
* (bright particle on a darker background).
* 
*把程序窗口、变量窗口、显示窗体变为off状态
dev_update_off () 
*读取图片
read_image (Image, 'pellets')
*关闭显示窗口
dev_close_window ()
*获取图片的宽高
get_image_size (Image, Width, Height)
*打开一个新的带有所给图像纵横比图像窗口
dev_open_window (0, 0, Width, Height, 'black', WindowID)
*修改图像显示的位置
dev_set_part (0, 0, Height-1, Width-1)
*设置窗口文字显示格式
set_display_font (WindowID, 16, 'mono', 'true', 'false')
*指定颜色
dev_set_colored (6)
*显示的对象只有边缘线
dev_set_draw ('margin')
*指定线宽度
dev_set_line_width (3)
*显示图片
dev_display (Image)

* Segment the regions of the pellets from the background
*自动确定阈值  Region:黑暗的区域的图像
bin_threshold (Image, DarkRegion)
*填充满足给定的图形特征的区域
fill_up_shape (DarkRegion, RegionFillUp, 'area', 1, 10)
*计算两个区域的不同,并返回 
difference (Image, RegionFillUp, Region)
*显示区域
dev_display (Region)
stop ()
* 
* Compute the connected pellet regions
* Note, that this approach fails, because some of
* the pellets are still connected.
*合并所有选定像素触摸相互连通区
connection (Region, ConnectedRegionsWrong)
*显示图片
dev_display (Image)
*显示图片
dev_display (ConnectedRegionsWrong)
stop ()
* 
* Separate each pellet from the others by erosion
*用一个圆形的结构元素腐蚀图像
erosion_circle (Region, RegionErosion, 7.5)
*显示区域
dev_display (RegionErosion)
stop ()
* 
* Now, compute the connected pellet regions
*合并所有选定像素触摸相互连通区
connection (RegionErosion, ConnectedRegions)
*显示图像
dev_display (ConnectedRegions)
stop ()
* 
* Turn back to the original pellet size by applying a dilation
*用一个圆形的结构元素膨胀图像
dilation_circle (ConnectedRegions, RegionDilation, 7.5)
*主要是用来计算被识别出来的区域的个数
count_obj (RegionDilation, Number)
*显示图像
dev_display (Image)
*显示图像
dev_display (RegionDilation)
*显示文字信息
disp_message (WindowID, Number + ' pellets detected', 'window', 12, 12, 'black', 'true')


     

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值