ovl.visions.ambient_vision module

class ovl.visions.ambient_vision.AmbientVision(main_vision: ovl.visions.vision.Vision, ambient_vision: ovl.visions.vision.Vision, main_amount: int, start_ambient: bool = False)[source]

Bases: object

A mesh of 2 vision objects that extends one of the visions at a time.

The visions are swapped every main_amount of update_vision calls. This makes the “ambient_vision” run in the background once every multiple frames.

The example includes only general instructions, 2 vision objects need to be defined to detect something

An example will be as follows:

vision1 = Vision(....)

vision2 = Vision(....)

vision_controller = AmbientVision(main_vision=vision1, ambient_vision=vision2, main_amount=3)

while True:
    image = vision_controller.get_image()

    contours, image = vision_controller.detect(image)

    vision_controller.update_vision()

you can get the current vision object using vision_controller.current_vision

apply_image_filters(image: numpy.ndarray) → numpy.ndarray[source]

Applies all of the image filter of the current vision on the given image

See Vision.apply_image_filters for more information

apply_morphological_functions(mask: numpy.ndarray) → numpy.ndarray[source]

Applies the current vision’s morphological functions on a binary mask (numpy ndarray)

See Vision.apply_morphological_functions for full description

connection
detect(image: numpy.ndarray, verbose=False) → Tuple[List[numpy.ndarray], numpy.ndarray][source]

Gets contours and applies all filters and returns the result, thus detecting the object according to the specifications in the vision, Uses the current vision

Parameters:
  • image – image in which the vision should detect an object
  • verbose – if true prints additional information about contour filtering
Returns:

contours, ratio list (from the filter functions) and the filtered image

directions
find_contours(image: numpy.ndarray, threshold=None, return_hierarchy=False) → List[numpy.ndarray][source]

Find contours in the given image, using the current vision.

See Vision.find_contours for full description

find_contours_in_mask(mask: numpy.ndarray, save: bool = True, return_hierarchy: bool = False) → List[numpy.ndarray][source]

Returns a list of contours from a given binary mask (numpy ndarray), using the current vision

See Vision.find_contours_in_mask for full description

get_directions(contours, image, sorter=None)[source]

Returns the directions for the given image and contours using the current vision

Parameters:
  • contours – the final contours detected.
  • image – the image where the contours were detected in.
  • sorter – a sorter function that can be added to be applied before getting directions
Returns:

the directions

get_image() → numpy.ndarray[source]

Take a picture using the current vision

See Vision.get_image for more information

image_filters
send(data, *args, **kwargs)[source]

Sends a given value to the current vision’s connection object

Parameters:
  • data – the data to be sent
  • args – any other parameters to the specific connection object
  • kwargs
Returns:

Whatever the underlying connection object returns, usually the parameter data

threshold
update_vision()[source]

Increases the inner counter and swaps the ambient and the main vision after the set number of updates (self.main_amount)

This is used to switch between the main vision and ambient vision