@@ -0,0 +1,2489 @@
+%22%22%22Plot image crops around GCPs.%0A%22%22%22%0A%0Afrom __future__ import print_function%0Afrom __future__ import division%0Afrom __future__ import unicode_literals%0Afrom __future__ import absolute_import%0A%0Aimport argparse%0Aimport logging%0A%0Aimport numpy as np%0Aimport matplotlib.pyplot as plt%0A%0Afrom opensfm import features%0Afrom opensfm import io%0Afrom mapillary_sfm import dataset%0A%0Alogger = logging.getLogger(__name__)%0A%0A%0Adef parse_args():%0A    parser = argparse.ArgumentParser(%0A        description=__doc__)%0A    parser.add_argument(%0A        'dataset',%0A        help='dataset',%0A    )%0A    return parser.parse_args()%0A%0A%0Adef pix_coords(x, image):%0A    return features.denormalized_image_coordinates(%0A        np.array(%5B%5Bx%5B0%5D, x%5B1%5D%5D%5D), image.shape%5B1%5D, image.shape%5B0%5D)%5B0%5D%0A%0A%0Adef gcp_to_ply(gcps):%0A    %22%22%22Export GCP position as a PLY string.%22%22%22%0A    vertices = %5B%5D%0A%0A    for gcp in gcps:%0A        p = gcp.coordinates%0A        c = 255, 0, 0%0A        s = %22%7B%7D %7B%7D %7B%7D %7B%7D %7B%7D %7B%7D%22.format(%0A            p%5B0%5D, p%5B1%5D, p%5B2%5D, int(c%5B0%5D), int(c%5B1%5D), int(c%5B2%5D))%0A        vertices.append(s)%0A%0A    header = %5B%0A        %22ply%22,%0A        %22format ascii 1.0%22,%0A        %22element vertex %7B%7D%22.format(len(vertices)),%0A        %22property float x%22,%0A        %22property float y%22,%0A        %22property float z%22,%0A        %22property uchar diffuse_red%22,%0A        %22property uchar diffuse_green%22,%0A        %22property uchar diffuse_blue%22,%0A        %22end_header%22,%0A    %5D%0A%0A    return '%5Cn'.join(header + vertices + %5B''%5D)%0A%0A%0Adef main():%0A    args = parse_args()%0A    logging.basicConfig(%0A        format=%22%25(asctime)s %25(levelname)s %25(name)s: %25(message)s%22,%0A        level=logging.DEBUG)%0A%0A    data = dataset.DataSetBase(args.dataset)%0A    reconstruction = data.load_reconstruction()%5B0%5D%0A    gcps = data.load_ground_control_points()%0A%0A    with io.open_wt(data.data_path + '/gcp.ply') as fout:%0A        fout.write(gcp_to_ply(gcps))%0A%0A    for gcp in gcps:%0A        for i, observation in enumerate(gcp.observations):%0A            image = data.load_image(observation.shot_id)%0A            shot = reconstruction.shots%5Bobservation.shot_id%5D%0A%0A            reprojected = shot.project(gcp.coordinates)%0A            annotated = observation.shot_coordinates%0A            rpixel = pix_coords(reprojected, image)%0A            apixel = pix_coords(annotated, image)%0A%0A            n = (len(gcp.observations) + 3) / 4%0A            plt.subplot(n, 4, i + 1)%0A            plt.imshow(image)%0A            plt.scatter(rpixel%5B0%5D, rpixel%5B1%5D)%0A            plt.scatter(apixel%5B0%5D, apixel%5B1%5D)%0A        plt.show()%0A%0A%0Aif __name__ == '__main__':%0A    main()%0A

add script to plot GCPs