loading
 
Object Recognition with more objects
Guido from Italy  [7 posts]
4 years
Hi,
Kindly I would want to know, in simple way, if a way exists to work with more objects contemporarily, since in the variable OBJECT_NAME only 1 value is memorized.

That is: if it recognizes only me the object "A", RR performs an action, if it recognizes only me the object "B", RR performs me a different action, and still if it recognizes me the object "A" + the object "B", RR still performs me a different action. (eventually also to plan any action)

- An example specify of what would serve me - :
1) only object "A" = Action
2) to the object "B" is added object "A" = No Action
3) only object "B" no action

There would be very thankful and I hope that you can tell me if this thing is possible, and in positive case I would appreciate an explanation in simple way, if with a small example for the one that, as I, am a little practical.

Thanks awfully.
Regards
David Chik from Japan  [31 posts] 4 years
Object_Name returns only the name of the largest object, but all other objects are stored in the Objects array. You need to tick Create Object Array under Variables in the object recognition module. Then open VBScripts module and try this:

objects = GetArrayVariable("OBJECTS")
names = GetStrVariable("OBJECTS_PATH")
if isArray(objects) then
  if ubound(objects) > 0 then
    for i=0 to ubound(objects)-1 step 15
      nstart = objects(i+13)
      nend = objects(i+14)
      write mid(names, nstart+1, nend-5) & vbCRLF
    next
  end if
end if

Anonymous 4 years
Thanks for the kind answer.

Then, if I, have TWO objects, and I want to give a condition according to the object that recognizes, or, to the recognition of both; how do I do to impute to a determined object that is found in an Array one determined action ?

e.g. If it recognizes "A" then you make an action - If recognizes "B" then you make another action - If it recognizes both the objects you still make a different action.

Thanks
David Chik from Japan  [31 posts] 4 years
If you run the previous code, you should see the name of all found objects, right?

The names of the objects are in this term: mid(names, nstart+1, nend-5)

so you can access them by defining  NowName = mid(names, nstart+1, nend-5)

Then you can write:
if NowName = "apple" then
   do something
   apple_exist = 1
else
   apple_exist = 0
end if

To see both objects, the easiest way is to add a variable apple_exist as in above, so you can do this:
if NowName = "orange" then
   if apple_exist = 1 then
     do something
  else
    do another thing
  end if
end if

Below I attach my previous code but it uses fiducials instead of objects, so you need to do some modification:

speed = 30
keep_distance = 7
halfwidth = GetVariable("IMAGE_WIDTH") / 2
fiducials = GetArrayVariable("FIDUCIALS")
names = GetStrVariable("FIDUCIALS_PATH")
if isArray(fiducials) then
  if ubound(fiducials) > 0 then
    for i=0 to ubound(fiducials)-1 step 17
      nstart = fiducials(i+15)
      nend = fiducials(i+16)

      NowName = mid(names, nstart+1, nend-5)

      if NowName = "arrow" then
        ArrowSize = fiducials(i+11)
        ArrowX = fiducials(i+9)
        if ArrowSize < keep_distance then
          leftMotor = 128 + speed * (ArrowX / halfwidth) + speed
          rightMotor = 128 - speed * (ArrowX / halfwidth) + speed
        else
          leftMotor = 128
          rightMotor = 128
        end if
      end if

      if NowName = "balcony" then
        BalconySize = fiducials(i+11)
        BalconyX = fiducials(i+9)
        if Abs(ArrowSize - BalconySize) < 1.5 then
          if Abs(ArrowX - BalconyX) < halfwidth then
              whatsong = "Indiana"
          end if
        end if  
      end if

      if NowName = "bedroom" then
        BedroomSize = fiducials(i+11)
        BedroomX = fiducials(i+9)
        if Abs(ArrowSize - BedroomSize) < 1.5 then
          if Abs(ArrowX - BedroomX) < halfwidth then
              whatsong = "Harry Potter"
          end if
        end if  
      end if

    next
  end if
end if
SetVariable "LEFT_MOTOR", leftMotor
SetVariable "RIGHT_MOTOR", rightMotor
SetVariable "PLAY_SONG", whatsong
Anonymous 4 years
Thanks very for the detailed answer, I will attentively study it, and I will try to put everything into practice.
I am a little practical and the code it will be useful to understand better. :-)
Regards.
Anonymous 4 years
Hi,
I have made a simple test with the following code to begin to understand the operation, but it doesn't work. Where have I been wrong ?

Contained of the Pipeline :

- 1) Object Recognition C:\User\Administrator\Pictures ......
- 2) VBScript Program :

objects = GetArrayVariable("OBJECTS")
names = GetStrVariable("OBJECTS_PATH")
if isArray(objects) then
  if ubound(objects) > 0 then
    for i=0 to ubound(objects)-1 step 15
      nstart = objects(i+13)
      nend = objects(i+14)
      write mid(names, nstart+1, nend-5) & vbCRLF

      NowName = mid(names, nstart+1, nend-5)

    next
  end if
end if

- 3) if NowName = "apple" then
- 4) Beep
- 5) end_if

It doesn't make the Beep.

In "Pictures" I have 3 images : "apple" , "orange" and "kiwi"

In the VBScript ("OBJECTS_PATH") it is correct ? ... or must write ("OBJECTS_NAME") ?

