Halcon案例之BLOB分析

 

æµè°æºå¨è§è§ä¹BLOBå¾åå¤çææ¯

Blob分析主要内容包括但不限于以下几点:

(1)图像分割:将图像中的目标和背景分离。

(2)去噪:消除或减弱噪声对目标的干扰。

(3)场景描述:对目标之间的拓扑关系进行描述。

(4)特征量计算:计算目标的2-D形状特征。

 

Blob分析的主要过程(常用套路):

获取图像->分割图像(区分前景像素和背景像素)->特征提取(比如面积、重心、旋转角度等)

 

参考:https://blog.csdn.net/Gavinmiaoc/article/details/79407685

* ball.hdev: Inspection of Ball Bonding
* 这个例子演示了如何找出 电路板上 那一排焊接点
dev_update_window ('off')
*把更新环境窗口关了
dev_close_window ()
dev_open_window (0, 0, 728, 512, 'black', WindowID)
read_image (Bond, 'die/die_03')
dev_display (Bond)
set_display_font (WindowID, 14, 'mono', 'true', 'false')
disp_continue_message (WindowID, 'black', 'true')
stop ()
threshold (Bond, Bright, 100, 255)
shape_trans (Bright, Die, 'rectangle2')
*形状选择,把某个区域转正外接矩形 区域
dev_set_color ('green')
dev_set_line_width (3)
dev_set_draw ('margin')
dev_display (Die)
*上面四步骤就是显示一下区域的边缘
disp_continue_message (WindowID, 'black', 'true')
stop ()
reduce_domain (Bond, Die, DieGrey)
*裁剪某个区域的图像
threshold (DieGrey, Wires, 0, 50)
fill_up_shape (Wires, WiresFilled, 'area', 1, 100)
*填充区域内的空洞
dev_display (Bond)
dev_set_draw ('fill')
dev_set_color ('red')
dev_display (WiresFilled)
disp_continue_message (WindowID, 'black', 'true')
stop ()
opening_circle (WiresFilled, Balls, 15.5)
*以半径为15.5的圆去做开运算,放得下这个圆的地方保留,放不下的去掉
dev_set_color ('green')
dev_display (Balls)
disp_continue_message (WindowID, 'black', 'true')
stop ()
connection (Balls, SingleBalls)
select_shape (SingleBalls, IntermediateBalls, 'circularity', 'and', 0.85, 1.0)
*以圆度筛选出上面那几个圆,筛选掉下面那个 开运算留下的噪声特征
sort_region (IntermediateBalls, FinalBalls, 'first_point', 'true', 'column')
*按照列排序
dev_display (Bond)
dev_set_colored (12)
dev_display (FinalBalls)
disp_continue_message (WindowID, 'black', 'true')
stop ()
smallest_circle (FinalBalls, Row, Column, Radius)
*算出七个区域的最小外接圆,圆心坐标 和半径
NumBalls := |Radius|
Diameter := 2 * Radius
meanDiameter := mean(Diameter)
minDiameter := min(Diameter)
dev_display (Bond)
disp_circle (WindowID, Row, Column, Radius)
dev_set_color ('white')
for i := 1 to NumBalls by 1
    if (fmod(i,2)==1)
      disp_message (WindowID, 'D: ' + Diameter[i-1]$'.4', 'image', Row[i-1] - 2 * Radius, Column, 'white', 'false')
    else
      disp_message (WindowID, 'D: ' + Diameter[i-1]$'.4', 'image', Row[i-1] - 42 * Radius, Column+32, 'red', 'false')
   
    endif
endfor

dev_update_window ('on')

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Halcon中的blob分析是一种图像分析方法,用于检测和分析图像中的连通区域。以下是Halconblob分析的基本流程: 1.采集图像并进行预处理,包括ROI(感兴趣区域)的定义、去噪、几何变换和拉开对比度等操作。 2.进行二值化处理,将像素根据灰度值范围分为两部分,这个灰度范围值叫做阈值。 3.进行形态学操作,包括膨胀、腐蚀、开运算和闭运算等,以去除噪声和填充空洞。 4.进行连通区域分析,检测和分析图像中的连通区域,包括计算区域的面积、周长、中心位置、最小外接矩形和最小外接圆等。 5.根据需要,可以进行形状分析、灰度分析和纹理分析等。 以下是一个Halconblob分析的例子: ```python import halcon as ha # 读取图像 image = ha.read_image('test.png') # 定义ROI roi = ha.gen_rectangle1(100, 100, 200, 200) # 对ROI内的图像进行二值化处理 threshold = 128 binary = ha.threshold(image, threshold, 255) # 对二值化图像进行形态学操作 selem = ha.gen_circle(5) binary = ha.dilation_circle(binary, selem) # 进行连通区域分析 regions = ha.connection(binary) # 计算区域的面积、周长、中心位置、最小外接矩形和最小外接圆等 area = ha.area_center(regions) perimeter = ha.perimeter(regions) row, col = ha.centroid(regions) rect = ha.smallest_rectangle2(regions) circle = ha.smallest_circle(regions) # 显示结果 ha.disp_obj(image, 'Original Image') ha.disp_obj(regions, 'Connected Regions') ha.disp_obj(rect, 'Smallest Rectangle') ha.disp_obj(circle, 'Smallest Circle') ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

往事如yan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值