Award
Congratulations bhouston, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Camera Detection Script Help

Assistance Requested

Help Steve G with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

Steve G claims to have checked these sources:
 
#1

Hey guys.

A little help is needed with a script. I am helping a friend out setting up their v4 camera and doing some object recognition. What my friend want's is, if nothing is recognized after 10 seconds, a script or part of a script runs. Here's an example of what is needed...

Code:

waitforchange($CameraObjectName,10000)
sayezbwait("I have identified, " +$CameraObjectName)
stop()

# If nothing is detected, the following should run
# which will shine an LED on the subject.

Servo(D5, 120)
Set(D6, On)
waitforchange($CameraObjectName,10000)
sayezbwait("I have identified, " +$CameraObjectName)
stop()


# If nothing is detected again after a further 10 seconds,
# the following phrase will be spoken.

SayEZB("Sorry. I could not recognize the object.")



I don't have my laptop with me, and I cannot figure out for the life of me what else is needed.

As always, I'd be grateful for any help filling in the gaps.

Steve. Smile

I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.


Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


#2

Here's a script that L. Vasquez posted awhile ago. It's a basic script that is easily changed for different types of object detection.

Code:


ControlCommand("Camera", CameraColorTrackingEnable)
ControlCommand("Camera", CameraColorTracking, "red")

Sayezb("i am looking for something red")

sleep(3000)

if($CameraHorizontalQuadrant = "Unknown")
Sayezb("no I do not see a red Object")


endif

if($CameraHorizontalQuadrant != "Unknown")
Sayezb("yes I do see a red object")


endif

sleep(7000)

ControlCommand("Camera", CameraColorTrackingDisable)
ControlCommand("Auto Position", AutoPositionAction, "Rest")

#3

Thanks Bob. I'll have a play around and give it a try.

#4

Thanks again Bob(and to Luis for sharing the script).

I had a quick play with the script Luis originally posted, and have the following script working well...

Code:

ControlCommand("Camera", CameraObjectTrackingEnable)
Sayezbwait("Camera detection, enabled.")

sleep(5000)

if($CameraHorizontalQuadrant = "Unknown")
Sayezbwait("Sorry. I could not recognize the subject.")
endif

if($CameraHorizontalQuadrant != "Unknown")
Sayezbwait("I have identified, " +$CameraObjectName)
endif

sleep(1000)
ControlCommand("Camera", CameraObjectTrackingDisable)



A I mentioned, it works well but I would like to add a "wait for change" command in somewhere so as soon as the object is recognized, it will say what the object is. At the moment, you have to wait for the 5 second time out to be reached, so if an object is detected at the 3 second mark, and then the recognition is lost at the 4 or 5 second mark, the "object cannot be detected" phrase is spoken (I hope that makes sense). I had a play around adding a wait for change command, but no joy. If I can get this bit sorted, then I'll add what is needed to be done such as "Goto's" for the script posted in post #1 for my friends project.

Anybody have any ideas how to achieve this?

#5

I wrote a script for my friend (I may actually use this in K-9 and E4-B4 as well), and thought I'd share it here too for anyone who is interested. Smile

Code:

# The first part starts object tracking after a two second pause.
#If recognized, the object name will be spoken
#and stop object tracking.

ControlCommand("Camera", CameraObjectTrackingEnable)
sleep(2000)
if($CameraIsTracking)
sayezbwait("" +$CameraObjectName)
ControlCommand("Camera", CameraObjectTrackingDisable)


# If object is not recognizes, object tracking will disable to refresh
#then restart again to track for 10 seconds. A torch will deploy
#to shine light on subject to improve recognition. If recognized,
#the object name will be spoken and torch will turn off.
#If object is not recognized, nothing is said and torch turns off.

else
ControlCommand("Camera", CameraObjectTrackingDisable)
sleep(2000)
SayEZBwait("I cannot see the subject properly. Let me try again. ")
ControlCommand("Script Manager", ScriptStart, "Deploy Torch")
sleep(4500)
ControlCommand("Camera", CameraObjectTrackingEnable)
waitforchange($CameraObjectName,10000)
sayezbwait("" +$CameraObjectName)
sleep(1000)
ControlCommand("Script Manager", ScriptStart, "Retract Torch")
sleep(3000)
endif

# Object recognition will now disable.

ControlCommand("Camera", CameraObjectTrackingDisable)



I would still like to find a way to add a third instance where if the second part of the script is not met after 10 seconds, a phrase is spoken to say that the object needs to be trained or something. I tried using elements from the script in post #2, but so far my efforts have failed.

