ocvu.contour module

class ocvu.contour.Contour(contour)[source]

Bases: object

Provides a user-friendly object defining a contour in OpenCV. Adapted from: http://answers.opencv.org/question/6043/segmentation-and-contours/

approx

Lorem

area

Contour.area - Area bounded by the contour region

bounding_box

Lorem

centroid
diameter

EquivDiameter: diameter of circle with same area as region

draw(image, **kwargs)[source]

Draw contour. kwargs are passed to cv2.rectangle method. Default color is green.

draw_approx(image, **kwargs)[source]

Draw approximated contour. kwargs are passed to cv2.rectangle method. Default color is red.

draw_bounding_box(image, **kwargs)[source]

Draw contour’s bounding box on image. kwargs are passed to cv2.rectangle method. Default color is white.

draw_centroid(image, radius=3, **kwargs)[source]

Draw contour’s centroid. kwargs are passed to cv2.circle method.

draw_ellipse(image, **kwargs)[source]

Draw contour’s ellipse. kwargs are passed to cv2.circle method.

draw_hull(image, **kwargs)[source]

Draw convex hull. kwargs are passed to cv2.rectangle method. Default color is blue.

ellipse

Fits an ellipse and returns the rotated rectangle in which the ellipse is inscribed.

The returned value is the tuple: ((x, y), (major_axis, minor_axis), angle)

hull

Lorem

moments

Lorem

perimeter

Lorem

position

Top left coordinate of the contour bounding box.

ocvu.contour.find_biggest_contours(mask, n=1, area_min=None, **kwargs)[source]

Returns the n biggest contours in mask. Returns a list of contours sorted by area in descending order. If you provide a minimal area value, contours returned will be filtered like so.