首页 > 编程语言 >VisionPro[CogBlobTool]斑点工具,圆形标注(C#脚本)

VisionPro[CogBlobTool]斑点工具,圆形标注(C#脚本)

时间:2024-10-18 13:48:50浏览次数:3  
标签:VisionPro tool 斑点 C# using circle Cognex CogBlobTool

圆形标注

标注图样板

标注图样板

添加CogToolBlock工具 图像源拖入CogToolBlock

在这里插入图片描述

在CogToolBlock中添加斑点工具拖入图像源

在这里插入图片描述

因为图像比较对比清晰,模式选用硬阈值(动态)

在这里插入图片描述

可以清晰的识别出斑点

在这里插入图片描述

创建C#脚本

​ 选用C#Advabced Scrip高级脚本

在这里插入图片描述

CogGraphicCollection

 //CogGraphicCollection是一个所有图像存储和管理图形对象 集合的元素为 ICogGraphic类型
  //我们用于存储圆形 CogCircle
  CogGraphicCollection graphs = new CogGraphicCollection();

斑点工具GetBlobs方法 , 斑点工具对象名.Results.GetBlobs()

该方法得到的是一组斑点信息,每个斑点信息都是CogBlobResult类型

在这里插入图片描述

C#整体脚本内容

#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.Blob;
#endregion

public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{
  #region Private Member Variables
  private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
  //CogGraphicCollection是一个所有图像存储和管理图形对象 集合的元素为 ICogGraphic类型
  //我们用于存储圆形 CogCircle
  CogGraphicCollection graphs = 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
    //取出斑点工具
    //mToolBlock.Tools["CogBlobTool1"] as CogBlobTool 进行尝试转换 不可以转换返回null
    CogBlobTool blob = mToolBlock.Tools["CogBlobTool1"] as CogBlobTool;
    
    // Run each tool using the RunTool function
    foreach(ICogTool tool in mToolBlock.Tools)
      mToolBlock.RunTool(tool, ref message, ref result);
      
    //循环添加圆给graphs
    //blob.Results.GetBlobs()的到所有斑点的信息
    foreach(CogBlobResult re in blob.Results.GetBlobs())
    {
      //创建圆
      CogCircle circle = new CogCircle();
      
      //设置圆心XY
      //re.CenterOfMassX的到斑点的中心点X
      circle.CenterX = re.CenterOfMassX;
      circle.CenterY = re.CenterOfMassY;
      //设置园的半径
      circle.Radius = 120;
      //设置圆的颜色
      circle.Color = CogColorConstants.Blue;
      //设置园的线条粗细
      circle.LineWidthInScreenPixels = 2;
      
      //将圆添加到graphs
      graphs.Add(circle);
      
    }
    
    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)
  {
    
    //将圆添加到图像中
    foreach(ICogGraphic graph  in graphs)
    {
      CogCircle circle = graph as CogCircle;
      mToolBlock.AddGraphicToRunRecord(circle, lastRecord, "CogBlobTool1.InputImage", "Scrip");
    }
  }
  #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

}


运行结果

在这里插入图片描述

标签:VisionPro,tool,斑点,C#,using,circle,Cognex,CogBlobTool
From: https://blog.csdn.net/2301_80357031/article/details/143034146

相关文章

  • Stratix® 10 SX SoC FPGA结构图— 1SX040HH3F35E2LG 1SX040HH3F35E3XG 1SX040HH3F35I
    Stratix®10SXSoCFPGA结构图英特尔®Stratix®10SoCFPGA结合了四核ARM*Cortex*-A53MPCore*硬处理器系统与革命性的英特尔®Hyperflex™FPGA架构,为嵌入式应用提供了必要的嵌入式性能、功效、密度和系统集成。针对数百万个逻辑元件(LE)FPGA设计优化的全新引擎......
  • linux下使用VSCODE 调试python
    文章目录一、环境准备安装VSCode:安装Python:二、环境测试创建Python文件:编写测试代码运行Linux下使用VSCode调试Python在Linux环境中进行Python开发时,一个高效、直观的调试工具是必不可少的。VisualStudioCode(VSCode)凭借其强大的编辑器功能和丰富的扩展插件,......
  • 用大模型或者向量模型比如huggingface上的模型,处理一批图片,对该图片进行分类,检索
    要使用大模型或向量模型对图片进行分类和检索,通常可以采用以下几种方法:1.**图像分类**:使用预训练的图像分类模型(如ResNet、EfficientNet等)对图片进行分类。2.**图像特征提取**:使用预训练的模型(如CLIP、ResNet等)提取图像的特征向量,然后进行相似度检索。以下是使用HuggingF......
  • CSS文本属性
    在CSS中,我们可以通过文本属性来控制文字的样式。下面是一些常用的文本属性:font-family:用于指定文字的字体。font-size:用于指定文字的大小。font-style:用于指定文字的样式,例如italic或normal。font-weight:用于指定文字的粗细程度。color:用于指定文字的颜色。text-align:用于指定......
  • .NET 开源实时监控系统 - WatchDog 技术解析
    引言在快速迭代的软件开发环境中,实时监控系统的运行状态对于确保应用的稳定性和可靠性至关重要。特别是对于ASP.NETCoreWeb应用程序和API,一个高效、实时的监控系统不仅能够提高开发效率,还能帮助快速定位和解决问题。WatchDog正是一款专为.NET应用设计的开源实时监控系统,本文将......
  • 使用 Crystal 实现验证码识别与自动化登录
    安装所需依赖首先,确保你已经安装了Crystal。可以从Crystal官方网站获取安装指南。接下来,我们需要安装以下依赖:HTTP::Client:用于发送HTTP请求。Tesseract:用于OCR识别(需在系统中安装)。使用以下命令安装Tesseract:bashsudoaptinstalltesseract-ocr2.下载验证码......
  • 2024全网最详细CTF入门指南,新手必看!!!
     2024年最新的CTF(CaptureTheFlag,夺旗赛)入门指南如下,涵盖了入门思路、常见题型及练习网站推荐,帮助你逐步了解并提升在CTF中的解题技巧。一、CTF入门指南CTF基础概念CTF是一种网络安全竞赛形式,主要通过解密、逆向工程、网络攻击、隐写术等方式解决各种网络安全挑战。CTF......
  • Spacy之下载和使用
    下载并使用spacy正常下载和使用参考这个:安装spaCy(最简单的教程)_spacy安装-CSDN博客如果不成功以下提供一种玄学的方法:环境使用anaconda环境,在这个环境下开一个.py文件,写一行importspacy会有波浪线提示你直接下载,点击下载即可。然后在下面打开终端,选择commonprompt,acti......
  • 实时数据化可视化工具LightningChart .NET v12.1.1全新发布
    LightningChart.NET完全由GPU加速,并且性能经过优化,可用于实时显示海量数据-超过10亿个数据点。LightningChart包括广泛的2D,高级3D,Polar,Smith,3D饼/甜甜圈,地理地图和GIS图表以及适用于科学,工程,医学,航空,贸易,能源和其他领域的体绘制功能。立即获取LightningChart.NETv12.1.1正......
  • 第六章 元素应用CSS
    6.1使用CSS设置字体样式<!DOCTYPEhtml><html> <head> <metacharset="utf-8"> <title></title> <style> /*6.1使用CSS设置字体样式*/ h1{ /*6.1.1.字体类型*/ font-family:fangsong; /*6.1.2.字体大小*/ f......