Professional Documents
Culture Documents
VP03 2 Graphics-Lab
VP03 2 Graphics-Lab
Objectives:
Instructions:
Exercise
Add code to the vision inspection portion of your application to draw the Edge
graphics from the Caliper tool in the previous lab.
Solution
Up top:
Add references:
Cognex.VisonPro.Caliper
Imports Cognex.VisionPro.Caliper
To bottom of Form_Load():
'Set to interactive
myRect.Interactive = True
Imports Cognex.VisionPro
Imports Cognex.VisionPro.QuickBuild
Imports Cognex.VisionPro.ToolGroup
Imports Cognex.VisionPro.PMAlign
Imports Cognex.VisionPro.Caliper
End Sub
'Initialize variables
myJob = myJobManager.Job("DemoPlate")
myIndependentJob = myJob.OwnedIndependent
'Flush queues
myJobManager.UserQueueFlush()
myJobManager.FailureQueueFlush()
myJob.ImageQueueFlush()
myIndependentJob.RealTimeQueueFlush()
End Sub
'Disable buttons
btnRunOnce.Enabled = False
chkContinuous.Enabled = False
ControlBox = False
chkShowTrain.Enabled = False
End Sub
If InvokeRequired Then
End If
'Enable buttons
btnRunOnce.Enabled = True
chkContinuous.Enabled = True
End Sub
Try
myJobManager.RunContinuous()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Else
btnRunOnce.Enabled = True
ControlBox = True
chkShowTrain.Enabled = True
Try
myJobManager.Stop()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
If InvokeRequired Then
' Create a pointer to this function
Dim myDel As New myJobManagerDelegate(AddressOf
myJobManager_UserResultAvailable)
' Call this same function on the correct thread
Dim eventArgs() As Object = {sender, e}
Invoke(myDel, eventArgs)
Return
End If
End Sub
Else
stlStatus.Text = "There is no input image to load as a train
image."
End If
Else
btnRunOnce.Enabled = True
chkContinuous.Enabled = True
btnRetrain.Enabled = False
End If
End Sub
End Sub
'Assign the new CogRectablgeAffine the region of the Caliper tool from the
application loaded above
'This means that the new interactive graphic will appear exactly where the
caliper tool is already inspecting
myRect = myCaliperTool.Region
'Set to interactive
myRect.Interactive = True
'Set the space in which it will be interpreted (this is the string name
assigned within the coordiante space tool; watch for default duplicate names)
myRect.SelectedSpaceName = "Fixture"
End Sub
'Grab the transferred arguments and set them to the properties 'of the
CogRectangleAffine
myRect = e.DragGraphic
'Set the Caliper tool inspection region to the region 'designated by the
interactive graphic that has just changed
myCaliperTool.Region = myRect
End Sub
End Class