def create_local_homography_object(bandwidth, magnitude, lambda_): """ Helper function for creating WeightedLocalHomography objects """ H = WeightedLocalHomography(SqExpWeightingFunction(bandwidth, magnitude)) H.regularization_lambda = lambda_ return H
def get_homography_estimate(filename): # # Conventions: # a_i, b_i # are variables in image space, units are pixels # a_w, b_w # are variables in world space, units are meters # print '\n========================================' print ' File: ' + filename print '========================================\n' from skimage.io import imread from skimage.color import rgb2gray im = imread(filename) im = rgb2gray(im) detections = get_tag_detections(im, cache_tag=filename) print ' %d tags detected.' % len(detections) # # Sort detections by distance to center # c_i = np.array([im.shape[1], im.shape[0]]) / 2. dist = lambda p_i: np.linalg.norm(p_i - c_i) closer_to_center = lambda d1, d2: int(dist(d1.c) - dist(d2.c)) detections.sort(cmp=closer_to_center) from tag36h11_mosaic import TagMosaic tag_mosaic = TagMosaic(0.0254) mosaic_pos = lambda det: tag_mosaic.get_position_meters(det.id) det_i = np.array([ d.c for d in detections ]) det_w = np.array([ mosaic_pos(d) for d in detections ]) # # Improvisation on the classic calibration procedure. We # obtain our initial homography estimate from 9 detections # at the center. This is better because the distortion is # minimal at the center. # det_i9 = det_i[:9] det_w9 = det_w[:9] from projective_math import WeightedLocalHomography, UnitWeightingFunction H_estimator = WeightedLocalHomography(UnitWeightingFunction()) for s, t in zip(det_w9, det_i9): H_estimator.add_correspondence(s, t) from tupletypes import Correspondence H = H_estimator.get_homography_at(det_w9[0]) corrs = [ Correspondence(w, i) for w, i in zip(det_w, det_i) ] return HomographyInfo(corrs, H, im.shape)