首页 > 编程语言 >C#联合Visionpro编程学习记录(将指定颜色的十字线图形添加到CogRecordDisplay上)

C#联合Visionpro编程学习记录(将指定颜色的十字线图形添加到CogRecordDisplay上)

时间:2024-10-09 19:13:11浏览次数:9  
标签:十字线 CogGraphicCollection C# CogRecordDisplay Image strmsg Visionpro null cogreco


1 /// <summary> 2 /// 将指定颜色的十字线图形添加到CogRecordDisplay上 3 /// </summary> 4 /// <param name="icogimage"></param> 5 /// <returns></returns> 6 public static string AddCrossCurveRecord2CogRecordDisplay(ICogImage Image, /*ref*/ CogRecordDisplay cogrecorddisplay, Cognex.VisionPro.CogColorConstants CrosshairColor) 7 { 8 string strmsg = ""; 9 CogCreateLineTool[] cogCreateTool = new CogCreateLineTool[2] {new CogCreateLineTool(),new CogCreateLineTool() }; 10 CogGraphicCollection cgc = new CogGraphicCollection(); 11 ICogImage icogimage = Image; 12 ClearCogRecordDisplay(cogrecorddisplay); 13 try 14 { 15 //cogrecorddisplay.Image = icogimage; 16 if (cogrecorddisplay.Image==null) 17 { 18 if (icogimage!=null) 19 { 20 cogrecorddisplay.Image = icogimage; 21 } 22 else 23 { 24 cogrecorddisplay.Image = new CogImage8Grey(icogimage.Width, icogimage.Height); 25 } 26 } 27 if (cogrecorddisplay.Image != null) 28 { 29 for (int i = 0; i < 2; i++) 30 { 31 cogCreateTool[i].InputImage = cogrecorddisplay.Image; 32 cogCreateTool[i].OutputColor = CrosshairColor; 33 cogCreateTool[i].Line.X = cogrecorddisplay.Image.Width / 2; 34 cogCreateTool[i].Line.Y = cogrecorddisplay.Image.Height / 2; 35 36 switch (i) 37 { 38 case 0: 39 cogCreateTool[i].Line.Rotation = 0; 40 break; 41 case 1: 42 cogCreateTool[i].Line.Rotation = 90 / (180 / Math.PI); 43 break; 44 default: 45 break; 46 } 47 cogCreateTool[i].Run(); 48 GraphicsAddIn(Get_ToolResultGC(cogCreateTool[i]), ref cgc); 49 } 50 ShowImageAndGc2CogRecordDisplay(ref cogrecorddisplay, cgc); 51 } 52 else 53 { 54 strmsg += "cogrecorddisplay中没有图像!"; 55 } 56 } 57 catch (Exception ex) 58 { 59 strmsg += ex.Message; 60 } 61 return strmsg; 62 }

 

  1  /// <summary>
  2         /// 清空CogRecordDisplay中的图形和图像
  3         /// </summary>
  4         /// <param name="crd"></param>
  5         /// <returns></returns>
  6         public static string ClearCogRecordDisplay( CogRecordDisplay crd)
  7         {
  8             string strmsg = "";
  9             try
 10             {
 11                 ClearCogRecordDisplayWithoutImage(crd);
 12                 crd.Image = null;
 13             }
 14             catch (Exception ex)
 15             {
 16                 strmsg = ex.Message;
 17             }
 18             return strmsg;
 19         } 
 20         /// <summary>
 21         /// 清空CogRecordDisplay中的图形但不清空图像
 22         /// </summary>
 23         /// <param name="crd"></param>
 24         /// <returns></returns>
 25         public static string ClearCogRecordDisplayWithoutImage(CogRecordDisplay crd)
 26         {
 27             string strmsg = "";
 28             try
 29             {
 30                 crd.StaticGraphics.Clear();
 31                 crd.InteractiveGraphics.Clear();
 32                 //crd.Image = null;
 33             }
 34             catch (Exception ex)
 35             {
 36                 strmsg = ex.Message;
 37             }
 38             return strmsg;
 39         }
 40 
 41 
 42         /// <summary>
 43         /// 获取工具的CogGraphicCollection(几何图形图集)
 44         /// </summary>
 45         /// <param name="Tool"></param>
 46         /// <returns></returns>
 47         public static CogGraphicCollection Get_ToolResultGC(ICogTool Tool)
 48         {
 49             CogGraphicCollection graphics = new CogGraphicCollection();
 50             if (Tool == null)
 51             {
 52                 return graphics;
 53             }
 54             return Get_ToolResultGC_Ext(Tool);
 55         }
 56 
 57  /// <summary>
 58         /// 获取工具的CogGraphicCollection(几何图形图集)
 59         /// </summary>
 60         /// <param name="Tool"></param>
 61         /// <returns></returns>
 62         public static CogGraphicCollection Get_ToolResultGC_Ext(ICogTool Tool)
 63         {
 64             CogGraphicCollection graphics = new CogGraphicCollection();
 65             if (Tool != null)
 66             {
 67                 Tool.GetType();
 68                 ICogRecord record = Tool.CreateLastRunRecord();
 69                 ICogRecords records = record.SubRecords;
 70                 try
 71                 {
 72 
 73                     if (records == null)
 74                     {
 75                         return graphics;
 76                     }
 77                     int count = record.SubRecords.Count;
 78                     List<string> list = new List<string>();
 79                     for (int i = 0; i < record.SubRecords.Count; i++)
 80                     {
 81                         foreach (object obj2 in record.SubRecords[i].SubRecords)
 82                         {
 83                             ICogRecord record3 = (ICogRecord)obj2;
 84 
 85                             Type type = ((ICogRecord)obj2).ContentType;
 86                             list.Add(type.Name);
 87                             if (type.Name == "CogGraphicCollection")
 88                             {
 89                                 CogGraphicCollection graphics2 = (CogGraphicCollection)record3.Content;
 90                                 for (int j = 0; j < graphics2.Count; j++)
 91                                 {
 92                                     graphics.Add(graphics2[j]);
 93                                 }
 94                             }
 95                             else if (type.Name == "ICogGraphicInteractive")
 96                             {
 97                                 ICogGraphicInteractive interactive = (ICogGraphicInteractive)record3.Content;
 98                                 graphics.Add(interactive);
 99                             }
100                         }
101                     }
102                     int num3 = records.Count;
103                 }
104                 catch (Exception ex)
105                 {
106                 }
107             }
108             return graphics;
109         }
110 
111 /// <summary>
112         /// 将一个CogGraphicCollection(几何图形集合)添加到另一个CogGraphicCollection(几何图形集合)
113         /// </summary>
114         /// <param name="GC_Source"></param>
115         /// <param name="GC_Target"></param>
116         public static void GraphicsAddIn(CogGraphicCollection GC_Source, ref CogGraphicCollection GC_Target)
117         {
118             if ((GC_Source != null) && (GC_Target != null))
119             {
120                 for (int i = 0; i < GC_Source.Count; i++)
121                 {
122                     GC_Target.Add(GC_Source[i]);
123                 }
124             }
125         }
126 
127  /// <summary>
128         /// 将几何图形添加到指定CogRecordDisplay上
129         /// </summary>
130         /// <param name="cogRD"></param>
131         /// <param name="gc"></param>
132         public static void ShowImageAndGc2CogRecordDisplay(ref CogRecordDisplay cogRD, CogGraphicCollection gc)
133         {
134             cogRD.Fit(false);
135             if ((gc != null) && (gc.Count > 0))
136             {
137                 try
138                 {
139                     for (int i = 0; i < gc.Count; i++)
140                     {
141                         cogRD.StaticGraphics.Add(gc[i], "");
142                     }
143                 }
144                 catch (Exception ex)
145                 {
146                 }
147             }
148         }

 

