Table of Contents

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 object detection, 0 being low confidence and 1 being high confidence.

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

Example

The example demonstrates how to detect persons on the stage with different confidence thresholds.

Code

sprite = Sprite('Tobi')
obj = ObjectDetection()

obj.enablebox()
sprite.gotoxy(-180, -110)
sprite.setsize(100)

obj.setthreshold(0.3)
obj.analysestage()
sprite.say(str(obj.detectedcount("person")) + " Person Detected at 0.3 Threshold", 2)

obj.setthreshold(0.5)
obj.analysestage()
sprite.say(str(obj.detectedcount("person")) + " Person Detected at 0.5 Threshold", 2)

obj.setthreshold(0.9)
obj.analysestage()
sprite.say(str(obj.detectedcount("person")) + " Person Detected at 0.9 Threshold", 2)

Output

Read More
Learn how to code logic for video input detection with this example code. You will be able to direct your own Mecanum easily by just showing signs through the camera input.

Introduction

A sign detector Mecanum 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')
quarky = Quarky()
import time
meca=Mecanum(1,2,7,8)
recocards = RecognitionCards()

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:
      meca.runtimedrobot("forward",100,2)
    if 'Turn Left' in sign:
      meca.runtimedrobot("lateral left",100,2)
    if 'Turn Right' in sign:
      meca.runtimedrobot("lateral right",100,2)
    if 'U Turn' in sign:
      meca.runtimedrobot("backward",100,2)

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 Mecanum to manoeuvre through the terrain easily by just showing signs on the camera.

Final Output

Forward Motion:

Right-Left Motions:

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