示例#1
0
def main():
    parser = argparse.ArgumentParser(description="Calibrate using keypoint matches")
    parser.add_argument('--pattern_key_fname', type=str,default='keypoints_dir/left01.txt', help='reference pattern keypoint file')
    parser.add_argument('--img_keypoints_root', type=str,default='./keypoints_dir/',
                        help='Printf-formatted string representing keypoint files from N scene frames')
    parser.add_argument('--select_match_keypoints_root', type=str, default='./select_match_keypoints_dir/',help='Printf-formatted string representing keypoint match files')
    parser.add_argument('--example_image', type=str,default='./meilan_note6_resized/note01.jpg', help='Example image to get dimensions from')
    parser.add_argument('--out_fname', type=str, default='calibration_intrinsics.txt',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 = sift.read_features(args.pattern_key_fname)[0]

    img_keypoints_names=os.listdir(args.img_keypoints_root)
    img_keypoints_paths=[os.path.join(args.img_keypoints_root,f) for f in img_keypoints_names]

    select_match_keypoints_names = os.listdir(args.select_match_keypoints_root)
    select_match_keypoints_paths=[os.path.join(args.select_match_keypoints_root,f) for f in select_match_keypoints_names]

    if len(select_match_keypoints_names) == 0:
        print("No matching keypoint files")
        exit(1)

    missing = next((x for x in select_match_keypoints_paths if not os.path.isfile(x)), None)
    if missing is not None:
        print("File not found: %s" % missing)
        exit(1)

    print("reading keypoint from %d frames" % len(img_keypoints_paths))
    frames_keys = [sift.read_features(x)[0] for x in img_keypoints_paths]
    print("reading matches from %d frames" % len(select_match_keypoints_paths))
    frames_matches = [sift_match.read_matches(x) for x in select_match_keypoints_paths]

    # assert len(frames_keys)==len(frames_matches),"frames_keys should equal to frames_matches!"
    # print(len(frames_keys))
    # print(len(frames_matches))

    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)
示例#2
0
def sift_similar(img):
    img.save('./tmp/reg_img.jpg')
    key = sift.process_image('./tmp/reg_img.jpg')
    l, d = sift.read_features(key)
    return ravel(d)
示例#3
0
from PIL import Image
from numpy import *
from pylab import *
import sift

# print full array
set_printoptions(threshold=nan)

key1 = sift.process_image('h3.jpg')
#print key
#nk = str(key).split('\n')
#print len(nk)

l1, d1 = sift.read_features(key1)
img1 = array(Image.open('h3.pgm'))
print 'got the first pic'
#print d
#print array(ravel(d1))
#print '================================================'
sift.plot_features(img1, l1)

key2 = sift.process_image('h4.jpg')
l2, d2 = sift.read_features(key2)
img2 = array(Image.open('h4.pgm'))
print 'got the second pic'
sift.plot_features(img2, l2)
#print d2
#print array(ravel(d2))
#print '================================================'

'''