一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
posts - 3121,comments - 209,views - 578万

VisionPro实现多目标测量其效果如图所示:

VB代码如下:

复制代码
 1 Imports System
 2 Imports System.Collections
 3 Imports Cognex.VisionPro
 4 Imports Cognex.VisionPro3D
 5 Imports Cognex.VisionPro.ToolGroup
 6 Imports Cognex.VisionPro.Blob
 7 Imports Cognex.VisionPro.Caliper
 8  
 9  
10 Public Class UserScript
11   Inherits CogToolGroupBaseScript
12   
13   Dim labels As ArrayList = New ArrayList()
14  
15   'The GroupRun function is called when the tool group is run.  The default
16   'implementation provided here is equivalent to the normal behavior of the
17   'tool group.  Modifying this function will allow you to change the behavior
18   'when the tool group is run.
19   Overrides Function GroupRun(ByRef message As String, _
20                            ByRef result As CogToolResultConstants) _
21     As Boolean
22  
23     ' To let the execution stop in this script when a debugger is attached, uncomment the following line.
24     ' #If DEBUG Then
25     ' If System.Diagnostics.Debugger.IsAttached Then System.Diagnostics.Debugger.Break()
26     ' #End If
27  
28     'Run each tool in the tool group using the RunTool function
29     For toolIdx As Int32 = 0 To ToolGroup.Tools.Count - 1
30       ToolGroup.RunTool(ToolGroup.Tools(toolIdx), message, result)
31     Next
32     
33     Dim blobTool As CogBlobTool = ToolGroup.Tools("CogBlobTool1")
34     Dim caliperTool As CogCaliperTool = ToolGroup.Tools("CogCaliperTool1")
35     Dim caliperRegion As CogRectangleAffine = caliperTool.Region 
36     
37     ToolGroup.RunTool(blobTool, message, result)
38     Dim blobResults As CogBlobResultCollection = blobTool.Results.GetBlobs()
39     
40     For Each blob As CogBlobResult In blobResults
41       
42       caliperRegion.CenterX = blob.CenterOfMassX
43       caliperRegion.CenterY = blob.CenterOfMassY
44       ToolGroup.RunTool(caliperTool, message, result)
45       
46       Dim myCaliper As New CogCaliperTool
47       myCaliper = Me.toolGroup.Tools("CogCaliperTool1")
48       
49       Dim myLabel As CogGraphicLabel = New CogGraphicLabel()
50       myLabel.Alignment = CogGraphicLabelAlignmentConstants.BaselineCenter
51       myLabel.SetXYText(blob.CenterOfMassX, blob.CenterOfMassY, "当前宽度:" + (myCaliper.Results.Item(0).Width).ToString("0.00"))
52       myLabel.Color = CogColorConstants.Green
53       
54       labels.Add(myLabel)
55       
56     Next
57  
58     'Returning False indicates we ran the tools in script, and they should not be
59     'run by VisionPro 
60     Return False
61   End Function
62  
63 #Region "When the Current Run Record is Created"
64   Overrides Sub ModifyCurrentRunRecord(ByVal currentRecord As Cognex.VisionPro.ICogRecord)
65  
66   End Sub
67 #End Region
68  
69 #Region "When the Last Run Record is Created"
70   'Allows you to add or modify the contents of the last run record when it is
71   'created.  For example, you might add custom graphics to the run record here.
72   Overrides Sub ModifyLastRunRecord(ByVal lastRecord As Cognex.VisionPro.ICogRecord)
73  
74     For Each label As CogGraphicLabel In labels
75       ToolGroup.AddGraphicToRunRecord(label, lastRecord, "Image Source.OutputImage", "script")
76       
77     Next
78     
79   End Sub
80 #End Region
81  
82 #Region "When the Script is Initialized"
83   'Perform any initialization required by your script here
84   Overrides Sub Initialize(ByVal host As CogToolGroup)
85     'DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVE
86     MyBase.Initialize(host)
87   End Sub
88 #End Region
89  
90 End Class
复制代码

 

posted on   一杯清酒邀明月  阅读(1017)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示