loading
 
Multi object tracking and triggering
Aman Rana from United States  [25 posts]
4 years
Here is the working vbscript It work amazingly great for multiblob tracking and triggering. I found very tricky to work with it. Hope help other readers. Only problem I notice that I am still not able to keep the trigger on for desired time and then release. If I increase period at any point. it start behaving ridiculously. Let me know if anybody figure out how to handle this issue.

'SetVariable "FPS", 1
'SetVariable "COG_X", 130
'SetVariable "COG_Y", 130
SetVariable "Trigger", 1000

list = GetArrayVariable("BLOBS")
if isArray(list) then
  ' we have an array - write out the size
  write "The size is " & ubound(list) & vbCRLF
  ' now write out all the elements
  for i = 0 to ubound(list) step 2
    write "X: " & CInt(list(i)) & "   Y:" & CInt(list(i+1)) & Trigger & vbCRLF

period = 40
step = GetVariable("step")
if step = 0 then
SetVariable ("COG_X"), CInt(list(i))
SetVariable ("COG_Y"), CInt(list(i+1))
  SetVariable "Trigger", 1000
  SetVariable "step", 1
  SetTimedVariable "step", 2, period
else
if step = 2 then
SetVariable ("COG_X"), CInt(list(i))
SetVariable ("COG_Y"), CInt(list(i+1))
  SetVariable "Trigger", 2000
  SetVariable "step", 3
  SetTimedVariable "step", 4, period
else
if step = 4 then
SetVariable ("COG_X"), CInt(list(i))
SetVariable ("COG_Y"), CInt(list(i+1))
  SetVariable "Trigger", 1000
   SetVariable "step", 0
end if
end if
end if
next
end if
Steven Gentner from United States  [1370 posts] 4 years
Aman,

That's to be expected (behaving erradically) since you are using the same variables for all blobs. When there is more than one blob present you have to determine a sequence that will individually visit each blob while ignoring the ones that you've already sprayed.

If you include an example image and robofile of all those blobs we can supply you with a more practical approach to ordering the blobs and then visiting each one with enough time to spray. The trick is to ensure that you order all the blobs the same for each image capture ... or you could sample one image and keep that image instead of capturing more. Even if a blob were to change size or move it would not hurt the sequence of visitations.

You have a step variable which maintains the state but you'd need another one to maintain which blob you are currently processing so you know which one to continue with next.

STeven.
Aman Rana from United States  [25 posts] 4 years
Steven
I am sending you two plot pictures of situation where I want to to target each green plant and trigger. My prototype will run in steps. It will take picture, process targets by applying green filter, blobs filter for individual coordinates, vbscript, scaling variables, sent to pololu maestero  and trigger on each for desired period. When finished it will move again so that it can take next frame and repeat the whole process and never trigger twice on one plant. I knew something is wrong in my vbscript what I sent you before. But don't know what it is. I will really appreciate if any one can help out.

  
Steven Gentner from United States  [1370 posts] 4 years
Ok, try the following instead:


if GetVariable("SCRIPT_COUNT") = 0 then
  SetVariable "Trigger", 1000
end if

period = 500
step = GetVariable("step")

if step = 0 then
  list = GetArrayVariable("BLOBS")
  if isArray(list) then
    if ubound(list)>0 then
      SetVariable ("COG_X"), CInt(list(0))
      SetVariable ("COG_Y"), CInt(list(1))
      SetVariable "Trigger", 1000
      SetVariable "step", 1
      SetTimedVariable "step", 2, period
    end if
  end if
elseif step = 2 then
  SetVariable "Trigger", 2000
  SetVariable "step", 3
  SetTimedVariable "step", 4, period
elseif step = 4 then
  SetVariable "Trigger", 1000
  SetVariable "step", 0
end if

If you still have trouble, please include the rest of your robofile too so we can see what you are using Trigger and the other variables for.

STeven.
Aman Rana from United States  [25 posts] 4 years
Steven
Thanks a lot for your help. It's a great software. Unfortunately vbscript you provided only track and trigger first blob. It doesn't respond to left over blobs. May be because you used list(0) and List(1) instead of list(i). When I used list (i) in my vbscript, it stuck to the last blob. I used triggering as subroutine function that can be pulled on demand in main function.  But my requirement is if I have 10 blobs in one frame I want to send one by one coordinates of each blob and trigger them as you seen in picture of plants I sent you earlier. I want to program doesn't capture new image until it finished with all blobs tracking and triggering in existing frame.  I really appreciate you time and effort.
program.robo
Steven Gentner from United States  [1370 posts] 4 years
Aman,

No, we intentionally used list(0) as I HIGHLY recommend you process one object at time. The problem is that after doing something to the first detected blob it is very likely that the others have now moved due to some action (not sure what you are doing but it will probably cause the machine to move).

If you still want to do this for each blob, then you have what you need to accomplish this. You will have to set another counter variable that indicates which blob you are on. This can be added into step 4. This counter variable is only incremented on step 4 until all blobs have been processed ... the problem is that if any of the blobs you think you have processed suddenly disappear or new blobs are detected your list will be different from what you thought it was ... so be sure to  instead make a copy of the array before starting with index 1 step 1 and only grab a new copy when you return to that state. Then at least, you just ignore any new results of the image processing and work with a stable list of x,y coordinates.