One question for DJ if you're reading. Would it be possible to implement the option to delete individually trained objects from the camera control at some point, rather than deleting everything and retraining the one's we want to keep. Thanks. Winky

#6

Just butting in here. Smile

Before I can be of assistance, I would need to ask a few questions since I've not worked with the object recognition thing yet.

1) In the line near the start of the code which says:
if($CameraIsTracking)

Should that be:
if($CameraIsTracking =True)

Or does it work OK the way it is? Usually there always has to be a =True or =False in there.

2) In the section after the Else, about mid way down:

Code:


waitforchange($CameraObjectName,10000)
sayezbwait("" +$CameraObjectName)



It looks like it will say whatever is in $CameraObjectName regardless if the object was recognized or not. Is that what is wanted?

3) When you say:

Quote:


... third instance where if the second part of the script is not met after 10 seconds, a phrase is spoken to say that the object needs to be trained or something.


Is the 10 seconds mentioned, the 10 seconds that will pass if the waitforchange line goes the full 10 seconds without a recognition? That is to say, it times out.

Finally, I believe the data for the learned objects should be in the EZB file along with everything else. Which means it should be possible to find it by searching through the EZB file. I already have a program to do this for the data associated with the Speech Recognition control. The program finds the control and copies the data stored in the control and presents it for modification. It then can replace the existing data there with the modified data. By "Data" I mean the scripts stored in it for what to do when a given phrase is spoken. It was part of my methodology to totally remove the data from the Speech Recognition control and place it in separate scripts for processing instead.

Anyway, it should be possible to modify it to do the same thing for the learned objects. This would allow one, or more to be deleted from that data and then the whole thing replaced, effectively deleting just the one (or more) objects from the group.

Additionally, the program, as it stands now, can save the data to a file. I had thought to use that so as to be able to load different sets of data to a given project. For example, the same things, but in a different language. Then I discovered the "Merge" function in EZ-Builder so that wasn't so important to pursue any longer. Still, that could also be done for the learned objects data.

#7

Hi WBS, and thanks for the response. I'll go through the questions one by one...

Quote:

1) In the line near the start of the code which says:
if($CameraIsTracking)

Should that be:
if($CameraIsTracking =True)

Or does it work OK the way it is? Usually there always has to be a =True or =False in there.



It does work okay this way, but the object has to be recognised immediately when the end of the 2 second sleep is reached or it won't return the objects name. I believe you can also use a "True/False" or "0/1" with this command as well. I actually did give this a try but couldn't getting it working the way I wanted to correctly.

Quote:

It looks like it will say whatever is in $CameraObjectName regardless if the object was recognized or not. Is that what is wanted?



Not so. When the first part of the script runs and nothing is detected, the "I'll try again" phrase is spoken. Then the second part of the script runs. If the object is recognised within the 10 seconds, then the name of that object will be spoken. If after the 10 second timeout nothing is recognised, nothing is said.

Quote:

Is the 10 seconds mentioned, the 10 seconds that will pass if the waitforchange line goes the full 10 seconds without a recognition? That is to say, it times out.



Yes. The 10 second WaitForChangetimeout for the second half of the script is correct.

As for he deleting of the saved images, when you click on an image, you get a message confirming you wish to proceed. When excepting, another window pops up saying that this option has not been implemented yet and you have to use the clear everything option. I remember this was mentioned a few months ago by someone and DJ said put it in a future update. I was just wondering about an ETA. But thanks for the advice though. I'll have a look at the EZ Builder file and see if I can delete individual images.

Thanks again.

#8

Quote:


Not so. When the first part of the script runs and nothing is detected, the "I'll try again" phrase is spoken. Then the second part of the script runs. If the object is recognised within the 10 seconds, then the name of that object will be spoken. If after the 10 second timeout nothing is recognised, nothing is said.


I see, I think. So if nothing is recognized the $CameraObjectName variable is blank. If it times out then, it is also blank.

Could you not use that to test for the third instance you wanted?

Code:


waitforchange($CameraObjectName,10000)

if($CameraObjectName ="")
SayEZBWait("I will need training to recognize that object.")
else
sayezbwait("" +$CameraObjectName)
endif



Or maybe I don't quite understand what you meant.

FWIW, as a possible alternative:

Code:


$CameraObjectName ="I will need training to recognize that object."
WaitForChange($CameraObjectName ,10000)
SayEZBWait("" +$SpeechPhrase)



If nothing is recognized after 10 seconds, it will say the "I will need ..." text. If something is recognized, it will say the object name instead instead.

#9

I looks like you got the gist of it. I'll have a go with the examples you've supplied and try again.

Thanks. Smile