目录

VisionProVisionMaster-多模板匹配分类大球刀小球刀尖刀三角刀

VisionPro、VisionMaster 多模板匹配分类(大球刀、小球刀、尖刀、三角刀)

VisionPro

https://i-blog.csdnimg.cn/direct/3295b37b891641c79aa3bc56e706cb33.png

VisionMaster

https://i-blog.csdnimg.cn/direct/5c00c0ddde0f4a4f83bb573f9f5cdb8a.png


分类:大球刀、小球刀、尖刀、三角刀

https://i-blog.csdnimg.cn/direct/217271512a9b4407a51a708f8c1d30f5.png

VisionPro  实现

使用多模板匹配工具

https://i-blog.csdnimg.cn/direct/49047091c5e84144a5feebc74eba1bca.png

设置参数

https://i-blog.csdnimg.cn/direct/5fa4f7f31c0e4c3cb12f9fdd6c11aaaa.png

https://i-blog.csdnimg.cn/direct/766e5e74afc14dceb1c27221d5cd062a.png

小球刀

大球刀

https://i-blog.csdnimg.cn/direct/28e04aa9a5184827ad18899d1888e8ff.png

尖刀

三角刀

https://i-blog.csdnimg.cn/direct/4b3bdd5012fa4e1eb2f75d66e4a989c9.png

https://i-blog.csdnimg.cn/direct/e2e98ec425064028943b8035fb998cd8.png

右键添加终端

https://i-blog.csdnimg.cn/direct/1d30f5fcfb504fd4803bb1d3cf510904.png

代码实现

1.声明文本显示
 CogGraphicLabel label = new CogGraphicLabel();
2.找到工具
CogPMAlignMultiTool pma = mToolBlock.Tools["CogPMAlignMultiTool1"]as CogPMAlignMultiTool;
3.声明类名
   
    string s = pma.Results.PMAlignResults[0].ModelName;
    label.Alignment = CogGraphicLabelAlignmentConstants.TopLeft;
    label.SetXYText(10, 10, s);
    label.Color = CogColorConstants.Red;
4.显示图片上
 mToolBlock.AddGraphicToRunRecord(label, lastRecord, "CogPMAlignMultiTool1.InputImage", "");
5.总体需要写的代码
CogGraphicLabel label = new CogGraphicLabel();
CogPMAlignMultiTool pma = mToolBlock.Tools["CogPMAlignMultiTool1"]as CogPMAlignMultiTool;
string s = pma.Results.PMAlignResults[0].ModelName;
    label.Alignment = CogGraphicLabelAlignmentConstants.TopLeft;
    label.SetXYText(10, 10, s);
    label.Color = CogColorConstants.Red;
mToolBlock.AddGraphicToRunRecord(label, lastRecord, "CogPMAlignMultiTool1.InputImage", "");
给大家放的cv代码
#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;
#endregion

public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{
  #region Private Member Variables
  private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
  #endregion
  CogGraphicLabel label = new CogGraphicLabel();
  /// <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
    CogPMAlignMultiTool pma = mToolBlock.Tools["CogPMAlignMultiTool1"]as CogPMAlignMultiTool;

    // Run each tool using the RunTool function
    foreach(ICogTool tool in mToolBlock.Tools)
      mToolBlock.RunTool(tool, ref message, ref result);
   
    
    string s = pma.Results.PMAlignResults[0].ModelName;
    label.Alignment = CogGraphicLabelAlignmentConstants.TopLeft;
    label.SetXYText(10, 10, s);
    label.Color = CogColorConstants.Red;
    

    

    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)
  {
    mToolBlock.AddGraphicToRunRecord(label, lastRecord, "CogPMAlignMultiTool1.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

}

VisionMaster 实现

https://i-blog.csdnimg.cn/direct/87f860429b564a758f2e117816ed90db.gif

https://i-blog.csdnimg.cn/direct/47f0bbbe7a82495d8548fc504b4b74ad.png

https://i-blog.csdnimg.cn/direct/2746442020fe47458006040d99f92979.png

https://i-blog.csdnimg.cn/direct/e94982cbbe9d409a90c6c719bc589c37.png https://i-blog.csdnimg.cn/direct/ea2095478e7f4649950f255a9ac61056.png https://i-blog.csdnimg.cn/direct/13f141a564834b9cb7b307f981c228d1.png

https://i-blog.csdnimg.cn/direct/5a60101504674b36936af60da0085bdf.png https://i-blog.csdnimg.cn/direct/1aa62e0a47224358b03dd368529f81b3.png https://i-blog.csdnimg.cn/direct/fb58f86835b44d399ef147f19aef3bbd.png https://i-blog.csdnimg.cn/direct/705f604e661840c7a511eb1643f08de0.png

点击运行,进行下面的操作

https://i-blog.csdnimg.cn/direct/e4ba84adb5e644edb00c33c8622bd48f.png

https://i-blog.csdnimg.cn/direct/de86308d5db648079f9261f954c842af.png https://i-blog.csdnimg.cn/direct/5ff4e8d8b9964456b6149f1136493f91.png https://i-blog.csdnimg.cn/direct/4af42485e1db45728ef2fe53f1cdccf7.png https://i-blog.csdnimg.cn/direct/8b5a9eb4e000446cb974cad2770287e2.png https://i-blog.csdnimg.cn/direct/6856b11aaf4342ceaa052c639ab113f4.png https://i-blog.csdnimg.cn/direct/6b251e9457694193a5524136945c9e15.png

https://i-blog.csdnimg.cn/direct/16418516e67e49b5a448fc538db73d4c.png https://i-blog.csdnimg.cn/direct/48e69cdacb234ceab9df0885fae6447a.png https://i-blog.csdnimg.cn/direct/740816c9746c4a30bbdc5d168956a229.png

https://i-blog.csdnimg.cn/direct/1bf3fcc251aa492882cfa43563cae6fc.png https://i-blog.csdnimg.cn/direct/e4eb44485df840a4a3bfd3a47f41bd7b.png https://i-blog.csdnimg.cn/direct/ae578c502a5541e2ad87b1bc5ec4ac69.png

https://i-blog.csdnimg.cn/direct/eb04eeca0b4f454c8893580f03fc51b4.png