Table of Contents

setthreshold()

Function Definition: setthreshold(threshold = 0.5)

Parameters

NameTypeDescriptionExpected ValuesDefault Value
thresholdfloatConfidence value. 0 being low confidence and 1 being high confidence.0-10.5

Description

This function is used to set the threshold for the confidence (accuracy) of face detection, 0 being low confidence and 1 being high confidence.

With the threshold value, you can set the level of confidence required for face detection.

At 0.4 threshold:

At 0.9 threshold:

Tip: Use this block with a lower threshold if you are not able to detect objects due to dim light, partial appearance of the object, etc.

Example

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 code logic for video input detection with this example code. You will be able to direct your own Mars Rover easily by just showing signs through the camera input.

Introduction

A sign detector Mars Rover robot is a robot that can recognize and interpret certain signs or signals, such as hand gestures or verbal commands, given by a human. The robot uses sensors, cameras, and machine learning algorithms to detect and understand the sign, and then performs a corresponding action based on the signal detected.

These robots are often used in manufacturing, healthcare, and customer service industries to assist with tasks that require human-like interaction and decision making.

Code

sprite = Sprite('Tobi')
# sprite = Sprite('Tobi')
quarky = Quarky()
import time

recocards = RecognitionCards()
rover = MarsRover(4, 1, 7, 2, 6)

recocards.video("on flipped")
recocards.enablebox()
recocards.setthreshold(0.6)

while True:
  recocards.analysecamera()
  sign = recocards.classname()
  sprite.say(sign + ' detected')
  
  if recocards.count() > 1:
    if 'Go' in sign:
      rover.home()
      rover.setinangle(0)
      quarky.runtimedrobot("F",100,3)
      
    if 'Turn Left' in sign:
      rover.home()
      rover.setinangle(40)
      quarky.runtimedrobot("L",100,3)

    if 'Turn Right' in sign:
      rover.home()
      rover.setinangle(40)
      quarky.runtimedrobot("R",100,3)
      
    if 'U Turn' in sign:
      rover.home()
      rover.setinangle(0)
      quarky.runtimedrobot("B",100,3)

Logic

  1. Firstly, the code sets up the stage camera to look for signs and detects and recognizes the signs showed on the camera.
  2. Next, the code starts a loop where the stage camera continuously checks for the signs.
  3. Finally, if the robot sees certain signs (like ‘Go’, ‘Turn Left’, ‘Turn Right’, or ‘U Turn’), it moves in a certain direction (forward, backward, left, or backward) based on the respective signs.
  4. This can help the Mars Rover to manoeuvre through the terrain easily by just showing signs on the camera.

Output

Forward-Backward Motions:

Right-Left Motions:

Read More
Learn about face-tracking, and how to code a face-tracking Quadruped robot using sensors and computer vision techniques.

Introduction

A face-tracking robot is a type of robot that uses sensors and algorithms to detect and track human faces in real time. The robot’s sensors, such as cameras or infrared sensors, capture images or videos of the surrounding environment and use computer vision techniques to analyze the data and identify human faces. One of the most fascinating activities is face tracking, in which the Quadruped 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 Quadruped robot.

we will learn how to use face detection to control the movement of a Quadruped robot and how to incorporate external inputs into a program to create more interactive and responsive robotics applications.

Logic

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

Code

sprite = Sprite('Tobi')
quarky=Quarky()

import time
import math
quad=Quadruped(4,1,8,5,3,2,7,6)

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:
      quad.move("lateral right",1000,1)
    elif angle<90:
      quad.move("lateral left",1000,1)
    else:
      quad.home()

Code Explanation

  1. First, we import libraries and create objects for the time and math.
  2. Next, we set up the camera and enable face detection with a 0.5 threshold.
  3. Based on this information, We use a loop to continuously analyze the camera feed for faces and control the humanoid’s movement.
  4. When a face is detected, the quadruped sprite moves to the face’s location and the angle of the face is used to determine the direction of movement.
  5. The Quadruped moves to the left if the angle is greater than 90 degrees.
  6. The Quadruped moves to the right if the angle is less than 90 degrees.
  7. If the angle is exactly 90 degrees, the Qudruped returns to its original position.

Output

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  Quadruped robot should also move accordingly.

Read More
All articles loaded
No more articles to load