跳到主要内容

AI 驱动文档

您想了解什么?

训练 Segmenter

本指南向您展示如何设置和配置 OV20i segmentation 功能,以自动检测、测量和分析零件上的特定特征或缺陷。当需要识别不规则形状、测量面积或检测无法通过简单分类处理的特征模式时,请使用 segmentation。

视频指南

请观看本主题的实际演示: How to create a segmentation recipe in minutes

备注

OV10i 不具备 segmentation 功能。

何时使用 Segmentation: 需要像素级精度的特征检测时,例如表面缺陷、液体溢出、 irregular shapes、面积测量、模式检测等。

开始之前

需要准备的材料

  • OV20i 摄像系统已设置并连接
  • 带有要进行 segmentation 的特征的测试件(例如带铅笔痕迹的薄片)
  • 适用于您具体应用的良好照明条件
  • 用于训练的 15–20 张样本图像

步骤 1:创建 Segmentation Recipe

1.1 启动新的 Recipe

  1. 导航到 All Recipes 页面
  2. 点击 + New Recipe(右上角)

New Recipe button

  1. 输入 Recipe 名称: 使用描述性名称,例如 "Pencil_Mark_Detection" 或 "Surface_Defect_Segmentation"
  2. 选择 Recipe Type: 从下拉列表中选择 "Segmentation"
  3. 点击 OK 以创建

1.2 激活 Recipe

  1. 在列表中找到您的配方(显示为 "Inactive")
  2. 点击 Activate
  3. 点击 Activate and go to editor 以进行确认并启动配方编辑器

Activate recipe button

结果: 配方现已处于 "Active" 状态,且显示了 Recipe Editor。

步骤 2:配置相机设置

2.1 打开 Imaging 配置

  1. 点击 Configure Imaging(左下角)

Configure Image

2.2 优化 Segmentation 的焦点

焦点对精确边缘检测至关重要:

  1. 将测试件置于相机视图中
  2. 调整焦点,直到边缘清晰锐利
  3. 对不同的件进行测试,以确保在整个量程内焦点一致
提示
  • 将缺陷/特征将出现在的表面作为焦点
  • 确保感兴趣区域的整个区域处于清晰焦点
  • 对 segmentation,略微过锐优于软焦

2.3 设置最佳曝光

正确曝光可确保一致的特征检测:

  1. 调整曝光以获得均衡照明
  2. 避免过曝区域(纯白区域)
  3. 确保特征在良好对比度下可见

Segmentation 曝光指南:

  • 特征应与背景具有清晰对比
  • 避免可能被误认为缺陷的阴影
  • 在不同的零件条件下测试(干净、脏污、磨损)

2.4 配置 LED 照明模式

基于要进行 segmentation 的对象选择照明:

特征类型推荐照明原因
表面缺陷明场照明均匀照明可显示表面不规则性
划痕/裂纹侧光产生阴影,突出线性缺陷
凸起特征暗场使凸起区域从背景中突出
液体溢出侧光显示表面纹理差异

2.5 调整 Gamma 以增强特征对比

  1. 增大 Gamma 值 以提升特征与背景之间的对比度
  2. 在查看目标特征时测试不同的 Gamma 值
  3. 找到能让特征最易区分的设置

2.6 保存配置

  1. 在实时预览中检查设置
  2. 点击 Save Imaging Settings

Save Settings

检查点: 功能应在良好对比度下清晰可见。

Step 3: Set Up Template and Alignment

3.1 Navigate to Template Section

Click "Template Image and Alignment" in breadcrumb menu

3.2 Configure Alignment (Optional)

Template and alignment

For this example, we'll skip alignment:

  1. Select Skip Aligner if parts are consistently positioned
  2. Click Save

Template image

When to Use Aligner: Enable when parts arrive in varying positions or orientations that would affect segmentation accuracy.

Step 4: Define Inspection Region

4.1 Navigate to Inspection Setup

Click "Inspection Setup" in breadcrumb menu

4.2 Set Region of Interest (ROI)

The ROI defines where segmentation will occur:

  1. Position a test part in camera view
  2. Drag ROI corners to frame the inspection area
  3. Size ROI appropriately:
    • Include all areas where features might appear
    • Exclude unnecessary background regions
    • Leave small buffer around expected feature locations

ROI Setup

4.3 ROI Best Practices for Segmentation

应执行不应执行
覆盖整个检查表面包含无关背景对象
在边缘周围留出缓冲区将 ROI 设置得过小以致特征变化无法捕捉
考虑部件定位的变化与夹具或治具重叠
使用最大预期特征进行测试包含带永久标记的区域

4.4 Save ROI Settings

  1. Verify ROI covers all target areas
  2. Click Save

Step 5: Label Training Data

5.1 Navigate to Label And Train

Click "Label And Train" in breadcrumb menu

5.2 Configure Inspection Class

  1. Click Edit under Inspection Types
  2. Rename class to match your feature (e.g., "Pencil Mark", "Surface Defect", "Spill Area")
  3. Choose class color for visual identification
  4. Save changes

5.3 Capture and Label Training Images

You need minimum 10 labeled images, but 15-20 is recommended:

Image Capture Process

Label and Train

  1. Place first test part in inspection area
  2. Take image using camera interface
  3. Use Brush tool to paint over target features
  4. Paint accurately:
    • Cover entire feature area
    • Stay within feature boundaries
    • Don't paint background areas
    • Use consistent labeling approach
  5. Click Save Annotations
  6. Repeat with next part

标注最佳实践

良好标注差标注
精准的特征边界边缘涂抹不清晰
特征定义的一致性标准不一致
完整的特征覆盖缺少特征区域
背景干净(未着色)背景意外着色

5.4 训练数据多样性

