loading
 
Image Matching
Bob Simmons from United States  [17 posts]
8 year
Hi Steven,

I am getting a better handle on image matching.  What I am doing is using the api to change the parameter for the base_folder.  But I will have many folders and I want to train all those folders easily programmatically.  However, I don't want to train all of the folders together, but individually.  Is there a way?  I'm using VB.net 2015.

FYI - the pipeline seems to finish before the module is actually finished.  I wait for a handshake variable to be set at the end of the pipeline, but it doesn't work - I had to put a delay in before reading the variables.

Also - Something is not stable - it works for a while and then roborealm gets an error and has to close.....


Public Function LoadAndMatchImage(strFileName As String, strTrainedImagesPath As String,  ByRef objReturnVariables() As Object) As Boolean
        Dim intReturn As Integer
        Dim strReturn As String = ""

        lblRoboResult.BackColor = SystemColors.Control

        'Clear the handshaking flag
        intReturn = rr.SetVariable("ProgramDone", "0")
        If intReturn <> -1 Then
            MsgBox("Could not set Robo Variable ""ProgramDone""!", vbExclamation)
            Return False
        End If

        'Set vision command
        intReturn = rr.SetVariable("Command", "REGION")
        If intReturn <> -1 Then
            MsgBox("Could not set Robo Variable ""Command""!", vbExclamation)
            Return False
        End If

        intReturn = rr.SetParameter("Image_Match", 1, "base_folder", strTrainedImagesPath)
        If intReturn <> 0 Then
            MsgBox("Could not set Robo module parameter Image_Match:base_folder to """ & strTrainedImagesPath & """!", vbExclamation)
            Return False
        End If

        If My.Computer.FileSystem.FileExists(strFileName) = True Then
            intReturn = rr.LoadImage("source", strFileName)
            If intReturn <> -1 Then
                MsgBox("Could not set Robo source image to """ & strFileName & """!", vbExclamation)
                Return False
            End If
        Else
            MsgBox("Desired Robo source image """ & strFileName & """ does not exist!", vbExclamation)
            Return False
        End If

        ''When timeout occurs, then can't set variable from VB - that is a problem if timeout occurs!!!
        intReturn = rr.WaitVariable("ProgramDone", "1", 3000)
        If intReturn <> -1 Then
            MsgBox("Timeout waiting for Robo Variable ""ProgramDone""!", vbExclamation)
            Return False
        End If

        'Delay in milliseconds
        Dim intMsTickStart As Integer
        Dim intMsTickEnd As Integer
        intMsTickStart = My.Computer.Clock.TickCount
        intMsTickEnd = intMsTickStart
        While intMsTickEnd - intMsTickStart < 100
            intMsTickEnd = My.Computer.Clock.TickCount
            If intMsTickEnd < intMsTickStart Then intMsTickStart = My.Computer.Clock.TickCount
        End While

        Dim intMatchConfidence As Integer
        Dim strMatchFileName As String
        intMatchConfidence = Int(Val(rr.GetVariable("MATCH_CONFIDENCE")))
        strMatchFileName = rr.GetVariable("MATCH_FILENAME")

        lblRoboResult.Text = "Match Confidence: " & intMatchConfidence
        lblRoboResult.BackColor = Color.LightGreen

        lblResults.Text = "Image Match Results" & vbCr _
                    & vbTab & "Match Confidence: " & intMatchConfidence & vbCr _
                    & vbTab & "Match Filename: " & strMatchFileName & vbCr

        ReDim objReturnVariables(2)
        objReturnVariables(0) = IIf(intMatchConfidence > 0, True, False)
        objReturnVariables(1) = intMatchConfidence
        objReturnVariables(2) = strMatchFileName

        If Val(strReturn) = 1 Then
        Else
        End If

        'Update my displayed image only after the pipeline has run...  Otherwise the image won't be ready
        UpdateImage()

        Return True  'Pass
    End Function
program.robo
Steven Gentner from United States  [1446 posts] 8 year
Bob,

Ideally the image path is only set very infrequently. Its not a parameter that should be changed on every image. If you need to train it on more than one folder, add all the individual folders into a single tree (the training will recursively see all images) and then use the Path results that the image matching sets to see which one you actually matched.

If you cannot do this, then use multiple shape matching modules will set training paths and only active one when needed by setting a variable. I.e. each shape matching module would be enclosed by an if_statement module that checks a single state variable as to if that particular shape matching module should run.

if state = 1 then
  shape_match path1
end if
if state = 2 then
  shape_match path2
end if
if state = 3 then
  shape_match path3
end if
...etc.

I think you got it right in terms of setting a variable and waiting for a change but move the ProgramDone =0 to just before you are checking that it is non-zero and add a rr.waitImage. This ensures that the pipeline operates on the just loaded image and other configuration items at least once as apposed to skipping to reset to the ProgramDone field even before the image has fully loaded. Keep in mind that the pipeline is running while you are setting these variables so race conditions exist frequently. Setting a variable to zero, waiting for the next image and then checking for it to be non-zero will ensure that all settings have been sent and executed on before another iteration causes the variable to become 0.

rr.SetVariable("ProgramDone", "0")
rr.WaitImage()
rr.WaitVariable("ProgramDone", "1", 3000)

should prevent the pipeline from skipping any setting and not using the most recently loaded image.

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index