Table of Contents

Function Definition: width(object = 1)

Parameters

NameTypeDescriptionExpected ValuesDefault Value
objectintObject number for which the information is required.1-1001

Description

This function returns the width of the object detected. You can specify the object for which the value is needed. The position is mapped with the stage coordinates.

Example

The example demonstrates how to run an object detection on the stage and show all the objects with confidence.

Code

sprite = Sprite('Square Box')
obj = ObjectDetection()

obj.disablebox()
obj.setthreshold(0.5)
obj.analysestage()

sprite.gotoxy(0, 0)
sprite.setsize(100)
sprite.say(str(obj.count()) + " Object Detected", 2)

for object in range(1, obj.count() + 1):
  sprite.setx(obj.x(object))
  sprite.sety(obj.y(object))
  sprite.setsize(obj.width(object))
  sprite.say(obj.classname(object) + " with " + str(obj.confidence(object)), 2)

Output

  1. Detection at 0.3
  2. Detection at 0.5
  3. Detection at 0.8
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