visionpro检测液体是否合格并显示

添加完图片之后只用模板匹配工具框选出需要检测的

以及使用卡尺卡出液体达到的线

使用找线工具找出容器的起始线

随后以找线工具某点的xy轴来拟合一条直线

随后使用点到线工具测量卡尺工具卡到线的中心点到拟合线的距离即可

连线如下

最终效果以及脚本

#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.PMAlign;
using Cognex.VisionPro.Caliper;
using Cognex.VisionPro.Dimensioning;
#endregion

public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{
  #region Private Member Variables
  private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
  
  CogGraphicCollection col = new CogGraphicCollection();//创建图形集合

  
  #endregion

  /// <summary>
  /// Called when the parent tool is run.
  /// Add code here to customize or replace the normal run behavior.
  /// </summary>
  /// <param name="message">Sets the Message in the tool's RunStatus.</param>
  /// <param name="result">Sets the Result in the tool's RunStatus</param>
  /// <returns>True if the tool should run normally,
  ///          False if GroupRun customizes run behavior</returns>
  public override bool GroupRun(ref string message, ref CogToolResultConstants result)
  {
    // To let the execution stop in this script when a debugger is attached, uncomment the following lines.
    // #if DEBUG
    // if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();
    // #endif

    CogPMAlignTool pma = new CogPMAlignTool();//创建以下几个所需的工具
    CogFitLineTool fit = new CogFitLineTool();
    CogCaliperTool cal = new CogCaliperTool();
    CogDistancePointLineTool dis = new CogDistancePointLineTool();

    CogGraphicLabel mLable;//图形标签
   
    col.Clear();//清空图形集合
    
    // Run each tool using the RunTool function
    foreach(ICogTool tool in mToolBlock.Tools)
      mToolBlock.RunTool(tool, ref message, ref result);

    pma = (CogPMAlignTool)mToolBlock.Tools["CogPMAlignTool1"];//获取所需的工具
    cal = (CogCaliperTool)mToolBlock.Tools["CogCaliperTool1"];
    fit = (CogFitLineTool)mToolBlock.Tools["CogFitLineTool1"];
    dis = (CogDistancePointLineTool)mToolBlock.Tools["CogDistancePointLineTool1"];
//使用for循环来多次使用卡尺工具
    for (int i = 0; i < pma.Results.Count; i++)
    {
      cal.Region.CenterX= pma.Results[i].GetPose().TranslationX;//卡尺工具的输入坐标等于模板匹配工具输出的坐标
      cal.Region.CenterY= pma.Results[i].GetPose().TranslationY;
      cal.Run();//启动工具
      dis.X=cal.Results[0].Edge0.PositionX;//给点到线工具传入所需要的参数 x y 一条线
      dis.Y=cal.Results[0].Edge0.PositionY;
      dis.Line = fit.Result.GetLine();
     
      dis.Run();//启动工具

       CogRectangle z = new CogRectangle();//创建一个矩形
      
      
      //判断是否合格
      if (dis.Distance<130&&dis.Distance>110)
      {
        mLable = new CogGraphicLabel();
        mLable.Color = CogColorConstants.Green;
        mLable.SetXYText(cal.Results[0].Edge0.PositionX, cal.Results[0].Edge0.PositionY, "OK:"+dis.Distance.ToString("F2"));
        col.Add(mLable);//把图形标签存入图形集合
      }
      else
      {
        mLable = new CogGraphicLabel();
        mLable.Color = CogColorConstants.Red;
        mLable.SetXYText(cal.Results[0].Edge0.PositionX, cal.Results[0].Edge0.PositionY, "NG:" + dis.Distance.ToString("F2"));
        col.Add(mLable);   
      }
      

      //定义矩形的数据最终显示成为卡尺工具的线
      z.Color = CogColorConstants.Red;
      z.SetXYWidthHeight(cal.Results[0].Edge0.PositionX- 8,cal.Results[0].Edge0.PositionY, 25, 0.01);
      col.Add(z);
      
    }
    
    
    return false;
  }

  #region When the Current Run Record is Created
  /// <summary>
  /// Called when the current record may have changed and is being reconstructed
  /// </summary>
  /// <param name="currentRecord">
  /// The new currentRecord is available to be initialized or customized.</param>
  public override void ModifyCurrentRunRecord(Cognex.VisionPro.ICogRecord currentRecord)
  {
  }
  #endregion

  #region When the Last Run Record is Created
  /// <summary>
  /// Called when the last run record may have changed and is being reconstructed
  /// </summary>
  /// <param name="lastRecord">
  /// The new last run record is available to be initialized or customized.</param>
  public override void ModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord)
  {

//遍历图形集合输出到页面
    for(int i = 0;i < col.Count;i++){
      
      mToolBlock.AddGraphicToRunRecord(col[i], lastRecord, "CogPMAlignTool1.InputImage", "");
    }

    
  }
  #endregion

  #region When the Script is Initialized
  /// <summary>
  /// Perform any initialization required by your script here
  /// </summary>
  /// <param name="host">The host tool</param>
  public override void Initialize(Cognex.VisionPro.ToolGroup.CogToolGroup host)
  {
    // DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVE
    base.Initialize(host);


    // Store a local copy of the script host
    this.mToolBlock = ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host));
  }
  #endregion

}

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VisionPro毛刺检测是一种使用机器视觉技术来检测产品表面毛刺的方法。通过使用高分辨率的相机和图像处理软件,该系统可以快速准确地检测出产品表面的毛刺问题。 VisionPro毛刺检测的工作原理是先采集产品表面的图像,然后通过图像处理软件对图像进行分析和处理。软件可以根据预先设定的毛刺特征进行算法匹配,从而判断是否存在毛刺。检测结果会在显示屏上显示出来,以供操作人员判断。 VisionPro毛刺检测具有许多优势。首先,它可以高效地进行自动化检测,大大提高了生产效率。其次,该系统可以有效地减少人为因素的影响,提高检测的准确性和一致性。此外,VisionPro毛刺检测还可以提供详细的检测报告和统计数据,方便企业进行质量管理和改进。 然而,VisionPro毛刺检测也存在一些挑战和限制。首先,该系统需要高质量的图像输入才能获得准确的检测结果。其次,对于某些特殊形状、颜色或材质的产品,可能需要进行特殊的图像处理算法才能进行准确的毛刺检测。此外,VisionPro毛刺检测的投资成本较高,对于小型企业可能有一定的经济压力。 总的来说,VisionPro毛刺检测是一种高效、准确的自动化检测方法,可以在工业生产中广泛应用。随着机器视觉技术的不断发展,相信VisionPro毛刺检测会在未来有更广阔的应用前景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值