Example #1
0
def _show_marker_det_img_folder(marker_path, img_data_path, det_file_name,
                                block):
    # load detections
    det_file = os.path.join(img_data_path, det_file_name)
    print('\tDetection file: %s' % det_file)
    assert os.path.exists(det_file), 'Could not find detection file.'
    det = json_load(det_file)

    # check for image files
    img_list = find_images(img_data_path)
    print('Found %s images for marker detection.' % len(img_list))

    # sanity check
    assert len(det['p2d']) == len(
        img_list), 'Number of detections and number of images differs.'
    assert len(det['pid']) == len(
        img_list), 'Number of detections and number of images differs.'

    # set up detector
    detector = BoardDetector(marker_path)

    # show
    for idx, img_p in enumerate(img_list):
        img_file = os.path.basename(img_p)
        if img_file not in det['files']:
            print('No detection available for: %s' % img_file)
            continue
        img = cv2.imread(img_p)
        detector.draw_board(img,
                            np.array(det['p2d'][idx]),
                            np.array(det['pid'][idx]),
                            block=block)
Example #2
0
def _show_marker_det_video(marker_path, video_path, det_file_name, block):
    # load detections
    data_path = os.path.dirname(video_path)
    det_file = os.path.join(data_path, det_file_name)
    print('\tDetection file: %s' % det_file)
    assert os.path.exists(det_file), 'Could not find detection file.'
    det = json_load(det_file)

    # check video path
    video = cv2.VideoCapture(video_path)
    num_frames = video.get(cv2.CAP_PROP_FRAME_COUNT)
    print('Found video with %d frames.' % num_frames)

    # sanity check
    assert len(
        det['p2d']
    ) == num_frames, 'Number of detections and number of frames differs.'
    assert len(
        det['pid']
    ) == num_frames, 'Number of detections and number of frames differs.'

    # set up detector
    detector = BoardDetector(marker_path)

    # show
    idx = 0
    while True:
        if not video.isOpened():
            break
        ret, img = video.read()

        if not ret:
            break

        detector.draw_board(img,
                            np.array(det['p2d'][idx]),
                            np.array(det['pid'][idx]),
                            block=block)

        idx += 1
Example #3
0
def test_board_pose_estimator(show=False):
    """ Test detecting Boards in images. """
    import cv2
    from utils.general_util import json_load
    from core.BoardDetector import BoardDetector
    img_list = ['./data/calib_test_data/real/april_board_tags_sample.JPG']
    assert os.path.exists(img_list[0]), 'Image file not found.'

    detector = BoardDetector(
        './data/calib_test_data/marker_32h11b2_4x4x_7cm.json')
    point_coords_frames, point_ids_frames = detector.process_image_batch(
        img_list)
    gt1 = json_load('data/calib_test_data/real/gt_det1.json')
    _same(point_coords_frames[0], gt1['c'])
    _same(point_ids_frames[0], gt1['i'])

    if show:
        for img_path, points, point_ids in zip(img_list, point_coords_frames,
                                               point_ids_frames):
            image = cv2.imread(img_path)
            detector.draw_board(image, points, point_ids, linewidth=2)

    detector = BoardDetector(
        './data/calib_test_data/marker_16h5b1_4x4x_15cm.json')
    point_coords_frames, point_ids_frames = detector.process_image_batch(
        img_list)
    gt2 = json_load('data/calib_test_data/real/gt_det2.json')
    _same(point_coords_frames[0], gt2['c'])
    _same(point_ids_frames[0], gt2['i'])

    if show:
        for img_path, points, point_ids in zip(img_list, point_coords_frames,
                                               point_ids_frames):
            image = cv2.imread(img_path)
            detector.draw_board(image, points, point_ids, linewidth=2)

    print('SUCCESS: test_board_pose_estimator')