VisionPro多个结果显示

#region namespace imports
using System;
using System.Collections;
using System.Collections.Generic;
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.CalibFix;
using Cognex.VisionPro.Caliper;
#endregion

public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{
  #region Private Member Variables
  private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
  #endregion
  
  
  List<CogRectangle> labels = new List<CogRectangle>();

  /// <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)
    //      mToolBlock.RunTool(tool, ref message, ref result);
    int cirCount = 0;
    List<double> cirX = new List<double>();
    List<double> cirY = new List<double>();
    List<double> cirR = new List<double>();
    
    
    CogImageConvertTool convertT = (CogImageConvertTool) mToolBlock.Tools["CogImageConvertTool1"];
    CogPMAlignTool alignT = (CogPMAlignTool) mToolBlock.Tools["CogPMAlignTool1"];
    CogFindCircleTool findCirTool = (CogFindCircleTool) mToolBlock.Tools["CogFindCircleTool1"];
    
    convertT.Run();
    CogImage8Grey gray = (CogImage8Grey) convertT.OutputImage;
    alignT.Run();
    if(alignT.RunStatus.Result == CogToolResultConstants.Accept){
      cirCount = alignT.Results.Count;
      for(int i = 0 ;i < cirCount;i++){
        cirX.Add(alignT.Results[i].GetPose().TranslationX); 
        cirY.Add(alignT.Results[i].GetPose().TranslationY);
          
        findCirTool.RunParams.ExpectedCircularArc.CenterX = cirX[i];
        findCirTool.RunParams.ExpectedCircularArc.CenterY = cirY[i];
        findCirTool.Run();
        //          
        //          if(findCirTool.Results.Count != 0){
        cirX[i] = findCirTool.Results.GetCircle().CenterX;
        cirY[i] = findCirTool.Results.GetCircle().CenterY;
        cirR.Add(findCirTool.Results.GetCircle().Radius);
        labels.Add(findCirTool.Results.GetCircle().EnclosingRectangle(CogCopyShapeConstants.All));
        //          }
        //输出终端添加
        //          mToolBlock.Outputs.Add(new CogToolBlockTerminal("cirX", cirX));
        //          mToolBlock.Outputs.Add(new CogToolBlockTerminal("cirY", cirY));
        //          mToolBlock.Outputs.Add(new CogToolBlockTerminal("cirR", cirR));
        //          mToolBlock.Outputs.Add(new CogToolBlockTerminal("count", cirCount));
          
        mToolBlock.Outputs["cirX"].Value = cirX;
        mToolBlock.Outputs["cirY"].Value = cirY;
        mToolBlock.Outputs["cirR"].Value = cirR;
        mToolBlock.Outputs["count"].Value = cirCount;
        //          mToolBlock.Outputs.Add("cirY",cirY);
        //          mToolBlock.Outputs.Add("cirR", cirR);
        //          mToolBlock.Outputs.Add("count", labels.Count);
    
      }
    }
    
    

    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)
  {
  //最终结果显示
    if(labels.Count != 0){
      for(int i = 0;i < labels.Count;i++){
        
        ICogGraphic label = (ICogGraphic) labels[i];
        label.Color = CogColorConstants.Green;
        
       mToolBlock.AddGraphicToRunRecord(label, lastRecord, "CogIPOneImageTool1.OutputImage", "script" );
        
      }
      
    }
    
  }
  #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

}




  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值