• VisionPro 实现多目标测量


    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
  • 相关阅读:
    异地多活(异地双活)实践经验
    申诉受理
    申诉受理
    关于数据采集需求的讨论帖
    Http压测工具wrk使用指南
    设计爬虫Hawk背后的故事
    APP接口版本兼容的问题
    .net点选验证码实现思路分享
    央企晒年薪 现在终于有机会看到了_青新闻__中国青年网
    蘑菇街电商交易平台服务架构及改造优化历程(含PPT)
  • 原文地址:https://www.cnblogs.com/ybqjymy/p/14463787.html
Copyright © 2020-2023  润新知