ovl.math.contours module

ovl.math.contours.calculate_normalized_screen_space(contours: Union[List[numpy.ndarray], numpy.ndarray], image)[source]
Parameters:
  • contours
  • image
Returns:

ovl.math.contours.circle_rating(contour, area_factor=0.9, radius_factor=0.8)[source]

Returns a rating of how close is the circle to being a circle

Parameters:
  • contour – the contour that its rating is calculated
  • area_factor – the factor (p-value) that separates an area ratio that is a circle and one that isn’t
  • radius_factor – the factor (p-value) that separates an radius ratio that is a circle and one that isn’t
Returns:

the circle rating for the given contour

ovl.math.contours.contour_approximation(contour, approximation_coefficient=0.02)[source]

Returns the approximation of the contour

Parameters:
  • contour – a numpy array
  • approximation_coefficient – the coefficient of the contour length approximation
Returns:

ovl.math.contours.contour_average_center(contours) → Tuple[float, float][source]

Calculates the average center of a list of contours

Parameters:contours – the list of contours
Returns:the average center (x,y)
ovl.math.contours.contour_average_color(contours: List[numpy.ndarray], image: numpy.ndarray)[source]

Calculates the average color (in hsv) of all the pixels of a list of contours in the image.

Parameters:
  • contours – a list of contour(s) detected in the image
  • image – the image where the contours where detected, numpy array
Returns:

hsv color (h, s, v) tuple of the average color

ovl.math.contours.contour_center(contour: numpy.ndarray) → Tuple[float, float][source]

Returns the coordinates center of a contour

Parameters:contour – a single contour
Returns:X coordinate of center, Y coordinate of center
ovl.math.contours.contour_lengths_and_angles(contour, approximation_coefficient=0.02)[source]

Returns a list of lengths and angles of a given contour.

Parameters:
  • contour – contour (numpy array) to find its
  • approximation_coefficient
Returns:

returns the list of sides

ovl.math.contours.crop_contour_region(contour: numpy.ndarray, image: numpy.ndarray)[source]

Returns a region of the image where the contour (using its bounding box)

Parameters:
  • contour – the object found in the image, a numpy array
  • image – the image from which the contour was found
Returns:

the image region that contains the contour

ovl.math.contours.open_arc_length(contour: numpy.ndarray) → float[source]

Returns the arc length of an “open” contour

ovl.math.contours.open_contour_approximation(contour: numpy.ndarray, approximation_coefficient: float = 0.02)[source]

Returns the vertices of the approximation of the contour NOTE: for “open” (unclosed shape) contours only!

Parameters:
  • contour – open contour (numpy array)
  • approximation_coefficient – approximation coefficient
Returns:

list of vertices

ovl.math.contours.target_size(contours: List[numpy.ndarray]) → float[source]

Returns the sum of contour areas of a list of contours