You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Halcon中从含噪图像提取规整网格数据?

Halcon网格提取优化方案

1. 利用固定尺寸的形状模板匹配

因为网格大小固定,可先针对单个网格单元创建形状模板(create_shape_model),通过find_shape_model批量定位所有符合尺寸特征的网格单元,直接过滤掉不符合尺寸的噪点,即使矩形方向或图案有差异也能精准匹配。

2. 骨架提取+直线拟合重构网格

  • 用skeleton提取图像骨架,得到网格的线条框架
  • 通过gen_contours_skeleton_xld将骨架转换为XLD轮廓
  • 使用fit_line_contour_xld拟合直线,筛选出符合网格间距的直线段,最后用gen_region_line重新生成规整的网格线条

3. 优化形态学操作逻辑

摒弃单一的开闭运算组合,结合固定网格尺寸做针对性处理:

  • 执行closing_rectangle1时,将核尺寸设为网格单元的半尺寸,填补网格内部的小缺口
  • opening_rectangle1的核尺寸设为略小于网格间隙的数值,避免破坏网格结构
  • select_shape除了rectangularity,新增width、height的范围筛选(基于固定网格尺寸的上下浮动区间),精准过滤噪点

4. 区域生长+形状转换规整化

  • 先通过threshold得到初始二值区域
  • 用region_growing以固定网格尺寸为约束,合并相邻同色区域,填补网格断裂部分
  • 最后用shape_trans将区域转为'rectangle2',统一规整所有网格的形状

示例代码片段

// 假设GridWidth、GridHeight为已知固定网格尺寸,GridGap为网格间隙
closing_rectangle1 (Image, ImageClosing, GridWidth/2, GridHeight/2)
opening_rectangle1 (ImageClosing, ImageOpening, GridGap, GridGap)
threshold (ImageOpening, Regions, 128, 255)
select_shape (Regions, SelectedRegions, ['width','height','rectangularity'], 'and', [GridWidth*0.9, GridHeight*0.9, 0.8], [GridWidth*1.1, GridHeight*1.1, 1.0])
shape_trans (SelectedRegions, RectangularRegions, 'rectangle2')

内容的提问来源于stack exchange,提问作者Malinko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 09:15:44