码迷,mamicode.com
首页 > 其他好文 > 详细

VisionPro 实现多目标测量

时间:2021-03-02 12:04:55      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:over   mod   arraylist   visio   OLE   -o   目标   each   follow   

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

 

VisionPro 实现多目标测量

标签:over   mod   arraylist   visio   OLE   -o   目标   each   follow   

原文地址:https://www.cnblogs.com/ybqjymy/p/14463787.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!