机器视觉20 齿轮缺角 引脚缺失 液位高度 图像去噪

1.案例  齿轮缺角

1.预留图形预处理工具

1.边缘提取工具

利用copyRegin工具 实现 齿轮环 分割效果 为blob分析 齿轮缺失做准备

1和2 把 blob中的灰度图添加到 copyRegin的俩个图像输入参数中

3.把blob匹配结果中心坐标给copyRegin 匹配区域坐标

4.设置填充数值  128   目的  为了 使填充的区域灰度值和 目标图像背景灰度值 一致

5.填充区域设置

6.区域外 调整像素 调整为 不写入像素 

 1.勾选使用图像配对

1.运行

2.运行后最终效果    (此 图效果  可以清晰的匹配 每个齿轮)

1.使用blob工具

2.设置参数

3.匹配效果图根据blob分析的结果数 来判断是否 缺失齿轮

#region namespace imports
using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro3D;
using Cognex.VisionPro.ImageProcessing;
using Cognex.VisionPro.PMAlign;
using Cognex.VisionPro.Blob;
#endregion

public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{
  #region Private Member Variables
  private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
  #endregion
 
  //定义图形集合
  CogGraphicLabel label = new CogGraphicLabel();
 
  public override bool GroupRun(ref string message, ref CogToolResultConstants result)
  {

      
    
    int count = (int)mToolBlock.Inputs["Count"].Value;
    CogBlobTool blob = mToolBlock.Tools["CogBlobTool2"] as CogBlobTool;


    // Run each tool using the RunTool function
    foreach(ICogTool tool in mToolBlock.Tools)
      mToolBlock.RunTool(tool, ref message, ref result);
    
    //获取blob结果个数
    int currentCount = blob.Results.GetBlobs().Count;
    //获取齿轮差值
    int diff = count - currentCount;
    
       
    string res = "";
    label.Color = CogColorConstants.Green;
    label.Font = new Font("宋体", 20);
    //根据差值判断是否有缺失
    if (diff > 0)
    {
      res = "缺失:" + diff;
      label.Color = CogColorConstants.Red;
    }
    else
    {
      res = "良品";
      
    }
    label.SetXYText(100, 250

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值