def main(args): if args.output_directory: directory = args.output_directory else: directory = os.path.dirname(args.compared_image) print "No output directory specified. Defaulting to %s"%directory if not os.path.exists(directory): os.makedirs(directory) if args.output_prefix: prefix = args.output_prefix else: prefix_c = os.path.splitext(os.path.basename(args.compared_image))[0] prefix_r = os.path.splitext(os.path.basename(args.reference_image))[0] prefix = "%s_TO_%s"%(prefix_c, prefix_r) print "No output prefix selected. Defaulting to %s"%prefix output_file = "%s/%s.matches"%(directory, prefix) if not args.input_match_file: args.input_match_file = output_file if not args.force_overwrite and os.path.exists( args.input_match_file ): match_set_old = MatchSet( args.compared_image, args.reference_image ) match_set_old.read_from_file( args.input_match_file ) for match in match_set_old.get_matches(): compare_pts.append(match.compare_pt) reference_pts.append(match.reference_pt) strengths.append(match.strength) compared_image = cv.LoadImage( args.compared_image) reference_image = cv.LoadImage( args.reference_image ) compare_window = ClickWindow( compared_image, args.compare_zoom_out, COMPARE) reference_window = ClickWindow( reference_image, args.reference_zoom_out, REFERENCE) global mode global strength while(True): cont = update_all_windows() if not cont: break if compare_window.click_pt and reference_window.click_pt: compare_pts.append(compare_window.click_pt) reference_pts.append(reference_window.click_pt) strengths.append(strength) compare_window.clear_click_pt() reference_window.clear_click_pt() if save_flag: match_set = MatchSet(args.compared_image, args.reference_image) for i in range( len(compare_pts) ): match_set.add_match( compare_pts[i], reference_pts[i], strengths[i] ) match_set.save_to_file( output_file ) print "Saved to %s"%output_file
def main(args): match_set = MatchSet("foo", "bar") match_set.read_from_file(args.comp_file) ref_set = PointSet() ref_set.read_from_file(args.ref_file) ref_pts = ref_set.get_points() print ref_pts output_set = MatchSet("foo", "bar") for match in match_set.get_matches(): idx = min([i for i in range(len(ref_pts))], key=lambda i: dist(ref_pts[i], match.reference_pt)) print match.reference_pt print dist(ref_pts[idx], match.reference_pt) match.ref_idx = idx output_set.add_match(match) output_set.save_to_file(args.comp_file)
def main(args): match_set = MatchSet( "foo", "bar" ) match_set.read_from_file( args.comp_file ) ref_set = PointSet( ) ref_set.read_from_file( args.ref_file ) ref_pts = ref_set.get_points() print ref_pts output_set = MatchSet( "foo", "bar" ) for match in match_set.get_matches(): idx = min( [i for i in range(len(ref_pts))], key = lambda i: dist(ref_pts[i],match.reference_pt) ) print match.reference_pt print dist(ref_pts[idx],match.reference_pt) match.ref_idx = idx output_set.add_match( match ) output_set.save_to_file( args.comp_file )
def main(args): match_set = MatchSet( "foo", "bar" ) print "Reading from " + args.match match_set.read_from_file( args.match ) compare_set = PointSet( ) ref_set = PointSet( ) if not args.ref_file: args.ref_file = os.path.basename(args.match).split('_TO_')[1].split('.matches')[0]+".pts" if not args.comp_file: args.comp_file = os.path.basename(args.match).split('_TO_')[0]+".pts" for match in match_set.get_matches(): compare_set.add_point(match.compare_pt) ref_set.add_point(match.reference_pt) ##if not os.path.exists(os.path.dirname( args.ref_file ) ): ## os.makedirs(os.path.dirname( args.ref_file ) ) ##if not os.path.exists(os.path.dirname( args.comp_file ) ): ## os.makedirs(os.path.dirname( args.comp_file ) ) ref_set.save_to_file( args.ref_file ) compare_set.save_to_file( args.comp_file )