Vision Library

Back to docs

The sr.robot library contains support for detecting libkoki markers with the provided webcam. Markers are attached to various items in the RoboCon Arena. Each marker encodes a number in a machine-readable way, which means that robots can identify these objects. For information on which markers codes are which, see the markers page.

Using knowledge of the physical size of the different markers and the characteristics of the webcam, libkoki can calculate the position of markers in 3D space relative to the camera. Therefore, if the robot can see a marker that is at a fixed location in the arena, a robot can calculate its exact position in the arena.

The sr.robot library provides all of this power through a single function, R.see:

from sr.robot import *
R = Robot()
markers = R.see()

When called, this function takes a photo through the webcam and searches for markers within it. It returns a list of Marker objects, each of which describes one of the markers that were found in the image. A detailed description of the attributes of Marker objects is provided later in this page.

Here’s an example that will repeatedly print out the distance to each token marker that the robot can see:

from sr.robot import *
R = Robot()

while True:
    markers = R.see()
    print "I can see", len(markers), "markers:"

    for m in markers:
        print " - Marker #{0} is {1} metres away".format( m.info.code, m.dist )

 

 

Note: The code detects MARKERS. If a token is positioned in such a way that more than one face is available to the camera, it will return the number of markers it can see, NOT cubes. (unless you have a system implemented to check the tokens present using token IDs).

DEFINITION OF AXES

The vision system describes the markers it can see using three coordinate systems. These are intended to be complementary to each other and contain the same information in different forms.

The individual coordinate systems used are detailed below on the Point object, which represents a point in space. Both it and the Orientation object provide further details about what measurements of rotation or position mean for their attributes.

The axis definitions match those in common use, as follows:

x-axis
The horizontal axis running left-to-right in front of the camera. Rotation about this axis is equivalent to leaning towards or away from the camera.
y-axis
The vertical axis running top-to-bottom in front of the camera. Rotation about this axis is equivalent to turning on the spot, to the left or right.
z-axis
The axis leading away from the camera to infinity. Rotation about this axis is equivalent to being rolled sideways.
Note that the axes are all defined relative to the camera. Since we have no way to know how you’ve mounted your camera, you may need to account for that in your usage of the vision system’s data.

OBJECTS OF THE VISION SYSTEM

MARKER

Marker object contains information about a detected marker. It has the following attributes:

info
MarkerInfo object containing information about the type of marker that was detected.
centre
Point describing the position of the centre of the marker.
vertices
A list of 4 Point instances, each representing the position of the black corners of the marker.
dist
An alias for centre.polar.length
rot_y
An alias for centre.polar.rot_y
orientation
An Orientation instance describing the orientation of the marker.
res
The resolution of the image that was taken from the webcam. A 2-item tuple: (width, height).
timestamp
The timestamp at which the image was taken (a float).

MARKERINFO

The MarkerInfo object contains information about a marker. It has the following attributes:

code
The numeric code of the marker.
marker_type
The type of object that this marker represents.
One of:

  • MARKER_ARENA
  • MARKER_TOKEN
  • MARKER_BUCKET_SIDE
  • MARKER_BUCKET_END
offset
The offset of the numeric code of the marker from the lowest numbered marker of its type. For example: markers 32 and 33, which are the lowest numbered markers that represent tokens, have offsets of 0 and 1 respectively.
size
The size of the marker in metres. This is the length of the side of the main black body of the marker.

POINT

Point object describes a position in three different ways. These are accessed through the following attributes:

image
The pixel coordinates of the point in the image, with the origin (0,0) in the top-left of the image. This has two attributes: x and y.
world
The Cartesian coordinates of the point in 3D space. This has three attributes: xy, and z, each of which specifies a distance in metres. Positions in front of, to the right, or above the camera are positive. Positions to the left or below are negative.
polar
The polar coordinates of the point in 3D space.
This has three attributes:

length
The distance to the point.
rot_x
Rotation about the x-axis in degrees. Positions above the camera are positive.
rot_y
Rotation about the y-axis in degrees. Positions to the right of the camera are positive.

For example, the following code displays the polar coordinate of a Point object p:

print "length", p.polar.length
print "rot_x", p.polar.rot_x
print "rot_y", p.polar.rot_y

ORIENTATION

An Orientation object describes the orientation of a marker. It has three attributes:

rot_x
Rotation of the marker about the x-axis.Leaning a marker away from the camera increases the value of rot_x, while leaning it towards the camera decreases it. A value of 0 indicates that the marker is upright.
rot_y
Rotation of the marker about the y-axis.Turning a marker clockwise (as viewed from above) increases the value of rot_y, while turning it anticlockwise decreases it. A value of 0 means that the marker is perpendicular to the line of sight of the camera.
rot_z
Rotation of the marker about the z-axis.Turning a marker anticlockwise (as viewed from the camera) increases the value of rot_z, while turning it clockwise decreases it. A value of 0 indicates that the marker is upright.
Last Updated On March 03, 2018