Exemple #1
0
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()
def main():
    camera = gbv.USBCamera(0)
    camera.set_exposure(-5)
    window = gbv.CameraWindow('feed', camera)
    window.open()
    while True:
        frame = window.show_and_get_frame()
        k = window.last_key_pressed
        if k == 'r':
            bbox = cv2.selectROI('feed', frame)
            thr = gbv.median_threshold(frame, stdv, bbox, 'HSV')
            break
    cv2.destroyAllWindows()

    print(thr)

    original = gbv.FeedWindow(window_name='original')
    after_proc = gbv.FeedWindow(window_name='after threshold', drawing_pipeline=thr)

    original.open()
    after_proc.open()
    while True:
        ok, frame = camera.read()
        if not original.show_frame(frame):
            break
        if not after_proc.show_frame(frame):
            break

    original.close()
    after_proc.close()
def main():
    camera = gbv.USBCamera(0, gbv.UNKNOWN_CAMERA)
    #camera.set_exposure(-1)
    cv2.namedWindow('window', cv2.WINDOW_FREERATIO)
    ok, frame = camera.read()
    while ok:
        ok, frame = camera.read()
        cv2.imshow('window', frame)

        k = chr(cv2.waitKey(1) & 0xFF)
        if k == 'r':
            bbox = cv2.selectROI('window', frame)
            thr = gbv.median_threshold(frame, stdv, bbox, 'HSV')
            break
    cv2.destroyAllWindows()

    print(thr)

    original = gbv.FeedWindow(window_name='original')
    after_proc = gbv.FeedWindow(window_name='after threshold', drawing_pipeline=thr + gbv.Erode(3) + gbv.Dilate(3))

    original.open()
    after_proc.open()
    while True:
        ok, frame = camera.read()
        if not original.show_frame(frame):
            break
        if not after_proc.show_frame(frame):
            break

    original.close()
    after_proc.close()
Exemple #4
0
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):
            print("object is at distance: %s meters" %
                  (gbv.distance_from_object(objects[0])))
    window.close()
Exemple #5
0
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)
            frame = gbv.draw_circles(frame=frame,
                                     circs=[fuel_follower.get()],
                                     color=(255, 0, 0),
                                     thickness=10)

        if len(all_fuels) == 0:
            found_fuel = False
        if fuel_follower is not None and fuel_follower.is_lost(max_count=20):
            found_fuel = False
        if not window.show_frame(frame):
            break
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)))
Exemple #7
0
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)))
    def __init__(self, seconds_buffer, extra_seconds, stream_url, filename):
        """
        abstract class for stream recorder

        :param seconds_buffer: How much time you enter into the buffer
        :param extra_seconds: How much time to record directly into the recorder
        """
        self.stream = gbv.USBCamera(stream_url)
        self.recorder = gbv.OpenCVRecorder(f"video/{filename}.avi", FPS)
        self.buffer = deque(maxlen=seconds_buffer)
        self.extra_seconds = extra_seconds
        self.status = self.stream.read()[0]
        self.frame = self.stream.read()[1]
Exemple #9
0
 def send_tcp_stream(port: int):
     global python_stream_running
     if not python_stream_running:
         python_stream_running = True
         camera = gbv.USBCamera(port)
         try:
             stream = gbv.TCPStreamBroadcaster(STREAM_PORT)
             while True:
                 ok, frame = camera.read()
                 stream.send_frame(frame)
         except gbv.TCPStreamClosed:
             camera.release()
             python_stream_running = False
def main():
    camera = gbv.USBCamera(0)
    camera.set_exposure(-5)
    find_fuel = gbv.CircleFinder(FUEL_THRESHOLD,
                                 FUEL,
                                 contour_min_area=CONTOUR_MIN_AREA)
    window = gbv.CameraWindow(
        'feed',
        camera,
        drawing_pipeline=gbv.DrawCircles(
            FUEL_THRESHOLD, (0, 255, 0),
            contours_process=gbv.FilterContours(CONTOUR_MIN_AREA),
            thickness=6))
    while True:
        frame = window.show_and_get_frame()
        fuels = find_fuel.find_shapes(frame)
        k = window.last_key_pressed
        if k == 'r':
            wrapper = gbv.ContinuesShapeWrapper(fuels,
                                                frame,
                                                find_fuel.find_shapes,
                                                shape_type=SHAPE_TYPE,
                                                tracker_type=TRACKER_TYPE,
                                                shape_lifespan=20,
                                                track_new=True)
            break
    window.close()
    window = gbv.FeedWindow('track')
    window.open()
    ok = True
    while ok:
        ok, frame = camera.read()
        fuels = wrapper.find_shapes(frame)

        for i, fuel in fuels.items():
            if fuel is None:
                continue
            frame = gbv.draw_circles(frame, [fuel], (0, 255, 0), thickness=6)
            frame = gbv.draw_text(frame,
                                  f'ID: {i}',
                                  (int(fuel[0][0]) - 10, int(fuel[0][1]) - 10),
                                  1, (0, 255, 0),
                                  thickness=3)
        if not window.show_frame(frame):
            break
Exemple #11
0
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)))
def main():
    print('place object in the middle of the frame and press r')
    width = float(input('Enter object width in meters >>> '))
    height = float(input('Enter object height in meters >>> '))
    z = float(
        input('Enter distance from object in the Z axis in meter units >>> '))
    camera = gbv.USBCamera(0)
    camera.set_exposure(-3)
    window = gbv.CameraWindow('feed', camera)
    window.open()
    while True:
        frame = window.show_and_get_frame()
        k = window.last_key_pressed
        if k == 'r':
            bbox = cv2.selectROI('feed', frame)
            fov = find_fov(bbox, (width, height), z,
                           (camera.get_width(), camera.get_height()))
            break
    cv2.destroyAllWindows()

    print(f'width fov: {fov[0] / 2}\nheight fov: {fov[1] / 2}')
 def test_connect_to_camera(self):
     camera = gbv.USBCamera(0)
     self.assertTrue(camera.is_opened())
     self.assertTrue(camera.read()[0])
Exemple #14
0
def main():
    camera = gbv.USBCamera(0)
    window = gbv.RecordingCameraWindow(window_name='camera example', wrap_object=camera, file_name='record.avi',
                                       fps=camera.get_fps())
    window.show()
    camera.release()