Table of Contents

count()

Function Definition: count()

Parameters

Description

This function displays the total number of faces detected in the camera feed or the stage.

Example

The project detects the number of faces detected on the stage.

Code

sprite = Sprite('Tobi')

fd = FaceDetection()

# Enable Bounding Box on the stage
fd.enablebox()

# Set Theshold of the stage
fd.setthreshold(0.9)

fd.analysestage()

sprite.say(str(fd.count()) + " Faces Detected")

Output

Read More
The example demonstrates the application of face detection with a stage feed.

The example demonstrates the application of face detection with a stage feed. Following are the key steps happening:

  1. Initializing the program with parameters for the sprite and face detection library.
  2. Running face detection
  3. Running the loop to show every face and its expression

Code

sprite = Sprite('Square Box')
import time
fd = FaceDetection()

# Disable Bounding Box on the stage
fd.disablebox()

# Set Theshold of the stage
fd.setthreshold(0.4)

fd.analysestage()

print(fd.count())

for i in range(fd.count()):
  sprite.setx(fd.x(i + 1))
  sprite.sety(fd.y(i + 1))
  sprite.setsize(fd.width(i + 1))
  sprite.say("Face " + str(i + 1) + ": " + fd.expression(i + 1))
  time.sleep(1)

Output

 

Read More
The example demonstrates how to use face detection with a camera feed.

The example demonstrates how to use face detection with a camera feed. Following are the key steps happening:

  1. Initializing the program with parameters for the sprite, and face detection library.
  2. Running face detection.
  3. Running the loop to show every face and expression.

Code

sprite = Sprite('Square Box')
import time
fd = FaceDetection()

fd.video("on", 0)

# Enable Bounding Box on the stage
fd.enablebox()

# Set Theshold of the stage
fd.setthreshold(0.5)

while True:
  fd.analysestage()

  for i in range(fd.count()):
    sprite.setx(fd.x(i + 1))
    sprite.sety(fd.y(i + 1))
    sprite.setsize(fd.width(i + 1))
    sprite.say(fd.expression(i + 1))

Output

Read More
Learn how to use face detection to control humanoid robot movements for interactive and responsive robotics applications. Get started now!

Introduction

One of the most fascinating activities is face tracking, in which the Quarky can detect a face and move its head in the same direction as yours. How intriguing it sounds, so let’s get started with the coding for a face-tracking robot.

Logic

  1. If the face is tracked at the center of the stage, the humanoid should be straight.
  2. As the face moves to the left side, the humanoid will also move to the left side.
  3. As the face moves to the right side, the humanoid will also move to the right side.

Code

sprite = Sprite('Tobi')
quarky=Quarky()
import time
import math
humanoid = Humanoid(7,2,6,3,8,1)

fd = FaceDetection()
fd.video("on", 0)
fd.enablebox()
fd.setthreshold(0.5)
time.sleep(1)
Angle=0
while True:
  fd.analysestage()
  for i in range(fd.count()):
    sprite.setx(fd.x(i + 1))
    sprite.sety(fd.y(i + 1))
    sprite.setsize(fd.width(i + 1))
    Angle=fd.width(i + 1)
    angle=int(float(Angle))
    if angle>90:
      humanoid.move("left",1000,3)
    elif angle<90:
      humanoid.move("right",1000,3)
      time.sleep(1)
    else:
      humanoid.home()

Code Explanation

  1. First, we import libraries and create objects for the robot.
  2. Next, we set up the camera and enable face detection with a 0.5 threshold.
  3. We use a loop to continuously analyze the camera feed for faces and control the humanoid’s movement based on this information.
  4. When a face is detected, the humanoid sprite moves to the face’s location, and the angle of the face is used to determine the direction of movement.
  5. If the angle is greater than 90 degrees, the humanoid moves to the left.if angle is less than 90 degrees, the humanoid moves to the right.if angle is  exactly 90 degrees, the humanoid returns to its original position.
  6. This code demonstrates how to use face detection to control the movement of a humanoid robot and how to incorporate external inputs into a program to create more interactive and responsive robotics applications.

Output

Read More
All articles loaded
No more articles to load