示例#1
0
import gbvision as gbv

VISION_TARGET_THRESHOLD = gbv.Threshold([[0, 25], [150, 255], [0, 25]], 'BGR')
# the vision target threshold, found using median threshold

VISION_TARGET = gbv.GameObject(0.08424226967)
# target size (in meters) is about 0.14x0.05
# the square root of this size is the constant above (0.0842422...)


def main():
    finder = gbv.TargetPairFinder(
        VISION_TARGET_THRESHOLD + gbv.Erode(3) + gbv.Dilate(4), VISION_TARGET)
    # define the target finder
    camera = gbv.USBCamera(0, gbv.LIFECAM_3000)
    # connect to camera
    camera.set_auto_exposure(False)
    # turn off auto exposure mode (on raspberry pi)
    camera.set_exposure(False)
    # turn exposure to minimum (on raspberry pi)
    while True:
        ok, frame = camera.read()
        if ok:
            hatches = finder(frame, camera)
            if len(hatches) > 0:
                closest_hatch = hatches[0]
                print('found hatch at distance: %s\nand angle: %s' %
                      (gbv.distance_from_object(closest_hatch),
                       gbv.plane_angle_by_location(closest_hatch)))

示例#2
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()
import gbvision as gbv

CARGO = gbv.GameObject(0.2926321307845007)

CARGO_THRESHOLD = gbv.Threshold([[5, 15], [225, 255], [115, 175]], 'HSV')


def main():
    camera = gbv.USBCamera(0, gbv.LIFECAM_3000)
    find_cargo = gbv.CircleFinder(CARGO_THRESHOLD, CARGO)
    while True:
        ok, frame = camera.read()
        all_cargos = find_cargo(frame, camera)
        if len(all_cargos) > 0:
            nearest_cargo = all_cargos[0]
            print('found cargo at distance %f meters and %f angles' %
                  (gbv.distance_from_object(nearest_cargo),
                   gbv.plane_angle_by_location(nearest_cargo)))


if __name__ == '__main__':
    main()
import gbvision as gbv

THRESHOLD_CONST = gbv.Threshold([[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)
    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):
            print("object is at distance: %s meters" % (gbv.distance_from_object(objects[0])))
    window.close()


if __name__ == '__main__':
    main()