确保你的训练集包括:

  • 不同的特征尺寸
  • 不同的特征强度
  • ROI 内的多个位置
  • 不同的照明条件(如适用)
  • 边界情况和临界示例

5.5 训练数据质量检查

  1. 检查所有标注图像
  2. 验证标注方法的一致性
  3. 移除任何错误标注的样本
  4. 如有需要,添加更多样本

第6步:训练分割模型

6.1 启动训练过程

  1. 在完成标注时点击 Return to Live
  2. 点击 Train Segmentation Model

开始训练

6.2 配置训练参数

  1. 设置迭代次数:
    • 快速训练: 50-100 次迭代(5-10 分钟)
    • 生产级质量: 200-500 次迭代(15-30 分钟)
    • 高精度: 500 次及以上迭代(30 分钟以上)
  2. 点击 Start Training

6.3 监控训练进度

训练进度显示:

  • 当前迭代次数
  • 训练准确率百分比
  • 估计完成时间

训练进度

训练控制:

  • 中止训练: 遇到问题时停止
  • 提前结束训练: 当达到足够的准确度时停止

Training 2

提示
  • 85% 的准确度通常适用于生产
  • 训练在达到目标准确度后自动停止
  • 通常,更多的训练数据往往比更多的迭代次数更有帮助

第7步:测试分割性能

7.1 进入实时预览

  1. 在训练完成后点击 Live Preview
  2. 使用不同部件进行测试:
    • 已知良品部件(应显示无/极少分割)
    • 已知缺陷部件(应突出显示缺陷)
    • 边界情况和临界示例

实时预览

7.2 评估结果

检查分割质量:

指标良好表现需要改进
准确度能稳定发现真实特征容易遗漏明显特征
精度很少误报背景区域被高亮的情况较多
边缘质量边界干净、准确边缘粗糙或不准确
一致性重复测试结果相似结果高度可变

7.3 处理不良结果

问题可能原因解决方案
缺少特征训练数据不足添加更多带标注的样本
误报照明/对比度差改善成像设置
边缘粗糙图像质量差提高对焦/照明
结果不一致训练多样性不足添加更多多样化样本

第 8 步:配置通过/失败逻辑

8.1 访问 IO Block

  1. 确保 AI 模型显示为绿色(已训练状态)
  2. 通过面包屑导航进入 IO Block

8.2 删除默认逻辑

  1. 删除 Classification Block Logic 节点
  2. 准备构建自定义分割逻辑

8.3 构建分割流程

使用以下组件创建 Node-RED 流:

  1. 从左侧面板拖拽节点:
    • Function 节点(用于逻辑)
    • Debug 节点(用于测试)
    • 最终的 Pass/Fail 节点
  2. 用连线将节点连接

NodeRed

8.4 根据需要配置逻辑

选项 A:若未检测到缺陷则通过

用例: 质量检测中,检测到的任何特征均视为不合格

Function Node Code:

const allBlobs = msg.payload.segmentation.blobs;
const results = allBlobs.length <1; // Pass if no features found
msg.payload = results;
return msg;

选项 B:仅对较小的缺陷通过

用例: 接受低于阈值大小的次要缺陷

Function Node Code:

const threshold = 500; // Adjust pixel count threshold
const allBlobs = msg.payload.segmentation.blobs;
const allUnderThreshold = allBlobs.every(blob => blob.pixel_count < threshold);
msg.payload = allUnderThreshold;
return msg;

选项 C:若总缺陷面积较小则通过

用例: 接受总缺陷面积受限的零件

Function Node Code:

const threshold = 5000; // Adjust total pixel threshold
const allBlobs = msg.payload.segmentation.blobs;
const totalArea = allBlobs.reduce((sum, blob) => sum + blob.pixel_count, 0);
msg.payload = totalArea < threshold;
return msg;

8.5 配置 Function Node

  1. 双击 Function 节点
  2. 从上述示例中复制相应代码
  3. 粘贴到 “On Message” 标签页
  4. 为您的应用调整阈值
  5. 点击 Done

8.6 部署并测试逻辑

  1. 点击 Deploy 以激活逻辑
  2. 导航到 HMI 进行测试
  3. 使用已知良品和不良品进行测试
  4. 验证通过/失败结果是否符合预期

第 9 步:生产验证

9.1 全面测试

对分割系统进行以下测试:

测试用例预期结果失败时的处理
干净零件通过(无分割)调整阈值或重新训练
次要缺陷按您的标准通过/失败精细调整逻辑参数
重大缺陷失败(分割清晰)检查模型精度
边缘情况行为一致增加训练数据

9.2 性能验证

监控以下指标:

  • 每次检测的处理时间
  • 多次测试的一致性
  • 在生产光照下的准确性
  • 长时间运行的可靠性

9.3 最终调整

若性能不令人满意:

  1. 为边缘情况添加更多训练数据
  2. 在逻辑中调整阈值
  3. 改善成像条件
  4. 使用额外迭代重新训练模型

成功!您的分割系统已就绪

您现在拥有一个可工作的分割系统,能够:

  • 自动检测特定特征或缺陷
  • 以像素级精度测量面积
  • 根据您的要求应用自定义通过/失败逻辑
  • 通过 I/O 控制与生产系统集成

高级配置选项

自定义阈值逻辑

对于复杂的验收条件,将多个条件结合起来:

const smallThreshold = 200;
const largeThreshold = 1000;
const maxTotalArea = 3000;

const allBlobs = msg.payload.segmentation.blobs;
const smallBlobs = allBlobs.filter(blob => blob.pixel_count < smallThreshold);
const largeBlobs = allBlobs.filter(blob => blob.pixel_count > largeThreshold);
const totalArea = allBlobs.reduce((sum, blob) => sum + blob.pixel_c