import ovl
from ovl import display_contours

target_filters = [
    ovl.percent_area_filter(minimal_percent=0.5),
    ovl.circle_filter(min_area_ratio=0.5),
    ovl.area_sort()
]

threshold = ovl.Color([20, 50, 50], [55, 255, 255])

yellow_circle = ovl.Vision(
    threshold=threshold,
    target_filters=target_filters,
    camera=0,  # open the first connected camera
    image_filters=[ovl.gaussian_blur()])

while True:
    image = yellow_circle.get_image()
    targets, filtered_image = yellow_circle.detect(image)
    directions = yellow_circle.get_directions(targets, filtered_image)
    display_contours(filtered_image, targets, display_loop=True)
    print(
        directions)  # prints out the (x, y) coordinates of the largest target
Example #2
0
contour_filters = [
    ovl.area_filter(min_area_ratio=150),
    ovl.straight_rectangle_filter(min_area_ratio=0.7),
    ovl.area_sort()
]

director = ovl.Director(directing_function=ovl.x_center_directions,
                        failed_detection=9999,
                        target_amount=1)

camera = ovl.Camera(0, image_width=640, image_height=480)

roborio = ovl.NetworkTablesConnection(roborio=TEAM_NUMBER,
                                      table_name="SmartDashboard",
                                      table_key="vision_directions")

image_filters = [ovl.gaussian_blur((5, 5))]

red_square = ovl.Vision(threshold=threshold,
                        contour_filters=contour_filters,
                        director=director,
                        camera=camera,
                        image_filters=image_filters)

while True:
    image = red_square.get_filtered_image()
    contours, filtered_image = red_square.detect(image)
    directions = red_square.get_directions(contours, filtered_image)
    red_square.send(directions)
Example #3
0
"""
A Simple program that display a rotated (180 degrees) and blurred (using gaussian blur) of the
live feed of the first (0) connected camera and utilizes the high-FPS realtime oriented Ovl Camera
"""
import ovl

CAMERA_PORT = 0

image_filters = [ovl.gaussian_blur(), ovl.rotate_image()]

pipeline = ovl.Vision(image_filters=image_filters,
                      camera=CAMERA_PORT,
                      ovl_camera=True)

while True:
    image = pipeline.get_image()
    blurred_image = pipeline.apply_image_filters(image)
    ovl.display_image(blurred_image, display_loop=True)
Example #4
0
import asyncio
import copy
from logging import getLogger

import ovl
from ovl import display_contours

logger = getLogger("multi_vision_example")

target_filters = [ovl.percent_area_filter(minimal_percent=2), ovl.area_sort()]

camera = ovl.Camera(0)

red_circle = ovl.Vision(target_filters=target_filters,
                        threshold=ovl.HSV.red,
                        camera=camera)

green_circle = copy.copy(red_circle)
green_circle.detector = ovl.ThresholdDetector(threshold=ovl.HSV.green)

yellow_circle = copy.copy(red_circle)
yellow_circle.detector = ovl.ThresholdDetector(threshold=ovl.HSV.yellow)

# connection = NetworkTablesConnection("1937")

circles = {"green": green_circle, "red": red_circle, "yellow": yellow_circle}
controller = ovl.MultiVision(visions=circles)

switcher = {"green": "red", "red": "yellow", "yellow": "green"}

current_color = "green"
Example #5
0
target_filters = [ovl.percent_area_filter(minimal_percent=0.03),
                  ovl.polygon_filter(side_amount=6, side_length_deviation=0.4, min_fill_ratio=0.6),
                  ovl.area_sort()]

direction_monitors = [ovl.StopIfCloseModifier(minimum_size=0.6, value_sent=5000)]

director = ovl.Director(direction_modifiers=direction_monitors,
                        target_selector=6,
                        failed_detection="Could not detect!",
                        directing_function=ovl.center_directions)

connection = ovl.SerialConnection(port=SERIAL_PORT)


pipeline = ovl.Vision(image_filters=image_filters,
                      target_filters=target_filters,
                      director=director,
                      camera=1,
                      ovl_camera=True,
                      threshold=dark_purple)

while True:
    image = pipeline.get_image()
    contours, filtered_image = pipeline.detect(image, verbose=True)
    directions = pipeline.get_directions(contours, filtered_image)
    if isinstance(directions, tuple):
        directions = directions[0]
    pipeline.send(directions)

Example #6
0
ball_contour_filters = [
    ovl.area_filter(min_area=200),
    ovl.circle_filter(min_area_ratio=0.65),
    ovl.area_sort()
]

hexagon_director = ovl.Director(ovl.xy_normalized_directions,
                                failed_detection="Could not detect!",
                                target_selector=2)

ball_director = ovl.Director(ovl.target_amount_directions,
                             failed_detection="Could not detect!",
                             target_selector=2)

red_ball_amount_counter = ovl.Vision(threshold=ovl.HSV.red,
                                     target_filters=ball_contour_filters,
                                     camera=camera,
                                     image_filters=image_filters)

two_blue_hexagons = ovl.Vision(threshold=BLUE,
                               target_filters=hexagon_contour_filters,
                               camera=camera,
                               image_filters=image_filters)

vision_controller = ovl.AmbientVision(main_vision=two_blue_hexagons,
                                      ambient_vision=red_ball_amount_counter,
                                      main_amount=5)

while True:
    image = vision_controller.get_image()
    contours, filtered_image, _ = vision_controller.detect(image)
    directions = vision_controller.get_directions(contours, filtered_image)
import ovl

# filter contours that are larger than 200 pixels
# and are approximately a circle and then sort by size

contour_filters = [ovl.area_filter(min_area=200),
                   ovl.circle_filter(min_area_ratio=0.7),
                   ovl.area_sort()]

image_filters = [ovl.gaussian_blur()]

threshold = ovl.YELLOW_HSV  # Define the wanted color to detect 

yellow_circle = ovl.Vision(threshold=threshold,
                           contour_filters=contour_filters,
                           camera=0,  # open the first connected camera
                           image_filters=image_filters)

while True:
    image = yellow_circle.get_filtered_image()
    contours, filtered_image = yellow_circle.detect(image)
    directions = yellow_circle.get_directions(contours, filtered_image)

    print(directions)  # prints out the (x, y) coordinates of the largest target