Beispiel #1
0
def main():
    parser = argparse.ArgumentParser(
        description='Photogrammetric filtering of sparse reconstructions.')
    parser.add_argument('--input',
                        help='Path to the input file [.out/.nvm]',
                        required=True)
    parser.add_argument('--output',
                        help='Path to the output folder',
                        required=True)
    parser.add_argument(
        '--intrinsics',
        help=
        'Path to the file containing the full instrisic values of the cameras',
        required=True)
    parser.add_argument('--intrinsic_format',
                        help='Format of the instrisic file',
                        required=True)
    parser.add_argument(
        '--features',
        help='Path to the file containing the photogrammetric features',
        required=True)
    parser.add_argument('--sigma',
                        help='Path to the file containing the sigma features',
                        required=True)
    parser.add_argument('--eq', help='Filtering equation id', default='0')
    parser.add_argument('--weight', help='Weight factor id', default='1')
    parser.add_argument('--debug',
                        help='Run in debug mode',
                        type=int,
                        default=0)
    args = parser.parse_args()

    if args.debug == 1:
        log_level = logging.DEBUG
    else:
        log_level = logging.INFO
    logging.basicConfig(
        format=
        '%(levelname)-6s %(asctime)s:%(msecs)d [%(filename)s:%(lineno)d] %(message)s',
        datefmt='%Y-%m-%d:%H:%M:%S',
        filename=os.path.join(args.output, "log_filter.txt"),
        filemode='w',
        level=log_level)

    # Get id of the filter weights and equations
    global equation_id, weight_id
    equation_id, weight_id = args.eq, args.weight
    logging.info('Filtering params: equation id: {}, weight id: {}'.format(
        equation_id, weight_id))

    geometry = Geometry()

    # Load reconstruction
    geometry.load_reconstruction(args.input)

    # Load camera intrinsics (per se not needed, but import them to avoid errors when generating the filtered .out)
    if args.intrinsic_format.lower() == 'metashape':
        geometry.load_full_camera_intrinsics(
            args.intrinsics, GeometrySettings.InstriscsFormatType.METASHAPE)
    elif args.intrinsic_format.lower() == 'opencv':
        geometry.load_full_camera_intrinsics(
            args.intrinsics, GeometrySettings.InstriscsFormatType.OPENCV)
    else:
        logging.critical(
            'Unknown intrinsic format. Supported values: [\'opencv\', \'metashape\']'
        )
        exit(1)

    # Import photogrammetric and sigma features
    import_photo_features(args.features, geometry)
    import_sigma_features(args.sigma, geometry)

    # Compute filter theshold
    global filter_threshold
    filter_threshold = compute_filter_threshold(geometry)
    logging.info("Computed filter threshold: {}".format(filter_threshold))

    # Filter the points
    filter_points3D(geometry)

    # Export filtered dataset in .out format
    out_path = geometry.export_reconstruction(
        args.output, GeometrySettings.SupportedOutputFileFormat.OUT)
    logging.info('Filtered reconstruction saved in {}'.format(
        os.path.join(out_path)))
Beispiel #2
0
def main():
    parser = ArgumentParser(
        description=
        'Create a file containing 3D points and photogrammetric features')
    parser.add_argument('--input',
                        help='Path to the input file [.out/.nvm]',
                        required=True)
    parser.add_argument('--output',
                        help='Path to the output folder',
                        required=True)
    parser.add_argument(
        '--intrinsics',
        help=
        'Path to the file containing the full instrisic values of the cameras',
        required=True)
    parser.add_argument('--intrinsic_format',
                        help='Format of theinstrisic file',
                        required=True)
    parser.add_argument('--debug',
                        help='Run in debug mode',
                        type=int,
                        default=0)
    args = parser.parse_args()

    if args.debug == 1:  # Set logging
        log_level = logging.DEBUG
    else:
        log_level = logging.INFO
    logging.basicConfig(
        format=
        '%(levelname)-6s %(asctime)s:%(msecs)d [%(filename)s:%(lineno)d] %(message)s',
        datefmt='%Y-%m-%d:%H:%M:%S',
        filename=os.path.join(args.output, "log_compute_features.txt"),
        filemode='w',
        level=log_level)

    geometry = Geometry()

    # Load reconstruction
    geometry.load_reconstruction(args.input)

    # Load full camera intrinsics
    if args.intrinsic_format == 'opencv':
        geometry.load_full_camera_intrinsics(
            args.intrinsics, GeometrySettings.InstriscsFormatType.OPENCV)
    elif args.intrinsic_format == 'metashape':
        geometry.load_full_camera_intrinsics(
            args.intrinsics, GeometrySettings.InstriscsFormatType.METASHAPE)
    else:
        logging.critical(
            'Unknown intrinsic format. Supported values: [\'opencv\', \'metashape\']'
        )
        exit(1)

    # Compute photogrammetric features
    geometry.compute_mean_reprojection_errors()
    geometry.compute_multiplicities()
    geometry.compute_max_intersection_angles(in_degree=True)

    # Export features
    geometry.export_points3D_xyz_and_features(args.output)
    logging.info('Photogrammetric features exported in {}'.format(
        os.path.join(args.output, "features.txt")))