[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')


[Halcon] Blob分析的形态学算子应用(count_pellets.hdev)_第1张图片   [Halcon] Blob分析的形态学算子应用(count_pellets.hdev)_第2张图片 [Halcon] Blob分析的形态学算子应用(count_pellets.hdev)_第3张图片   [Halcon] Blob分析的形态学算子应用(count_pellets.hdev)_第4张图片

你可能感兴趣的:([Halcon] Blob分析的形态学算子应用(count_pellets.hdev))