Asked — Edited
Resolved Resolved by Rich!

Using The Camera As A Button

I ran across a neat project online that uses a web camera as a button for application. The functionality is nothing too wild as the code takes the camera values and if the image detection meets a threshold of darkness (like you block the camera with your hand) that registers as a button press and you make the app do what you want from there, like open or close a window or play music or whatever.

I thought, why can't ARC do this? I created a custom multicolor named "Dark" and set it the darkest shade of blue with a narrow scope. The result is most of the time it will only detect my multicolor "Dark" if the camera is blocked with my hand. Sometimes it see that color flash by looking around the room.

Has anyone else done this? Is there a better way to achieve this in ARC?

Below is my script to trigger a sound file from a sound board when the custom multicolor is detected incase anyone would like to see it as an example.


$CameraObjectColor = ""

:Start
IF ($CameraObjectColor = "Dark")
    ControlCommand("Bender Sounds and Noises", Track_22)
ENDIF 

$CameraObjectColor = ""
sleep(5000)

goto(start)


ARC Pro

Upgrade to ARC Pro

Elevate your robot's capabilities to the next level with Synthiam ARC Pro, unlocking a world of possibilities in robot programming.

United Kingdom
#1  

I'd personally use the camera variables for the object sizes too which would reduce the false positives.

Also, and bear in mind I'm only quickly looking here, but your code will reset the $CameraObjectColor variable on each loop and wait 5 seconds for the loop. Which may mean the hand would need to be over the camera for up to 5 seconds for it to work.

There is a script command called WaitForChange($variable) which would work better. It will hold the script at that line until the variable value is changed. Since the variable may provide a value which may not be "dark" you may want to add in another variable which sets to 1 if the $CameraObjectColor is "dark" and 0 if it isn't. Then use that variable in the WaitForChange. It would mean having another script looping too which would constantly (or with a slight sleep) monitoring the variable and setting the 0 or 1 as appropriately.

Something like;

:loop
IF($CameraObjectColor = "dark")
  $SwitchVariable = 1
Else
  $SwitchVariable = 0
EndIf
Sleep(100)
Goto(loop)

And the main script just throw a WaitForChange($SwitchVariable) in there to hold it before the IF.

PRO
Synthiam
#2  

Multi color will be a good idea. If you set the size to be large, it would prevent false positives.

#3  

Thanks Rich and DJ, I overlooked the size option. Works much better. Tutorial and video coming soon.

Another camera question I have is, what is the proper variable that changes when a face is detected when using face tracking? I know $CameraTrackingType will change to "Face" if a face is detected. And if a face is being tracked the $CameraIsTracking will change from 0 to 1 (or maybe higher for more faces?) but that change seems to happen rather slow, like not as fast as when the colored box appears in the camera preview window. Are those the only two system variables that change when a face is detected?

PRO
Synthiam
#4  

Configure the drop down for how many frames before object is considered tracked. The configure button on all controls opens a menu for options. There are lots of options on the camera control:) I put blue question marks on every option. Hover your cursor on the blue question mark.

#5  

The blue question marks are helpful as is the configuration options for most of the objects in ARC.

The drop down you mentioned is from the Motion tab, correct?

User-inserted image

PRO
Synthiam
#6  

No, that is a value specific to the motion tracking method. The configure button is a gear and found on all controls. Pressing the gear will open a configuration menu for each control.

#7  

Under the configuration menu I'm not seeing an option for that. I assume it's not on the main "settings" tab as those options relate to the robot's physical control.

User-inserted image

I don't believe it would be the tracking option under scripts because I'm not kicking off a script.

User-inserted image

Can you tell me where the "drop down for how many frames before object is considered tracked" is located?