使用 Segmenter
本教程将引导您利用 OV80i 的 AI 驱动 Segmentation 功能,创建一次完整的 Segmentation 检测流程。您将学习如何通过教摄像机逐像素识别并测量这些特征,以检测和分析铅笔痕迹、划痕或其他缺陷。
你将学到:
- 如何从头到尾设置 Segmentation 配方
- 如何训练 AI 模型以识别特定特征
- 如何基于 Segmentation 结果配置 通过/不通过 逻辑
- 如何在生产环境中优化 Segmentation 的性能
现实世界应用: 这个教程以铅笔痕迹检测为示例,但相同的原理同样适用于检测划痕、裂纹、污染,或任何可通过视觉区分的特征。
先决条件
- OV80i 摄像头系统已设定并连接
- 具有你想要检测的特征的样本部件(例如带铅笔痕迹的纸张)
- AI 训练概念的基础理解
- 访问 Recipe Editor 和 Node-RED 功能
教程概览
我们将构建: 一个 Segmentation 模型,能够检测纸张上的铅笔痕迹,并依据检测到的标记量来判定合格/不合格。
所需时间: 45-60 分钟(含训练时间)
所学技能: AI 模型训练、Segmentation 标注、通过/不通过逻辑配置
第 1 步:创建新的 Segmentation 配方
1.1 启动一个新的 Segmentation 配方
- 在 所有配方 页面,点击右上角的 “+ 新建配方”
- 将出现 Add A New Recipe 对话框
- 为您的配方输入一个描述性 名称(例如 "Pencil_Mark_Detection")
- 从下拉菜单中选择 "Segmentation" 作为 Recipe Type
- 点击 "OK" 以创建新配方
为什么选择 Segmentation? 与识别整个对象的分类不同,Segmentation 会在图像中定位并测量特定特征,非常适用于缺陷检测、污染分析,或测量覆盖区域。
1.2 启用您的配方
- 您新建的配方将在 All Recipes 页面显示为未激活
- 在配方右侧选择 “操作 > 启用”
- 点击 "启用" 以确认
- 配方状态将变为 已激活
1.3 进入配方编辑器
- 点击活动配方旁的 "编辑"
- 点击 "打开编辑器" 以确认
- 您现在将进入包含您分段配方的 Recipe Editor
检查点: 您应在面包屑导航中看到带有 Segmentation 配方名称的 Recipe Editor 界面。
第 2 步:配置相机成像
2.1 访问成像设置
- 在 Recipe Editor 中,点击左下角的 "Configure Imaging"
- 这将打开成像配置页面,您将在此处优化相机设置
2.2 优化聚焦设置
- 将带有铅笔标记的样张放入摄像头的视野中
- 使用 Focus slider 以实现铅笔标记的清晰聚焦
- 也可以手动输入对焦值以提高精度
- 如有可用,请使用 Focus View 以查看边缘高亮和对焦分数
Focus Tips:
- 将焦点放在缺陷将出现的表面
- 确保铅笔标记清晰且定义明确
- 更高的对焦分数表示更好的对焦质量
2.3 配置曝光设置
- 调整 Exposure 滑块以实现合适的亮度
- 铅笔标记应清晰可见,且纸张不过曝
- 先使用自动设置,必要时再进行微调
- 监控实时预览,以查看实时变化
Exposure Guidelines:
- 铅笔标记应与纸张具有良好的对比度
- 避免过曝以致模糊微小标记
- 确保整个检测区域的照明一致
2.4 设置 LED 照明
- 选择适合您应用的 LED Light Pattern
- 对铅笔标记而言,均匀照明通常效果最佳
- 调整 LED Light Intensity 以最小化阴影和眩光
- 如有反射问题,测试不同的模式
2.5 调整 Gamma 与对比度
- 微调 Gamma 以增强标记与背景之间的对比度
- 较高的 Gamma 可以让微小的铅笔标记更清晰
- 较低的 Gamma 可以降低干净区域的噪声
- 调整 Gamma 以同时优化缺陷可见性与背景清晰度
2.6 保存成像设置
- 当所有设置优化完毕后,点击 "Save Imaging Settings"
- 您的摄像机配置现已保存到此配方
- 实时预览应显示清晰、对比度良好的图像
Checkpoint: 相机应生成清晰的图像,铅笔标记应与纸张背景易于区分。
第 3 步:配置模板与对齐
3.1 导航至 模板图像与对齐
- 在面包屑导航中点击 Recipe Name 以返回到 Recipe Editor
- 从菜单中选择 "Template Image and Alignment"
3.2 在本教程中跳过对齐器
- 由于我们要在整张纸上检测特征,请单击 "Skip Aligner"
- 这会禁用基于位置的对齐并使用全图像
- 点击 "Save" 来应用更改
何时使用 Aligner: 当您需要在可能移动或旋转的部件上特定位置检测特征时,请启用对齐器。对于像铅笔标记这样需要整张纸检测的情况,通常应跳过对齐器。
第 4 步:设置检测区域
4.1 导航至 检测设置
- 返回到 Recipe Editor,并选择 "Inspection Setup"
- 这里您将定义要分析的图像区域
4.2 配置感兴趣区域(ROI)
- 您将看到摄像头视野的预览
- 拖动 ROI 框的四个角 以调整其大小和位置
- 对铅笔标记检测,通常覆盖整张纸区域
- 确保 ROI 覆盖铅笔标记可能出现的所有区域
ROI 最佳实践:
- 包含可能出现缺陷的所有区域
- 排除边缘或背景等不应分析的区域
- 将 ROI 调整到足以捕捉部件定位变化的大小
- 避免包含文本、标识或其他预期标记
4.3 保存 ROI 配置
-
当您的 ROI 已正确定位后,点击 "保存"
-
检测区域现已为您的分割模型定义完毕
Step 5: Label and Train Your Model
5.1 Navigate to Label and Train
-
返回 Recipe Editor 并选择 "Label and Train"
-
这是你将教 AI 如何识别 pencil marks 的地方
5.2 Configure Inspection Class
-
Under Inspection Types, click "Edit"
-
Rename the class to "Pencil Mark" (or your specific defect type)
-
Choose a distinctive color for visualizing detected marks
-
Click "Save" to apply the changes
5.3 Capture Training Images
-
Take at least 10 images of sheets with different pencil markings
-
Vary the training examples:
- Different pencil mark sizes and shapes
- Light and dark marks
- Various positions on the sheet
- Different mark densities
Training Image Tips:
- Include both subtle and obvious marks
- Capture various lighting conditions you'll encounter
- Include clean areas without marks in each image
- Ensure images represent production conditions
5.4 Annotate Training Images
-
For each training image, use the Brush tool to trace over pencil marks
-
Paint only the pencil marks - avoid marking paper or other features
-
Be precise but thorough in your annotations
-
Click "Save Annotations" after completing each image
Annotation Best Practices:
- Be consistent in what you label as "pencil marks"
- Include complete marks, not just parts of them
- Don't label expected markings like text or logos
- Use steady, careful brush strokes for accurate boundaries
5.5 Review Your Annotations
-
Double-check all labeled images to ensure accuracy
-
Look for missed marks or incorrectly labeled areas
-
Re-annotate any images that need correction
-
Quality annotations lead to better model performance
Step 6: Train the Segmentation Model
6.1 Start Training Process
-
Once you've labeled at least 10 images, click "Return to Live"
-
Click "Train Segmentation Model"
-
Enter the Number of Iterations for training
Iteration Guidelines:
- Start with 100-200 iterations for initial training
- More iterations generally improve accuracy but take longer
- Monitor training progress and adjust as needed
- Balance accuracy requirements with training time
6.2 Monitor Training Progress
-
Click "Start Training" to begin the process
-
A training progress modal will appear showing:
- Current iteration number
- Training accuracy percentage
- Estimated time remaining
6.3 Training Control Options
During training, you can:
- Abort Training - Stop if you need to make changes
- Finish Training Early - Stop when accuracy is sufficient
- Monitor Progress - Watch accuracy improve over iterations
Training Tips:
- Training will automatically finish when target accuracy is reached
- Higher accuracy percentages indicate better model performance
- If accuracy plateaus, you may need more training data
6.4 评估训练结果
- 当训练完成后,查看最终准确度
- 单击 "Live Preview" 以查看实时分割结果
- 使用新样本进行测试以验证模型性能
成功指标:
- 铅笔标记以您选择的颜色高亮显示
- 未标记的干净区域保持不变
- 对不同标记类型的检测保持一致
- 模型对新样本(未见样本)的响应良好
Step 7: 配置通过/失败逻辑
7.1 导航至 IO Block
- 返回到 Recipe Editor 并选择 "IO Block"
- 确保所有 AI Blocks 显示为 "trained (green)" 然后再继续
- 单击 "Configure I/O" 进入 Node-RED 编辑器
7.2 设置 Node-RED Flow
- Delete the existing Classification Block Logic 节点
- 从左侧调色板拖入:
- All Block Outputs 节点(若尚未存在)
- Function 节点
- Final Pass/Fail 节点
- 连接节点:All Block Outputs → Function → Final Pass/Fail
7.3 配置通过/失败逻辑
双击 Function 节点并从以下逻辑示例中选择一个:
选项 1:若未检测到缺陷则通过
// Pass if no pencil marks are found
const allBlobs = msg.payload.segmentation.blobs;
const results = allBlobs.length <1;
msg.payload = results;
return msg;
选项 2:若所有标记均较小则通过
// Pass if all marks are smaller than threshold
const threshold = 500; // pixels
const allBlobs = msg.payload.segmentation.blobs;
const allUnderThreshold = allBlobs.every(blob => blob.pixel_count < threshold);
msg.payload = allUnderThreshold;
return msg;
选项 3:若总覆盖率较低则通过
// Pass if total marked area is below threshold
const threshold = 5000; // total pixels
const allBlobs = msg.payload.segmentation.blobs;
const totalArea = allBlobs.reduce((sum, blob) => sum + blob.pixel_count, 0);
msg.payload = totalArea < threshold;
return msg;
7.4 部署并测试逻辑
- 单击 "Done" 以保存函数
- 单击 "Deploy" 以激活逻辑
- 转到 HMI 以测试您的通过/失败逻辑
测试您的逻辑:
- 使用干净的表面进行测试(应通过)
- 使用轻微标记的表面进行测试(应按您的标准通过/失败)
- 使用标记较重的表面进行测试(应失败)
- 验证结果与您的预期一致
Step 8: 优化与验证
8.1 使用生产样本进行测试
- 对检测进行多次测试样本的处理
- 验证检测准确度是否符合您的要求
- 检查通过/失败逻辑是否正确工作
- 记录任何问题或边缘情况
8.2 微调模型性能
如果检测不一致:
- 添加更多具有不同示例的训练图像
- 提升标注质量和一致性
- 调整成像设置以获得更好的对比度
- 使用更多迭代重新训练
如果通过/失败逻辑需要调整:
- 修改 Node-RED 函数中的阈值
- 测试不同的逻辑方法
- 考虑用于复杂决策的多重条件
- 以生产要求进行验证
8.3 生产验证
- 在实际条件下使用真实生产部件进行测试
- 与质量团队共同验证,以确保标准符合要求
- 记录性能指标,如检测准确性和误报率
- 建立监控,以随时间跟踪性能
第 9 步:理解 Segmentation 结果
9.1 Segmentation Data Structure
您的 Segmentation 结果包括:
- Blobs:检测到的单个特征(pencil marks,铅笔痕迹)
- Pixel Count:每个检测特征的大小
- Location Data:特征的发现位置
- Confidence Scores:模型对每个检测的置信度
9.2 使用 Segmentation Data
您可以基于以下指标创建复杂的通过/不通过逻辑:
- Number of defects 检测到的缺陷数量
- Size of individual defects(像素计数)单个缺陷的大小
- Total defect area(所有像素计数的总和)总缺陷面积
- Defect location(缺陷出现的位置)缺陷位置
- Defect shape characteristics(如用于高级应用)缺陷形状特征
成功!您的 Segmentation 模型已完成
您的 OV80i segmentation inspection 现在可以:
✅ Automatically detect pencil marks(或您特定的特征)在图像中自动检测
✅ Measure the size and quantity of detected features 在检测到的特征上测量其大小和数量
✅ Make pass/fail decisions 基于您具体的标准
✅ Provide detailed information 关于每个检测到的特征
✅ Adapt to variations 在标记大小、形状和位置的变化中保持适应性
关键要点
Segmentation vs. Classification:
- Segmentation 在图像中查找并测量特定特征
- Classification 确认整个对象或总体条件
- 使用 Segmentation 进行缺陷检测、污染分析或覆盖度测量
Training Best Practices:
- 高质量标注比数量更重要
- 在训练集中包含多样化示例
- 对生产样本进行彻底测试
- 持续监控并在需要时重新训练
Pass/Fail Logic:
- 从简单标准开始,按需增加复杂性
- 使用边界情况和临界样本测试逻辑
- 记录您的标准以保持一致性
- 考虑多因素以做出更稳健的决策
下一步
现在您已经完成了首个 segmentation 模型:
- Apply to other use cases - 尝试检测不同类型的缺陷或特征
- Integrate with production systems - 将其与 PLCs 或质量管理系统连接
- Set up data collection - 跟踪性能指标和检测统计
- Train operators - 确保团队了解如何监控和维护系统
- Plan maintenance - 安排定期模型更新和性能评估