Ejemplo n.º 1
0
    def test_handler(self):
        def test_frame_handler(frame, cam_id):
            if self.i == 200:
                w.CamCtrl.stop_cam(cam_id)
            if self.i % 100 == 0:
                print(frame.shape)
            self.i += 1

        w.frame_handler_thread(0,
                               test_frame_handler,
                               request_size=(1280, 720),
                               high_speed=True,
                               fps_limit=240)
Ejemplo n.º 2
0
def display_col_mask(
        cam,
        request_size=(1280, 720),  # type: Tuple[int, int]
        fps_limit=60  # type: float
):
    def cam_handler(frame, cam_id):
        win.frame_dict[str(cam_id) + "Frame"] = frame

    cam_thread = camp.frame_handler_thread(cam,
                                           cam_handler,
                                           fps_limit=fps_limit,
                                           high_speed=True)

    win.sub_win_loop(names=['contour test'],
                     input_cams=[cam],
                     input_vid_global_names=[str(cam) + 'Frame'],
                     callbacks=[
                         col_mask_callback(request_size,
                                           relative_color_filter=True,
                                           edge_filter=True,
                                           time_filter=False,
                                           combine_time_and_color=False,
                                           gpu=1)
                     ])

    return cam_thread
Ejemplo n.º 3
0
def show_v1(cam,
                    request_size=(640, 480),  # type: Tuple[int, int]
                    fps_limit=60,  # type: float
                    high_speed=True,  # type: bool
                    no_cl=False  # type: bool
                ):
    def cam_handler(frame, cam_id):
        win.SubscriberWindows.frame_dict[str(cam_id) + "Frame"] = frame

    cam_thread = camp.frame_handler_thread(cam, cam_handler, fps_limit=fps_limit,
                                           high_speed=high_speed)

    v1 = V1(request_sizes=RGC.get_size_list(request_size), gpu=0, rgc=None)

    v1.is_displaying = True

    v1.setup_callback()

    callback = v1.main_callback if not no_cl else v1.nocl_callback

    win_names = ["V1 End Stop {}x{}".format(size[0], size[1]) for size in v1.request_sizes]

    win.SubscriberWindows(window_names=win_names,
                     input_cams=[cam],
                     input_vid_global_names=[str(cam) + 'Frame'],
                     callbacks=[callback]).loop()

    return cam_thread
Ejemplo n.º 4
0
def display_rgc(cam,
                request_size=(1280, 720),  # type: Tuple[int, int]
                fps_limit=60,  # type: float
                high_speed=True,  # type: bool
                no_cl=False  # type: bool
                ):
    def cam_handler(frame, cam_id):
        win.SubscriberWindows.frame_dict[str(cam_id) + "Frame"] = frame

    cam_thread = camp.frame_handler_thread(cam, cam_handler, fps_limit=fps_limit,
                                           high_speed=high_speed)

    rgc = RGC(request_sizes=RGC.get_size_list(request_size),
              relative_color_filter=True,
              edge_filter=False,
              time_filter=False,
              combine_time_and_color=False,
              gpu=0)

    rgc.displaying = True

    rgc.setup_callback()

    callback = rgc.main_callback if not no_cl else rgc.rgc_nocl_callback

    win_names = ['RGC Scaled Output {}x{}'.format(size[0], size[1]) for size in rgc.request_sizes]
    win_names.extend(['RGC Color Edge Filter {}x{}'.format(size[0], size[1]) for size in rgc.request_sizes])
    #win_names.extend(['RGC Edge Filter {}x{}'.format(size[0], size[1]) for size in rgc.request_sizes])

    win.SubscriberWindows(window_names=win_names,
                     input_cams=[cam],
                     input_vid_global_names=[str(cam) + 'Frame'],
                     callbacks=[callback]).loop()

    return cam_thread
Ejemplo n.º 5
0
def display_average(cam,
                fps_limit=60,  # type: float
                high_speed=True,  # type: bool
                ento_animator = None
                ):
    def cam_handler(frame, cam_id):
        ento_animator.update_color(avg_total_color(frame))

    cam_thread = camp.frame_handler_thread(cam, cam_handler, fps_limit=fps_limit,
                                           high_speed=high_speed)

    return cam_thread
Ejemplo n.º 6
0
    def test_sub(self):
        def cam_handler(frame, cam_id):
            frame_dict[str(cam_id) + "Frame"] = (frame, frame)

        t = w.frame_handler_thread(0,
                                   cam_handler,
                                   request_size=(1280, 720),
                                   high_speed=True,
                                   fps_limit=240)

        sub_win_loop(names=['cammy', 'cammy2'],
                     input_vid_global_names=[str(0) + "Frame"])

        w.CamCtrl.stop_cam(0)

        t.join()
