def main(): parser = argparse.ArgumentParser(description="Calibrate using keypoint matches"); parser.add_argument('pattern_key_fname', type=str, help='reference pattern keypoint file') parser.add_argument('num_frames', type=int, help='Number of scene frames') parser.add_argument('scene_key_fmt', type=str, help='Printf-formatted string representing keypoint files from N scene frames') parser.add_argument('match_fmt', type=str, help='Printf-formatted string representing keypoint match files') parser.add_argument('example_image', type=str, help='Example image to get dimensions from') parser.add_argument('out_fname', type=str, help='filename for intrinsic calibrated camera') parser.add_argument('--min_matches', default=20, type=str, help='omit frames with fewer than N matches') args = parser.parse_args() pattern_keys = feat.read_features(args.pattern_key_fname)[0]; fnames = [(args.scene_key_fmt % x, args.match_fmt % x) for x in range(1,args.num_frames+1)] fnames = [x for x in fnames if os.path.isfile(x[0])] if len(fnames) == 0: print "No matching keypoint files" exit(1) missing = next((x[1] for x in fnames if not os.path.isfile(x[1])), None) if missing is not None: print "File not found: %s" % missing exit(1) [frame_fnames, match_fnames] = zip(*fnames) print "reading keypoint from %d frames" % len(frame_fnames) frames_keys = [feat.read_features(x)[0] for x in frame_fnames] print "reading matches from %d frames" % len(match_fnames) frames_matches = [feat.read_matches(x) for x in match_fnames] img = cv2.imread(args.example_image) img_size = (img.shape[1], img.shape[0]); [obj_pts, image_pts] = to_calibration_data(frames_matches, pattern_keys, frames_keys, args.min_matches) cam = calibrate_intrinsic(obj_pts, image_pts, img_size) calib.write_intrinsic_camera(args.out_fname, cam);
def read_matches(num_cams, num_frames, fmt, sparse): return read_cams_frames_(num_cams, num_frames, fmt, lambda x: [My_match(m) for m in feat.read_matches(x)], sparse)
def main(): parser = argparse.ArgumentParser( description="Calibrate using keypoint matches") parser.add_argument('pattern_key_fname', type=str, help='reference pattern keypoint file') parser.add_argument('num_frames', type=int, help='Number of scene frames') parser.add_argument( 'scene_key_fmt', type=str, help= 'Printf-formatted string representing keypoint files from N scene frames' ) parser.add_argument( 'match_fmt', type=str, help='Printf-formatted string representing keypoint match files') parser.add_argument('example_image', type=str, help='Example image to get dimensions from') parser.add_argument('out_fname', type=str, help='filename for intrinsic calibrated camera') parser.add_argument('--min_matches', default=20, type=str, help='omit frames with fewer than N matches') args = parser.parse_args() pattern_keys = feat.read_features(args.pattern_key_fname)[0] fnames = [(args.scene_key_fmt % x, args.match_fmt % x) for x in range(1, args.num_frames + 1)] fnames = [x for x in fnames if os.path.isfile(x[0])] if len(fnames) == 0: print "No matching keypoint files" exit(1) missing = next((x[1] for x in fnames if not os.path.isfile(x[1])), None) if missing is not None: print "File not found: %s" % missing exit(1) [frame_fnames, match_fnames] = zip(*fnames) print "reading keypoint from %d frames" % len(frame_fnames) frames_keys = [feat.read_features(x)[0] for x in frame_fnames] print "reading matches from %d frames" % len(match_fnames) frames_matches = [feat.read_matches(x) for x in match_fnames] img = cv2.imread(args.example_image) img_size = (img.shape[1], img.shape[0]) [obj_pts, image_pts] = to_calibration_data(frames_matches, pattern_keys, frames_keys, args.min_matches) cam = calibrate_intrinsic(obj_pts, image_pts, img_size) calib.write_intrinsic_camera(args.out_fname, cam)
def read_matches(num_cams, num_frames, fmt, sparse): return read_cams_frames_( num_cams, num_frames, fmt, lambda x: [My_match(m) for m in feat.read_matches(x)], sparse)
#!/usr/bin/env python from sys import argv import features_ as feat import cv2 if len(argv) < 6: print "Usage: show_matches img_1 img_2 keypoints_1 keypoints_2 matches" exit(1) img1 = cv2.imread(argv[1], 0) img2 = cv2.imread(argv[2], 0) kp1 = feat.read_features(argv[3])[0] kp2 = feat.read_features(argv[4])[0] matches = feat.read_matches(argv[5]) matched_img = feat.draw_matches(img1, img2, kp1, kp2, matches) cv2.imshow("Matches", matched_img) cv2.waitKey()