跳到主要内容

步骤 2:对齐

时间: 10–15 分钟

对齐器是相机中最强大(也是最易被误解)的部分。一旦理解,它就会豁然开朗。让我们用简单的方式解释。

对齐的作用(以及为何需要它)

想象你在检测电路板上的螺丝。你已经在每个螺丝位置周围画了一个小框。但是当下一块板略微向左偏移,或旋转一度时,你的框就会对准错误的位置。

对齐器可以解决这个问题。 它会查看每张新图像,找出部件移动到了哪里,并将所有检查框相应地移动来匹配。就像有个助手在说“电路板向左移动了 3 像素并旋转了 0.5 度,让我把所有框移动以匹配。”

为何这很强大: 当检查框能够随着部件一同移动时,你可以让它们变得更小。更小的框需要更少的数据来训练 AI。这是一种连锁收益,始于良好的对齐。

工作原理:把它想象成一个拼图

对齐器通过边缘匹配来工作。可以这样简单地理解:

  1. 你拍摄一张“参考照片”(模板图像)表示一个完美的部件
  2. 你在这张照片上指向特定特征(角点、边缘、孔洞),这些在每个部件上看起来都相同
  3. 每次有新部件到来时,摄像头在新图像中找到这些相同的特征
  4. 它计算差异:“这个部件向左 5 像素、向上 2 像素,并倾斜 1.2 度”
  5. 它将所有检查框按恰好相同的量移动

这就像在玩配对游戏。摄像头找到你给它的特征,并将它们用作锚点。

对齐的黄金法则

将 2-3 个小模板区域尽可能放在部件上彼此远离

这一条规则将决定对齐是否能完美工作,还是会抖动让人沮丧。原因如下:

可以这样理解: 想象你在判断墙上的画框是否歪斜。

  • 仅看一个角时,可能会误以为它是直的,实际却是倾斜
  • 观察两个对角(左上角和右下角)时,可以立即判断是否歪斜,以及偏差量到底是多少

同样的原理也适用于对齐器。若部件的一侧只有一个区域,0.5 度的微小测量误差仍然是 0.5 度。但若在对侧放置两个区域,该误差将平均到约 0.05 度,精度提升十倍。

对齐器界面

以下是对齐器设置屏幕的外观。你将看到模板图像及带有颜色边缘高亮的参考特征:

对齐器工具,全页概览

分步设置

1. 捕捉模板图像

将一个高质量、无缺陷的部件放入摄像头视野中。该部件将成为未来所有部件比较的参考。

  • 部件应照明良好且边缘清晰
  • 确保表面清洁,无碎屑或异常标记
  • 将其放置成在生产中通常呈现的姿态

点击 捕捉模板图像

2. 添加模板区域

Click + Rectangle (or + Circle) to create a template region. You'll place 2-3 of these.

What to align to (features that never change):

  • Machined edges
  • Drilled holes
  • PCB outlines
  • Molded features
  • Stamped corners

What NOT to align to:

  • Textured or variable surfaces
  • Areas where defects might appear
  • Reflective spots that create glare
  • Tiny details that might not be visible in every image
  • Labels or markings that could move

3. 了解边缘高亮

When you place a template region, you'll see colored highlights:

Edge highlights and red dot reference point

  • Green highlights = Strong, usable edges detected. This is what you want.
  • Red highlights = Not enough edges. Move the region to a feature with clearer edges.
  • Red dot = The alignment reference point (center of all your inspection regions).

4. 使用 Ignore 工具清理嘈杂边缘

This step is overlooked by most people, and it makes a huge difference.

Click Ignore Template Region and paint over any edges you don't want the aligner to use. Remove:

  • Random background texture
  • Glare or reflections
  • Surface noise
  • Edges from debris or labels
  • Any edge that might change between parts
高灵敏度 + 强力清理 = 最佳效果

If you need more edges, increase the sensitivity slider. But the more you increase sensitivity, the more important it is to clean up the noise with the Ignore tool. Think of it as casting a wide net, then carefully picking out only the good fish.

Sensitivity slider

5. 设置旋转范围