Ejemplo n.º 7
0
def display_rng(
        cam,
        request_size=(1280, 720),  # type: Tuple[int, int]
        fps_limit=60  # type: float
):
    def cam_handler(frame, cam_id):
        ws.SubscriberWindows.frame_dict[str(cam_id) + "Frame"] = frame

    cam_thread = wp.frame_handler_thread(cam, cam_handler, fps_limit=fps_limit)

    ws.SubscriberWindows(window_names=['Fast Random Number Generator'],
                         input_cams=[cam],
                         input_vid_global_names=[str(cam) + 'Frame'],
                         callbacks=[run_rng(request_size)]).loop()

    return cam_thread
Ejemplo n.º 8
0
def get_recognizer_thread(cam):
    """
    Creates a OpenCV window and thread to give OpenCV frames to classes.

    :param cam: Input Camera
    :param knorb1: Knowing ORB/ Image recognizer 1
    :param knorb2: Knowing ORB/ Image recognizer 2
    :param request_size: request camera to start with this resolution
    :param fps_limit: limit fps
    :return: camera thread, for joining and ending program
    """
    def cam_handler(frame, cam_id):
        win.SubscriberWindows.frame_dict[str(cam_id) + "Frame"] = frame

    cam_thread = camp.frame_handler_thread(cam,
                                           cam_handler,
                                           fps_limit=30,
                                           high_speed=False)

    def combined_callback(frame):
        tempFrame = np.copy(frame)
        tempFrame, tri_prob = tri_knorb.callback(tempFrame)
        frame, trap_prob = trap_knorb.callback(frame)
        out = np.concatenate(
            (tempFrame[0], frame[0]),
            axis=0)  # combine class debug output so we can see everything
        out = cv2.resize(
            out, (0, 0), fx=0.5,
            fy=0.5)  # resize, as it'd be too big for viewing otherwise

        # debug log output
        if tri_prob > trap_prob:
            print("TRI!")
        elif trap_prob > tri_prob:
            print("TRAP!")

        return [out]

    #run the OpenCV window. Has to be run in the main loop
    win_thread = win.SubscriberWindows(
        window_names=['recognition'],
        input_cams=[cam],
        input_vid_global_names=[str(cam) + 'Frame'],
        callbacks=[combined_callback]).loop()

    return cam_thread
Ejemplo n.º 9
0
def display(cam_num=0,
            request_size=(640, 480),
            fps_limit=24,
            window_title='display',
            callbacks=[]):
    def cam_handler(frame, cam_id):
        window_sub.frame_dict[str(cam_id) + "Frame"] = frame

    cam_thread = webcam_pub.frame_handler_thread(cam_num,
                                                 cam_handler,
                                                 fps_limit=fps_limit,
                                                 high_speed=False)

    window_sub.sub_win_loop(names=[window_title],
                            input_cams=[cam_num],
                            input_vid_global_names=[str(cam_num) + 'Frame'],
                            callbacks=callbacks)

    return cam_thread
Ejemplo n.º 10
0
def display_col_mask(
        cam,
        request_size=(1280, 720),  # type: Tuple[int, int]
        fps_limit=60  # type: float
):
    def cam_handler(frame, cam_id):
        win.SubscriberWindows.frame_dict[str(cam_id) + "Frame"] = frame

    cam_thread = camp.frame_handler_thread(cam,
                                           cam_handler,
                                           fps_limit=fps_limit,
                                           high_speed=False)

    win.SubscriberWindows(
        window_names=['by_np', 'yb_np', 'bw_np', 'rg_np', 'gr_np'],
        input_cams=[cam],
        input_vid_global_names=[str(cam) + 'Frame'],
        callbacks=[col_mask_callback(request_size, gpu=1)]).loop()

    return cam_thread
Ejemplo n.º 11
0
    def test_key_sub(self):
        def cam_handler(frame, cam_id):
            SubscriberWindows.frame_dict[str(cam_id) + "Frame"] = (frame,
                                                                   frame)

        t = w.frame_handler_thread(0,
                                   cam_handler,
                                   request_size=(1280, 720),
                                   high_speed=True,
                                   fps_limit=240)

        kt = start_print_keys_thread()

        SubscriberWindows(window_names=['cammy', 'cammy2'],
                          input_vid_global_names=[str(0) + "Frame"]).loop()

        w.CamCtrl.stop_cam(0)

        t.join()
        kt.join()
Ejemplo n.º 12
0
def display_average(
        cam,
        request_size=(1280, 720),  # type: Tuple[int, int]
        fps_limit=60,  # type: float
        high_speed=True,  # type: bool
        no_cl=False  # type: bool
):
    def cam_handler(frame, cam_id):
        win.SubscriberWindows.frame_dict[str(cam_id) + "Frame"] = frame

    cam_thread = camp.frame_handler_thread(cam,
                                           cam_handler,
                                           fps_limit=fps_limit,
                                           high_speed=high_speed)

    callback = avg_total_color

    win.SubscriberWindows(window_names=["avg"],
                          input_cams=[cam],
                          input_vid_global_names=[str(cam) + 'Frame'],
                          callbacks=[callback]).loop()

    return cam_thread