Skip to content

Targeting functions

Tim Poulsen edited this page Feb 24, 2019 · 1 revision

Target identification and analysis are the core operations for a FIRST vision system. You might want to find the retroreflective tape that identifies the cargo hatches on the rocket, or for other games, marks a target at which you need to shoot a ball.

Basic usage

import robovision as rv
target = rv.Target()

Target functions

set_color_range — Specify the HSV color range to look for to identify the target. For the retroreflective tape and green LED rings typically used by FIRST teams, target.set_color_range(lower=(60, 100, 100), upper=(100, 255, 255)) typically works well.

get_contours — Detect and return contours surrounding colors between the lower and upper bounds.

get_rectangle — Returns the bounding rectangle for a contour, without considering the rotation of the enclosed object.

get_rotated_rectangle — Returns the rotated rectangle that encloses the provided contour. The returned value is a 3-tuple of these values:

[0] - x,y coordinates of the rectangle's center
[1] - height, width of the rectangle
[2] - rotation angle, if width < height add 90 to get "true" rotation

get_rotated_rectangle_as_boxpoints — Returns the box points for a rotated rectangle that encloses an object contained within the contour. Useful for drawing a rectangle on the image (though you could just draw the contour instead).

get_skew_angle — Returns the angle in degrees at which a contour is canted (same as the third member of the tuple returned by get_rotated_rectangle but with the width/height accounted for).

get_extreme_points — Get the leftmost, topmost, rightmost, and bottommost points of a contour.

get_solidity — Returns the solidity for a contour. Solidity is the ratio of contour area to its convex hull area. A ratio close to 1 means that the contour is generally contiguous and regularly shaped.

do_shapes_match — Determines if shapes match, ignoring rotation and scaling.

sort_contours — Sort counters according to how they appear in the field of view, such as left-to-right, right-to-left, top-to-bottom, or bottom-to-top.

Clone this wiki locally