You have the code for array entry 0,1, now extend that to N,N+1.

STeven.
Aman Rana from United States  [25 posts] 4 years
Steven
Thanks a lot for your help. Sorry I am bothering you again. objects/image will be subjected to change based on plant population in real world situation. I tried but didn't find how can I save array as you suggested. Here I tried to use For...Next function with 2 step increment . Now it should be able to read two blob at a time with triggering. I separate triggering as sub function so that I can recall whenever needed. It able to write all blobs in msg box that mean it able to all blobs but when I set COG_X and COG_Y in same loop it fails. It still stuck to last object in array even everything camera and object both are stationary and not movement at all. I am doing this just by putting two green stickers on a plain paper in front of camera.  I just want you to have a look at it and suggest why For...Next loop is not working for all blobs. I will really appreciate your time & effort.


Here is my VBScript

if GetVariable("SCRIPT_COUNT") = 0 then
  SetVariable "Trigger", 1000
end if

list = GetArrayVariable("BLOBS")
  if isArray(list) then
    if ubound(list)>0 then    

For i = 0 to ubound(list) step 2
        SetVariable "COG_X", CInt(list(i))
        SetVariable "COG_Y", CInt(list(i+1))
        Call mysubroutine()

write "X: " & CInt(list(i)) & "   Y:" & CInt(list(i+1)) & vbCRLF    

Next
end if
end if


Sub mysubroutine()
period = 500
step = GetVariable("step")
if step = 0 then
            SetVariable "Trigger", 1000
      SetVariable "step", 1
      SetTimedVariable "step", 2, period
elseif step = 2 then
  SetVariable "Trigger", 1130
  SetVariable "step", 3
  SetTimedVariable "step", 4, 500
elseif step = 4 then
  SetVariable "Trigger", 1000
  SetVariable "step", 0
end if
end sub

program.robo
Steven Gentner from United States  [1370 posts] 4 years
Aman,

The issue you are having has to do with how variables are used and how RoboRealm executes its modules. Let me try to give you a larger view:

RoboRealm processes each image one at a time by capturing one image and then running each module in succession on that image. When all modules are done, it then captures the next image and repeats the process.

Modules are called one at a time. Only when one module is complete does the next get called. This is a sequential process.

So, when you use the VBScript module to set a variable that value is NOT used until the another module is called that may use that value. So when you set the variable more than once in the same module you are just overwriting the value until that module ends. At that point the variable will contain the last value that you set ... which is then used by subsequent modules.

So with that in mind, each time you call your mysubroutine from within the VBScript module you are just overwriting the previous values that were NEVER reacted on.

What you need is a structure that allows the VBScript module to end each time you make any change to the Trigger variables.

This can be done using a variable that you set to what you are thinking of as i. So remove the for loop that does nothing in the VBScript module and instead use

i = GetVariable("i")

SetVariable "COG_X", CInt(list(i))
SetVariable "COG_Y", CInt(list(i+1))
Call mysubroutine()

i = i + 2
SetVariable "i", i

and let the module end. Each time the module is called, i will increment by 2 and let all other modules that react to that new value.

Does that make better sense? You have to think of the entire pipeline as being within the loop.

STeven.
Steven Gentner from United States  [1370 posts] 4 years
Aman,

See the attached robofile which visits each of your green plants every couple seconds. Note the red circle that shows what the COG_X and COG_Y values are currently set to. Also note that even if you change the image during the visitation cycle it will NOT update. Only when all plants have been visited will it lock in a new array of green blobs.

The concepts are tricky so we though a full example may steer you along better.

You still have the very hard problem of translating the COG_X and COG_Y into actual servo movements. I suspect this will be difficult to get precise unless you servos are inline with the camera (i.e. right next to it).

Note the use of the "step" and "blob_index" variable that keeps state even when the VBScript module is exited. Also note the absense of any FOR or WHILE loop (you are in one in the processing pipeline).

STeven.
program.robo
Aman Rana from United States  [25 posts] 4 years
Steven
Thanks a lot for your help.Again, here I am sending you a robo file of situation where I want to process different object of same image to get different XY coordinates so that they can be sent to different channels of pololu maestero. For example small object will be triggered by X,Y and trigger and big one by X1,Y1 and trigger1. But when I do second processing in tab2, I think vbscript doesn't respond as expected but showing results were from first processing. Will you please help me figure out what and where it gone wrong? Thanks.
Aman
program.robo
Aman Rana from United States  [25 posts] 4 years
Steven
Again, I am also looking for option how to get blob size of a particular blob which is under processing i.e which has circle on it. so that I can use that blob size to correlate/attach with third servo which will control spray width. I will really appreciate your help.

Thanks

Aman
Steven Gentner from United States  [1370 posts] 4 years
Aman,

Instead of using the Blob Filter array you will need to use the Geometric Stats module to generate both the COG's and the AREA. I had to rename things since that module also generates a COG_X, etc. so I used NEW_COG_X, etc. as your variables.

See attached for that example.

Also, in your previous posts, the problems you were having with using multiple tabs is variable collision. Be careful when one module uses variables that get overwritten by others. In your case using Blob_Filter module in 2 tabs will cause one to overwrite the variable in the other .. tabs share the same variable space and are NOT separate instances as you may have thought. Thus setting a variable in one tab WILL change what the other sees.

STeven.
program.robo

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