import gbvision as gbv

THRESHOLD = gbv.ColorThreshold([[0, 62], [215, 255], [15, 95]], 'HSV')


def main():
    camera = gbv.AsyncUSBCamera(0)
    camera.wait_start_reading()
    window = gbv.CameraWindow('feed', camera)
    window.show_async()
    threshold_window = gbv.CameraWindow('threshold',
                                        camera,
                                        drawing_pipeline=THRESHOLD)
    threshold_window.show_async()
    denoising_window = gbv.CameraWindow('denoised',
                                        camera,
                                        drawing_pipeline=THRESHOLD +
                                        gbv.DistanceTransformThreshold(0.4))
    denoising_window.show()


if __name__ == '__main__':
    main()
Exemplo n.º 2
0
from typing import List

import gbvision as gbv

K = 0.6

THRESHOLD = gbv.ColorThreshold([[14, 34], [146, 255], [48, 208]],
                               'HSV') + gbv.DistanceTransformThreshold(K)


def radius_restore() -> gbv.Number:
    return 1 + K


def circle_process(circs: List[gbv.Circle]) -> List[gbv.Circle]:
    return [(c[0], c[1] * radius_restore()) for c in circs]


def main():
    camera = gbv.AsyncUSBCamera(0)
    camera.set_exposure(-5)
    camera.wait_start_reading()
    window = gbv.CameraWindow('feed',
                              camera,
                              drawing_pipeline=gbv.DrawCircles(
                                  THRESHOLD, (0, 255, 0),
                                  circle_process=circle_process))
    window.show_async()
    denoising_window = gbv.CameraWindow('denoised',
                                        camera,
                                        drawing_pipeline=THRESHOLD)
import cv2
import gbvision as gbv
import streamlink as sl
from collections import deque
import abc

FPS = 30
MATCH_TIME = 2.5 * 60
extra_time = 10


THRESHOLD = gbv.ColorThreshold([[0, 22], [0, 20], [234, 255]], 'BGR')


class StreamNotFound(Exception):
    """
    Rasied if stream was not found
    """
    pass


def get_stream_url(twitch_id='firstinspires', youtube_id=None, quality='480p'):
    """
    get stream url by twitch id or youtube video id (NOT URL)

    :param twitch_id: Twitch channel id
    :param youtube_id: Youtube video id (youtube.com/watch? *ID*)
    :param quality: quality of the stream, options are: 160p, 360p, 480p, 720p, best, worst

    :return: video stream url, -1 if stream not found
    """
Exemplo n.º 4
0
import gbvision as gbv

FUEL = gbv.GameObject(0.04523893421169302263386206471922)

FUEL_THRESHOLD = gbv.ColorThreshold([[0, 76], [215, 255], [40, 120]], 'HSV')


def main():
    camera = gbv.USBCamera(0, gbv.LIFECAM_3000)
    find_fuel = gbv.CircleFinder(FUEL_THRESHOLD, FUEL)
    while True:
        ok, frame = camera.read()
        all_fuels = find_fuel(frame, camera)
        if len(all_fuels) > 0:
            nearest_fuel = all_fuels[0]
            print('found fuel at distance %f meters and %f angles' %
                  (gbv.distance_from_object(nearest_fuel),
                   gbv.plane_angle_by_location(nearest_fuel)))


if __name__ == '__main__':
    main()
Exemplo n.º 5
0
import gbvision as gbv

CARGO_THRESHOLD = gbv.ColorThreshold([[0, 73], [167, 247], [40, 120]], 'HSV')


def main():
    camera = gbv.USBCamera(1, gbv.LIFECAM_3000)
    camera.resize(0.75, 0.75)
    # connect to camera

    camera.set_exposure(-8)
    # switch to auto exposure mode
    # this works on windows, when using a raspberry pi use booleans instead

    threshold_func = gbv.EMPTY_PIPELINE + CARGO_THRESHOLD + gbv.Erode(
        5) + gbv.Dilate(10)
    # the full pipeline of thresholding and denoising

    window = gbv.CameraWindow(
        'camera 0',
        camera,
        drawing_pipeline=gbv.
        DrawCircles(  # draw the outline circles of the cargos
            threshold_func,
            (255, 0, 0),  # threshold and color is blue (bgr)
            contours_process=gbv.FilterContours(100),  # filter small contours
            circle_process=gbv.sort_circles + gbv.filter_inner_circles
        ))  # sort circles and delete the inner circles

    window.show()
Exemplo n.º 6
0
import gbvision as gbv

THRESHOLD_CONST = gbv.ColorThreshold([[91, 151], [77, 137], [76, 136]], 'HSV')
# found using median threshold

OBJECT_CONST = gbv.GameObject(0.20706279240848655)


def main():
    camera = gbv.USBCamera(0, gbv.LIFECAM_3000)
    threshold_function = THRESHOLD_CONST + gbv.MedianBlur(5)
    finder = gbv.RotatedRectFinder(
        threshold_function,
        OBJECT_CONST,
        contour_min_area=100,
        rotated_rects_process=gbv.sort_rotated_rects +
        gbv.filter_inner_rotated_rects)
    window = gbv.CameraWindow(
        'feed',
        camera,
        drawing_pipeline=gbv.DrawRotatedRects(
            threshold_func=threshold_function,
            color=(255, 0, 0),
            contours_process=gbv.FilterContours(1000),
            rotated_rects_process=gbv.sort_rotated_rects +
            gbv.filter_inner_rotated_rects))
    window.open()
    while window.is_opened():
        frame = window.show_and_get_frame()
        objects = finder(frame, camera)
        if len(objects):
Exemplo n.º 7
0
import gbvision as gbv

FUEL = gbv.GameObject(0.04523893421169302263386206471922)

FUEL_THRESHOLD = gbv.ColorThreshold([[0, 73], [129, 209], [119, 199]], 'HSV')


def main():
    camera = gbv.USBCamera(0)
    find_fuel = gbv.CircleFinder(FUEL_THRESHOLD, FUEL, contour_min_area=1000)
    fuel_follower = None
    window = gbv.FeedWindow('follow')
    window.open()
    ok = True
    found_fuel = False
    tracker = gbv.Tracker('MEDIANFLOW')
    while ok:
        ok, frame = camera.read()
        all_fuels = find_fuel.find_shapes(frame)
        if (not found_fuel) and len(all_fuels) > 0:
            nearest_fuel = all_fuels[0]
            fuel_follower = gbv.ContinuesCircle(shape=nearest_fuel,
                                                frame=frame,
                                                tracker=tracker)
            found_fuel = True
        if found_fuel:
            for check in all_fuels:
                if fuel_follower.update(frame=frame, shape=check):
                    break
            else:
                fuel_follower.update_forced(frame=frame)