The recognized object should be memorized in the variable: NowName ?

I have used the module "If_Statement" to the point 3), because some commands, as the beep, don't work inside the form VBScript.
In fact I would have wanted to send some commands to the mouse, from the module VBScript, but I don't succeed. (e.g. To click to a position of the monitor)

Rest waiting for a kind answer.
Thanks.
Anonymous 4 years
I continue the post than above, have like if you could answer to my questions than above, in more, not to make you waste time, writes you directly a simple example (test) that I would want, with a lot of pleasure, to succeed in concluding :

I have 2 objects separated by to recognize: Apple and Orange
1) if it recognizes only the Apple it plays me the Beep.
2) if it recognizes the Apple + the Orange doesn't make any action.

I would like to make a Pipeline as the following :

- 1) Object Recognition
- 2) VBScript Program - if it is necessary
- 3) If_Statement (module) - in which to insert the conditions, for then, to make her perform in the following lines of the Pipeline
- 4) Beep - that it is activated if it recognizes the Apple.

It would be me very pleasant a practical example as that that you have already written me above.

I hope to have been brief.
Thanks still.
David Chik from Japan  [31 posts] 4 years
You should separate your tasks. You prepare one code for recognition (write out the variables so you can see if it works or not); another code for beep (so you will know how to play beep from vbscript); another for another things. When all parts work, then you can integrate them. If you do it all at once, it is difficult to debug.

Anonymous 4 years
Unfortunately I am not very practical and I don't succeed in understanding some things. (from few I am they study the operation of RR)
I am thankful if I can continue to have some suggestion to be able to continue to learn RR.

I would want to understand some points:

1) - in the Pipeline I have only a module VBScript in which I have written only the word: Beep . But it doesn't play.
Would I want to have a confirmation if the command Beep can work in the module VBScript, and as ?

2) - What it means:  "You prepare one tails for recognition (write out the variables......"  I must not use the module O_R ? , but I would not know whether to create the code that replaces the module O_R

3) - in the pipeline I have inserted 2 module :
    - O_R that perfectly works with a Confidence = 97%
    - VBS program with the following code :
--------
objects = GetArrayVariable ("OBJECTS")
names = GetStrVariable ("OBJECTS_PATH")
if isArray (objects) then
  if ubound (objects) > 0 then
    for i=0 to ubound (objects) -1 steps 15
      nstart = objects (i+13)
      nend = objects (i+14)
      write mid (names, nstart+1, nend -5) & vbCRLF

      NowName = mid (names, nstart+1, nend -5)

    next
  end if
end if
--------
but i have the window open of the VBS I don't read the variable NOwName from any part and therefore I don't know if she is valorized, as I can do for making a will if it works ?

Thanks, still for possible answers.
David Chik from Japan  [31 posts] 4 years
1)
First you open VBScript module and write:

SetVariable "whatfreq", 1000
SetVariable "howlong", 1000

click reload and run; then OK.

Then open Beep module; tick variable; in Frequency drop-down and select whatfreq; in Duration drop-down and select howlong; click OK.

Go back to VBScript module and you can click reload and run again.

3)
After opening the object recognition module and confirm it is working, you open VBScript module and enter the previous code and press reload and run. Please check: Near the bottom of the VBScript module there is a window called messages. If you show many objects in front of the camera, you should see ALL of them being listed in that window, right?

If the above is OK, then the next step, delete the sentence write mid (names, nstart+1, nend -5) & vbCRLF
but add the following lines below NowName = mid (names, nstart+1, nend -5)

If NowName = "apple" then
write "I see apple!!!"
else
write "I see nothing..."
end if

You should see "I see apple!!!" in the message window when you show the apple. Please note the filename of the training picture in the object folder must have the same name e.g. apple.jpg


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

If you continue to have issues, post what you have (i.e. your robofile) and we can better understand where your issue might be. Often a detail is left out that would be included in your robofile that may help.

STeven.
Guido from Italy  [7 posts] 4 years
I have attentively followed the instructions with all the "Reload and Run" to make a refresh of the module VBScript.

I attach you:

1) file.robo
2) a snap of the VBScript module opened and that it is in Running, with the objects in front of the cam (letter A and B)
3) another snap with the objects NOT in front of the cam

Unfortunately I stay me, as I don't read, in the window of the messages, the names of the objects that the cam reads me of time in time.
The names of the objects I read them only in the window "Available Variables."
I have made various tests, I have put then only in front of the cam an object, then, the other, both, but nothing to do.

- For memory I repeat the specific example of this that I would want to do:

1) only object "A" = Beep (or Mouse Module)
2) to the object "B" , object "A" is added = No Action
3) obviously only object "B" no action

If I succeed in understanding how to do, would be able, step after step, to make also complex things to according to my future necessity.

Regards and Thanks.

  

program.robo
Steven Gentner from United States  [1370 posts] 4 years
You need to enable the Array creation in the OR module ... otherwise the VBScript doesn't have anything to process.

See the attached robofile with that corrected and the logic to beep on A but not A and B.

STeven.
program.robo
Francesco from Italy  [20 posts] 4 years
I had not understood this thing, and now it work.

Following this post more other 2 that I have written with other questions, I have been able to establish that the software is all right for what I must realize.

Then I can also purchase it now.

I have trust of your help in the case I needed some suggestion.

Thanks.

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