Example #1
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 #2
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)
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 #4
0
"""
A pipeline that detects the center of 6 purple hexagons

"""

import ovl

SERIAL_PORT = "/dev/ttyUSB1"

dark_purple = ovl.Color([130, 100, 70], [154, 255, 255])

image_filters = [ovl.gaussian_blur(), ovl.rotate_image(angle=90), ovl.adaptive_brightness(brightness=45)]

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,