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.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).


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:

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.
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.
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.



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

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


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

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

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.
The size of the marker in metres. This is the length of the side of the main black body of the marker.


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

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.
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.
The polar coordinates of the point in 3D space.
This has three attributes:

The distance to the point.
Rotation about the x-axis in degrees. Positions above the camera are positive.
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


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

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.
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.
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