visionpro液位检测

在这里插入图片描述
在这里插入图片描述

#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.CalibFix;
using Cognex.VisionPro.Caliper;
using Cognex.VisionPro.Dimensioning; //测量工具
using System.Collections.Generic;

#endregion

public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{
  #region Private Member Variables
  private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
  CogGraphicCollection gc = new CogGraphicCollection();
    
  CogGraphicLabel ResultLabel = new CogGraphicLabel();
     
  List<CogGraphicLabel> labels = new List<CogGraphicLabel>();
  
  #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


    // Run each tool using the RunTool function
   
    foreach(ICogTool tool in mToolBlock.Tools)
    { 
      if( tool.Name != "CogCaliperTool2")
      {
         mToolBlock.RunTool(tool, ref message, ref result);  
      } 
    } /**/
     
      
    CogPMAlignTool pma = mToolBlock.Tools["CogPMAlignTool1"] as CogPMAlignTool;   
    CogCaliperTool c = mToolBlock.Tools["CogCaliperTool2"] as CogCaliperTool;
    gc.Clear(); 
    CogDistanceSegmentLineTool dis = mToolBlock.Tools["CogDistanceSegmentLineTool1"] as CogDistanceSegmentLineTool; 
    
    labels.Clear();
    
    foreach(CogPMAlignResult r  in  pma.Results)
    { 
      c.Region.CenterX  = r.GetPose().TranslationX ;
      c.Region.CenterY  = r.GetPose().TranslationY ; 
      mToolBlock.RunTool(c, ref message, ref result);  
        
      CogLineSegment  s = new  CogLineSegment(); 
      s.StartX = c.Results.Edges[0].PositionX;
      s.StartY=  c.Results.Edges[0].PositionY;
      s.EndX = c.Results.Edges[0].PositionX+20;
      s.EndY = c.Results.Edges[0].PositionY;
      s.Color = CogColorConstants.Red;
      s.LineWidthInScreenPixels = 5;
      gc.Add(s);  
      
      dis.Segment = s; 
      mToolBlock.RunTool(dis, ref message, ref result);  
      
      CogGraphicLabel label = new CogGraphicLabel();
      //label.SetXYText(s.StartX, s.StartY, dis.Distance.ToString("F4"));
      if(dis.Distance > 20)
      {
        label.SetXYText(s.StartX, s.StartY, "NG");
      }
      else
      {
        label.SetXYText(s.StartX, s.StartY, "OK"); 
      }
      labels.Add(label);
       
      
    }
       
    
    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

  /// <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)
  {
    foreach(ICogGraphic t in gc)
    {
      //mToolBlock.AddGraphicToRunRecord( t,lastRecord ,"CogPMAlignTool1.InputImage"  ,"");
      mToolBlock.AddGraphicToRunRecord( t,lastRecord ,"CogIPOneImageTool1.OutputImage"  ,""); 
      //ResultLabel.Color = Cognex.VisionPro.CogColorConstants.Blue;
      //mToolBlock.AddGraphicToRunRecord(ResultLabel, lastRecord, "CogIPOneImageTool1.OutputImage", "script"); 
    }
    
    foreach(CogGraphicLabel label in labels)
    { 
      mToolBlock.AddGraphicToRunRecord(label, lastRecord, "CogIPOneImageTool1.OutputImage", "");  
    }
    
    
  }
  #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

}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值