コード例 #1
0
def main(args):
    if args.output_directory:
        directory = args.output_directory
    else:
        directory = os.path.dirname(args.input_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 = os.path.splitext(os.path.basename(args.input_image))[0]
        print "No output prefix selected. Defaulting to %s" % prefix
    output_file = "%s/%s.pts" % (directory, prefix)
    if not args.input_points_file:
        args.input_points_file = output_file
    if not args.force_overwrite and os.path.exists(args.input_points_file):
        point_set_old = PointSet()
        point_set_old.read_from_file(args.input_points_file)
        for pt in point_set_old.get_points():
            points.append(pt)
    image = cv.LoadImage(args.input_image)
    window = PointWindow(image, args.zoom_out)

    if save_flag:
        point_set = PointSet()
        for pt in points:
            point_set.add_point(pt)
        point_set.save_to_file(output_file)
        print "Saved to %s" % output_file
コード例 #2
0
def main(args):
    if args.output_directory:
        directory = args.output_directory
    else:
        directory = os.path.dirname(args.input_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 = os.path.splitext(os.path.basename(args.input_image))[0]
        print "No output prefix selected. Defaulting to %s"%prefix
    output_file = "%s/%s.pts"%(directory, prefix)
    if not args.input_points_file:
        args.input_points_file = output_file
    if not args.force_overwrite and os.path.exists( args.input_points_file ):
        point_set_old = PointSet( )
        point_set_old.read_from_file( args.input_points_file )
        for pt in point_set_old.get_points():
            points.append( pt )
    image = cv.LoadImage( args.input_image)
    window = PointWindow( image, args.zoom_out)

    if save_flag:
        point_set = PointSet()
        for pt in points:
            point_set.add_point( pt )
        point_set.save_to_file( output_file )
        print "Saved to %s"%output_file
コード例 #3
0
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)
コード例 #4
0
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 )
コード例 #5
0
def main(args):
    output_files = []
    compared_images = []
    compared_windows = []
    for i,compared_image_file in enumerate(args.compared_images):
        if args.output_directory:
            directory = args.output_directory
        else:
            directory = os.path.dirname(args.compared_images[0])
            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_images[i]))[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)
        output_files.append(output_file)
        compared_image = cv.LoadImage( args.compared_images[i])
        compared_images.append(compared_image)
        compared_window = ClickWindow( compared_image, args.compared_zoom_out, i)
        compared_windows.append(compared_window)
        compared_pts.append({})

    if args.input_points_file:
        point_set = PointSet()
        point_set.read_from_file( args.input_points_file )
        for i,pt in enumerate(point_set.get_points()):
            reference_pts[i] = pt
    reference_image = cv.LoadImage( args.reference_image )
    reference_window = ClickWindow( reference_image, args.reference_zoom_out, -1)
    update_all_windows()
    # Tile
    y = reference_window.size()[1]
    x = 0
    for win in compared_windows:
        if x + win.size()[0] >= SCREEN_WIDTH:
            x = 0
            y += win.size()[1]
        print "Moving window %d to %f,%f"%(win.id,x,y)
        win.move(x,y)
        x += win.size()[0]

    global mode
    global selected_index
    while(True):
        cont = update_all_windows()
        if not cont:
            break
        if reference_window.click_pt:
            print "Updating reference_window click_pt"
            key = safe_max(reference_pts.keys())+1
            reference_pts[key] = reference_window.click_pt
            selected_index = key
            reference_window.clear_click_pt()
        for i,compared_window in enumerate(compared_windows):
            if compared_window.click_pt and selected_index > -1:
                print selected_index
                compared_pts[i][selected_index] = compared_window.click_pt
                compared_window.clear_click_pt()
    if save_flag:
        for i in range(len(compared_windows)):
            match_set = MatchSet(args.compared_images[i], args.reference_image)
            for k in compared_pts[i].keys():
                match_set.add_match( compared_pts[i][k], reference_pts[k], 1 )
            match_set.save_to_file( output_files[i] )
            print "Saved to %s"%output_files[i]
コード例 #6
0
def main(args):
    output_files = []
    compared_images = []
    compared_windows = []
    for i, compared_image_file in enumerate(args.compared_images):
        if args.output_directory:
            directory = args.output_directory
        else:
            directory = os.path.dirname(args.compared_images[0])
            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_images[i]))[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)
        output_files.append(output_file)
        compared_image = cv.LoadImage(args.compared_images[i])
        compared_images.append(compared_image)
        compared_window = ClickWindow(compared_image, args.compared_zoom_out, i)
        compared_windows.append(compared_window)
        compared_pts.append({})

    if args.input_points_file:
        point_set = PointSet()
        point_set.read_from_file(args.input_points_file)
        for i, pt in enumerate(point_set.get_points()):
            reference_pts[i] = pt
    reference_image = cv.LoadImage(args.reference_image)
    reference_window = ClickWindow(reference_image, args.reference_zoom_out, -1)
    update_all_windows()
    # Tile
    y = reference_window.size()[1]
    x = 0
    for win in compared_windows:
        if x + win.size()[0] >= SCREEN_WIDTH:
            x = 0
            y += win.size()[1]
        print "Moving window %d to %f,%f" % (win.id, x, y)
        win.move(x, y)
        x += win.size()[0]

    global mode
    global selected_index
    while True:
        cont = update_all_windows()
        if not cont:
            break
        if reference_window.click_pt:
            print "Updating reference_window click_pt"
            key = safe_max(reference_pts.keys()) + 1
            reference_pts[key] = reference_window.click_pt
            selected_index = key
            reference_window.clear_click_pt()
        for i, compared_window in enumerate(compared_windows):
            if compared_window.click_pt and selected_index > -1:
                print selected_index
                compared_pts[i][selected_index] = compared_window.click_pt
                compared_window.clear_click_pt()
    if save_flag:
        for i in range(len(compared_windows)):
            match_set = MatchSet(args.compared_images[i], args.reference_image)
            for k in compared_pts[i].keys():
                match_set.add_match(compared_pts[i][k], reference_pts[k], 1)
            match_set.save_to_file(output_files[i])
            print "Saved to %s" % output_files[i]