Exemplo n.º 1
0
    def setUp(self):
        self.img0 = cv2.imread(
            os.path.join(test_commons.resources_dir_path, 'fountain',
                         '0000.jpg'))
        self.img0_512 = resize_to(self.img0, width=512)

        self.dummy_fast = fast.DummyFastDetector()
Exemplo n.º 2
0
    def test_chessboard(self):
        chessboard_corners = np.zeros((8 * 8, 3), np.float32)
        chessboard_corners[:, :2] = np.mgrid[0:8, 0:8].T.reshape(-1, 2)

        frames_points_3d = []
        frames_points_2d = []

        for img_file in glob(
                os.path.join(test_commons.resources_dir_path, 'chessboard') +
                '/*.JPG'):
            img = resize_to(cv2.imread(img_file))
            gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
            cv2.imshow('kb', gray)
            cv2.waitKey()

            found, corners = cv2.findChessboardCorners(gray, (8, 8), None)

            if found:
                frames_points_3d.append(chessboard_corners)

                criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER,
                            30, 0.001)
                corners = cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1),
                                           criteria)
                frames_points_2d.append(corners)

                img = cv2.drawChessboardCorners(img, (7, 6), corners, found)
                cv2.imshow('img', img)
                cv2.waitKey(500)

        cv2.destroyAllWindows()
    def test_chessboard(self):
        chessboard_corners = np.zeros((8*8,3), np.float32)
        chessboard_corners[:, :2] = np.mgrid[0:8, 0:8].T.reshape(-1,2)

        frames_points_3d = []
        frames_points_2d = []

        for img_file in glob(os.path.join(test_commons.resources_dir_path, 'chessboard') + '/*.JPG'):
            img = resize_to(cv2.imread(img_file))
            gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
            cv2.imshow('kb', gray)
            cv2.waitKey()

            found, corners = cv2.findChessboardCorners(gray, (8, 8), None)

            if found:
                frames_points_3d.append(chessboard_corners)

                criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
                corners = cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)
                frames_points_2d.append(corners)

                img = cv2.drawChessboardCorners(img, (7,6), corners, found)
                cv2.imshow('img',img)
                cv2.waitKey(500)

        cv2.destroyAllWindows()
Exemplo n.º 4
0
def run_choose_pixel(image_file,
                     *,
                     mouse_moved=None,
                     mouse_left_click=None,
                     mouse_right_click=None,
                     width=1024):
    empty_handler = lambda pixels, pixel: None
    mouse_moved = mouse_moved or empty_handler
    mouse_left_click = mouse_left_click or empty_handler
    mouse_right_click = mouse_right_click or empty_handler

    src_img = cv2.imread(image_file)
    h, w = src_img.shape[:2]

    win_name = 'Leporis. Choose pixels'
    src_img = resize_to(src_img, width)
    cv2.imshow(win_name, src_img)

    points = []

    def on_mouse(event, x, y, flags, param):
        nonlocal points

        x, y = x / width, y / width
        point = np.array([x, y])

        event_handler = None
        update_image = False
        if event == cv2.EVENT_LBUTTONDOWN:
            points.append(point)
            event_handler = mouse_left_click
            update_image = True
        elif event == cv2.EVENT_RBUTTONDOWN:
            points = points[:-1]
            event_handler = mouse_right_click
            update_image = True
        elif event == cv2.EVENT_MOUSEMOVE:
            event_handler = mouse_moved
        if update_image:
            cv2.imshow(
                win_name,
                draw_points(src_img.copy(),
                            np.array(points),
                            color=(0, 0, 255)))
        if event_handler is not None:
            event_handler(_to_absolute_points(points, w),
                          _to_absolute_points(point, w))

    cv2.setMouseCallback(win_name, on_mouse)
    while True:
        if cv2.waitKey(20) & 0xFF == 27:
            break
    return _to_absolute_points(points, w)
Exemplo n.º 5
0
def run_choose_pixel(image_file,
                     *, mouse_moved=None, mouse_left_click=None, mouse_right_click=None, width=1024):
    empty_handler = lambda pixels, pixel: None
    mouse_moved = mouse_moved or empty_handler
    mouse_left_click = mouse_left_click or empty_handler
    mouse_right_click = mouse_right_click or empty_handler

    src_img = cv2.imread(image_file)
    h, w = src_img.shape[:2]

    win_name = 'Leporis. Choose pixels'
    src_img = resize_to(src_img, width)
    cv2.imshow(win_name, src_img)

    points = []

    def on_mouse(event, x, y, flags, param):
        nonlocal points

        x, y = x / width, y / width
        point = np.array([x, y])

        event_handler = None
        update_image = False
        if event == cv2.EVENT_LBUTTONDOWN:
            points.append(point)
            event_handler = mouse_left_click
            update_image = True
        elif event == cv2.EVENT_RBUTTONDOWN:
            points = points[:-1]
            event_handler = mouse_right_click
            update_image = True
        elif event == cv2.EVENT_MOUSEMOVE:
            event_handler = mouse_moved
        if update_image:
            cv2.imshow(win_name, draw_points(src_img.copy(), np.array(points), color=(0, 0, 255)))
        if event_handler is not None:
            event_handler(_to_absolute_points(points, w), _to_absolute_points(point, w))

    cv2.setMouseCallback(win_name, on_mouse)
    while True:
        if cv2.waitKey(20) & 0xFF == 27:
            break
    return _to_absolute_points(points, w)
Exemplo n.º 6
0
    def setUp(self):
        self.img0 = cv2.imread(os.path.join(test_commons.resources_dir_path, 'fountain', '0000.jpg'))
        self.img0_512 = resize_to(self.img0, width=512)

        self.dummy_fast = fast.DummyFastDetector()