Rotation range setting

This controls how much rotation the aligner will search for:

  • ±180°: Find the part at any rotation (full 360). Best for most applications.
  • ±5-20°: Only match if the part is roughly in the expected orientation
  • ±0°: Exact angle match only
Use rotation as a quality gate

If you set a narrow range like ±5° and a part comes in rotated 10°, the aligner won't match it, and you can use this failure as a reject signal. Handy for catching parts that aren't properly oriented.

6. 设置置信度阈值

Confidence threshold setting

How confident the aligner needs to be that it found the right match:

  • Range: 0.0 to 1.0 (lower percentage = stricter match)
  • Recommended: 0.6 to 0.9
  • Too high → may miss valid parts. Too low → may match wrong features.

7. 启用 Scale Invariant(如有需要)

If your part can be ±10% closer or farther from the camera (height variation on a conveyor, for example), enable this. Otherwise, leave it off for maximum speed.

8. 保存并测试

这是最重要的步骤。 不要跳过测试。

  1. 点击 保存。这将训练并部署对齐器。
  2. 点击 实时预览模式
  3. 将部件在左、右、上、下移动
  4. 在您预期的范围内旋转它
  5. 将部件放置在画面四角
  6. 尝试不同的有效部件
  7. 尝试让它失败。 找出它失败的位置。

If the alignment doesn't track reliably, fix it now. If you move on and spend time setting up inspection regions and training AI, then discover the alignment is unreliable, you'll have to come back and redo everything. That's the瀑布式流程.

2D 限制(重要信息)

对齐器仅在 2D 工作:摄像头所看到的平坦平面。它支持:

  • 左右移动
  • 上下移动
  • 旋转(在平面上旋转)
  • 尺寸的轻微变化(若 Scale Invariant 开启)

它不处理:

  • 变形或弯曲的工件
  • 相对于摄像头向前或向后倾斜的工件
  • 任何 3D 变形

如果你的工件存在 3D 变形(其中一面比另一面更贴近摄像头),请完全跳过对齐器,并改用具备 location-invariant training 的 segmenter。

何时跳过对齐器

你仍然需要捕捉模板图像(系统要求),但在以下情况下可以切换 Skip Aligner

  • 你的工件放在精密夹具中,移动小于 1-2 像素
  • 你正在使用能保证精确定位的机械配准
  • 你正在使用不需要位置跟踪的 segmenter

快速参考

设置推荐值在何时调整
模板区域2-3 个模板区域,尽量分布在工件两端尽可能远的位置对齐抖动 → 添加区域并将它们分散开
灵敏度能在你的特征上呈现稳定绿色的最低灵敏度边缘不足(红色) → 提高灵敏度,然后清理噪声
旋转范围大多数应用的范围为 ±180°工件进入时朝向已知 → 缩小范围
置信度0.6-0.9匹配错误 → 提高;遗漏有效工件 → 降低
Scale invariant除非需要,否则关闭工件距离摄像头距离变化时 → 启用

对齐故障排查

常见对齐问题及解决方法
问题可能原因解决方法
ROIs 不随工件移动Skip Aligner 已开启,或无模板区域禁用 Skip;添加模板区域
对齐来回抖动单一区域,或区域之间距离过近在对立两侧添加 2-3 个远距离区域
置信度接近 0%区域内无可用边缘将区域移至具有强、清晰边缘的特征
匹配到错误的对象特征不够唯一,阈值过低选择更具辨识度的特征;提高置信度阈值
在某些部件正常,在其他部件失败区域放置在不同部件之间变化的特征上将区域移动到通用特征(加工边缘、孔)

对齐检查清单

在继续之前,请确认:

  • 从良好且无缺陷的工件捕获模板图像
  • 在强大且稳定的特征上放置 2-3 个模板区域
  • 区域在工件上尽可能分布在最远的位置
  • 使用 Ignore 工具清理嘈杂边缘
  • 已设置旋转范围和置信度阈值
  • 已测试 Live Preview;对齐在所有位置跟踪工件

对齐运行良好?前往 Step 3: Inspection Regions.