标签:十字线,CogGraphicCollection,C#,CogRecordDisplay,Image,strmsg,Visionpro,null,cogreco
From: https://www.cnblogs.com/wwdwwd/p/18454943

相关文章

  • 探究AudioPolicyManager.cpp中的成员变量mAvailableOutputDevices/InputDevices是根据
    2024-09-2310:29:48.792286-445APM-AudioPolicyEnginepid-286Wframeworks/av/services/audiopolicy/enginedefault/src/Engine.cpp:getDeviceForStrategyInt:2782024-09-2310:29:48.792286-445AudioFlingerpid......
  • tricks
    二分答案P2824排序有时候可以尝试二分最后的答案,把不好维护的东西变成\(0\)和\(1\)。操作分块P5443桥梁将操作分块维护,一般适用于可以很好维护静态询问但是需要支持修改的情况(?)。状态压缩去除后效性P2157学校食堂dp有后效性但影响范围很小可以考虑把后续决策压缩起......
  • es: match_phrase短语匹配
    一,问题的表现当我们在es的索引库中搜索朝阳新城时,搜索结果中有包含朝阳新城这四个字的结果,也有只包含朝阳或只包含新城的结果,这是analyzer在对关键词做了分词之后从索引库中返回,如果说:我只想要包含朝阳新城这四个字的结果,需要怎么做?二,解决:1,默认的match搜索会对搜索内容......
  • CSP模拟7
    欠的太多了,就少说点吧T1.median把数组\(a,b,c,d,e\)存到一起,标记类型,然后排序,枚举每个数为中位数,算贡献即可。点击查看代码#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=1e5+107;constintmod=998244353;intn;structlmy{ in......
  • C++名字空间
    基本概念名字空间本质上是自定义作用域,由于C++设计的初衷是开发大规模软件,大量的软件库必然会加剧全局符号(变量、函数)的冲突,因此名字空间最基本的作用就是给不同的库和模块拥有自己的独特的作用域,处于不同名字空间中的重名符号相安无事,互不冲突,以此来大大提高编程的便利性。1.1......
  • CMake 属性之全局属性
    【写在前面】CMake的全局属性是指在CMake配置过程中,对整个项目范围生效的设置。这些属性不同于目标(Target)属性或目录(Directory)属性,后者仅对特定的目标或目录生效。【正文开始】CMake全局范围的属性有(CMake3.30 ):ALLOW_DUPLICATE_CUSTOM_TARGETSAUTOG......
  • C语言结构体
    1.结构体的定义、初始化、打印输出#include<stdio.h>#include<string.h>structStudent{//定义结构......
  • Facefusion3.0一键整合包,轻松三步实现换脸,不限电脑配置
    FaceFusion3.0,是由Roop项目的核心开发者独立发布的一款功能强大的人脸转换和增强工具。全新的FaceFusion3.0版本,除了支持AI视频/图片换脸、直播换脸、数字人外,还新增了表情修复、年龄修改等功能,效果更自然、逼真。具备高度真实感、快速运行等特点,能短时间内,生成逼真的换脸视......
  • 以pytorch的forward hook为例探究hook机制
    在看pytorch的nn.Module部分的源码的时候,看到了一堆"钩子",也就是hook,然后去研究了一下这是啥玩意。基本概念在深度学习中,hook是一种可以在模型的不同阶段插入自定义代码的机制。通过自定义数据在通过模型的特定层的额外行为,可以用来监控状态,协助调试,获得中间结果。以前向hook......
  • 树莓派 RasperryPi 开源免费的PLC通讯神器 LECPython,和欧姆龙Omron PLC通讯示例
    简介LECPython是一个强大的Python组件,基于C#开发,能够实现Python与PLC之间的高效通信。本文将指导您如何在树莓派(RaspberryPi)上安装和使用LECPython组件,为您的工业自动化项目提供便利。LECPython旨在解决在树莓派等嵌入式设备上,与可编程逻辑控制器(PLC)建立高效通信的......