ovl.visions.multi_vision module

class ovl.visions.multi_vision.MultiVision(visions: Union[List[Union[Vision, AmbientVision]], Dict[Any, Union[Vision, AmbientVision]]], update_connection: ovl.connections.connection.Connection, update_location: Optional[ovl.connections.network_location.NetworkLocation] = None, default_vision=0)[source]

Bases: object

An object used to switch between multiple vision objects. It does this by having a list of visions and a connection and network_location to update from So it can be automatically updated to swap to the desired Vision object use the start method to start an infinite loop that returns images and detections

connection = ovl.NetworkTablesConnection(1937)

vision1 = ovl.Vision(....)
vision2 = ovl.Vision(....)
vision3 = ovl.Vision(....)

update_location = ovl.NetworkLocation(table_key="current_vision")

multi_vision = ovl.MultiVision([vision1, vision2, vision3], connection, update_location)

for directions, contours, image  in multi_vision.start():

    # do something with the generated data

    # like sending the data or displaying the contours

    multi_vision.send(directions)

    ovl.display_contours(image, contours, delay=1)
is_ambient() → bool[source]
Returns True if the current_vision vision is an Ambient vision object
Returns:if the current vision is an AmbientVision
send(data, *args, **kwargs) → Any[source]

Sends the value to the target destination of the current_vision vision object

Parameters:data – the data to be sent
Returns:depends on the connection object
set_vision(index)[source]

Sets the current to the given index

Parameters:index – the index to set
Returns:the index
start(yield_ratios=False) → Generator[Tuple[List[numpy.ndarray], numpy.ndarray, Any], None, None][source]

A function that starts an infinite generator that takes an image detects with the current vision and returns the list of contours the image and directions and should be used as follows:

connection = ovl.NetworkTablesConnection(1937)

vision1 = ovl.Vision(....)
vision2 = ovl.Vision(....)
vision3 = ovl.Vision(....)

update_location = ovl.NetworkLocation(table_key="current_vision")

multi_vision = ovl.MultiVision([vision1, vision2, vision3], connection, update_location)

for directions, contours, image  in multi_vision.start():

    # do something with the generated data

    # like sending the data or displaying the contours

    multi_vision.send(directions)

    ovl.display_contours(image, contours, delay=1)

Note: automatically updates AmbientVision’s vision swapping (AmbientVision.update_vision())!

Parameters:yield_ratios – if True also yields the list of ratios returned from
Yields:contours image directions and ratios if yield_ratios if True
switch_vision(index: Any)[source]

Switches the current vision used to the vision at the given index (can be a key for dictionaries)

Parameters:index – the index of the new vision, can be an int if the container of the visions is a list or any immutable object if it is a dictionary
Returns:the index set (the index given if it is valid and
update_current() → int[source]

Reads the updated current vision from the update network location and then updates the current vision

Returns:the index received