ACTIVITY: FACE TRACKING WITH ROBOT
In this activity, we are going to make the robot detect the face and track it.
LOGIC
STEP-BY-STEP
Follow the steps below:
- Create a New file in PictoBlox App. Connect Quarky to PictoBlox.
- Drag and drop the when green flag clicked block from the Events
- Then, add a turn () video on stage with () % transparency block from the Face Detection extension and select one from the drop-down. This will turn on the camera.
- Add the forever block below turn () video on stage with () % transparency from the Control
- Inside the forever block, add an analyse image from () This block will analyze the face the camera detects. Select camera from the dropdown.
- To change the position of your servo, add the set servo on () to () angle below analyse image from ().
- Add the division () / ()block from the Operator palette into the scripting area.
- Place get () of face () at the first place of addition () + (), and 3 at the second place. From the dropdown select X position.
- Next, drag the addition ()+()block inside the set servo () to () angle Put 90 in the first space and put the ()/() block in the second space.
SERVO BLOCK EXPLAINED
- At the center of the stage, we will get the X position value which is zero.
- As we move to the left side the X position value will give you the negative value and as we move to the right side the X position value will give you the positive value.
- The x position value is divided by 3 which gives precise positioning.
- To set the servo angle at 90 when the face is at the center of the stage, we have added 90 to the X position value.
- As we move to the left side the servo angle value will get decreased as the X position value is going in negative.
- As we move to the right side the servo angle value will get increased as the X position value is going in positive.
Our next step is to check whether it is working right or not. Whenever your face will come in front of the camera, it should detect it and as you move to the right or left, the head of your robot should also move accordingly.