示例#1
0
    def georeference_with_gps(self,
                              images_path,
                              output_coords_file,
                              output_model_txt_geo,
                              rerun=False):
        try:
            if not io.file_exists(output_coords_file) or rerun:
                location.extract_utm_coords(self.photos, images_path,
                                            output_coords_file)
            else:
                log.ODM_INFO("Coordinates file already exist: %s" %
                             output_coords_file)

            # Deprecated: This is mostly for backward compatibility and should be
            # be removed at some point
            if not io.file_exists(output_model_txt_geo) or rerun:
                with open(output_coords_file, 'r') as f:
                    with open(output_model_txt_geo, 'w+') as w:
                        w.write(f.readline())  # CRS
                        w.write(f.readline())  # Offset
            else:
                log.ODM_INFO("Model geo file already exist: %s" %
                             output_model_txt_geo)

            self.georef = ODM_GeoRef.FromCoordsFile(output_coords_file)
        except:
            log.ODM_WARNING(
                'Could not generate coordinates file. The orthophoto will not be georeferenced.'
            )

        self.gcp = GCPFile(None)
        return self.georef
示例#2
0
    def georeference_with_gps(self, images_path, output_coords_file, rerun=False):
        try:
            if not io.file_exists(output_coords_file) or rerun:
                location.extract_utm_coords(self.photos, images_path, output_coords_file)
            else:
                log.ODM_INFO("Coordinates file already exist: %s" % output_coords_file)
            
            self.georef = ODM_GeoRef.FromCoordsFile(output_coords_file)
        except:
            log.ODM_WARNING('Could not generate coordinates file. The orthophoto will not be georeferenced.')

        self.gcp = GCPFile(None)
        return self.georef
示例#3
0
    def process(self, args, outputs):
        # Load tree
        tree = types.ODM_Tree(args.project_path, args.images, args.gcp)
        outputs['tree'] = tree

        if args.time and io.file_exists(tree.benchmarking):
            # Delete the previously made file
            os.remove(tree.benchmarking)
            with open(tree.benchmarking, 'a') as b:
                b.write(
                    'ODM Benchmarking file created %s\nNumber of Cores: %s\n\n'
                    % (system.now(), context.num_cores))

        # check if the extension is supported
        def supported_extension(file_name):
            (pathfn, ext) = os.path.splitext(file_name)
            return ext.lower() in context.supported_extensions

        # Get supported images from dir
        def get_images(in_dir):
            # filter images for its extension type
            log.ODM_DEBUG(in_dir)
            return [
                f for f in io.get_files_list(in_dir) if supported_extension(f)
            ]

        # get images directory
        input_dir = tree.input_images
        images_dir = tree.dataset_raw

        if not io.dir_exists(images_dir):
            log.ODM_INFO(
                "Project directory %s doesn't exist. Creating it now. " %
                images_dir)
            system.mkdir_p(images_dir)
            copied = [
                copyfile(io.join_paths(input_dir, f),
                         io.join_paths(images_dir, f))
                for f in get_images(input_dir)
            ]

        # define paths and create working directories
        system.mkdir_p(tree.odm_georeferencing)
        if not args.use_3dmesh: system.mkdir_p(tree.odm_25dgeoreferencing)

        log.ODM_DEBUG('Loading dataset from: %s' % images_dir)

        # check if we rerun cell or not
        images_database_file = io.join_paths(tree.root_path, 'images.json')
        if not io.file_exists(images_database_file) or self.rerun():
            files = get_images(images_dir)
            if files:
                # create ODMPhoto list
                path_files = [io.join_paths(images_dir, f) for f in files]

                photos = []
                with open(tree.dataset_list, 'w') as dataset_list:
                    for f in path_files:
                        photos += [types.ODM_Photo(f)]
                        dataset_list.write(photos[-1].filename + '\n')

                # Save image database for faster restart
                save_images_database(photos, images_database_file)
            else:
                log.ODM_ERROR('Not enough supported images in %s' % images_dir)
                exit(1)
        else:
            # We have an images database, just load it
            photos = load_images_database(images_database_file)

        log.ODM_INFO('Found %s usable images' % len(photos))

        # append photos to cell output
        if not self.params.get('proj'):
            if tree.odm_georeferencing_gcp:
                outputs['reconstruction'] = types.ODM_Reconstruction(
                    photos, coords_file=tree.odm_georeferencing_gcp)
            else:
                # Generate UTM from images
                try:
                    if not io.file_exists(
                            tree.odm_georeferencing_coords) or self.rerun():
                        location.extract_utm_coords(
                            photos, tree.dataset_raw,
                            tree.odm_georeferencing_coords)
                    else:
                        log.ODM_INFO("Coordinates file already exist: %s" %
                                     tree.odm_georeferencing_coords)
                except:
                    log.ODM_WARNING('Could not generate coordinates file. '
                                    'Ignore if there is a GCP file')

                outputs['reconstruction'] = types.ODM_Reconstruction(
                    photos, coords_file=tree.odm_georeferencing_coords)
        else:
            outputs['reconstruction'] = types.ODM_Reconstruction(
                photos, projstring=self.params.get('proj'))

        # Save proj to file for future use (unless this
        # dataset is not georeferenced)
        if outputs['reconstruction'].projection:
            with open(
                    io.join_paths(tree.odm_georeferencing,
                                  tree.odm_georeferencing_proj), 'w') as f:
                f.write(outputs['reconstruction'].projection.srs)
示例#4
0
    def process(self, args, outputs):
        log.ODM_INFO("Project path: %s" % args.project_path)

        outputs["project_path"] = args.project_path
        outputs["images_dir"] = os.path.join(args.project_path, 'images')
        outputs["image_list_file"] = os.path.join(outputs["project_path"],
                                                  "image_list.txt")
        outputs["cm"] = ColmapContext(args.project_path)

        log.ODM_INFO("Images dir: %s" % outputs["images_dir"])

        if not os.path.exists(outputs["images_dir"]):
            log.ODM_ERROR("No images found in %s, exiting..." %
                          outputs["images_dir"])
            exit(1)

        # create output directories (match ODM conventions for compatibility)
        odm_dirs = [
            'odm_orthophoto', 'odm_meshing', 'odm_texturing', 'odm_dem',
            'odm_georeferencing'
        ]

        for odm_dir in odm_dirs:
            system.mkdir_p(os.path.join(args.project_path, odm_dir))

        images_database_file = io.join_paths(args.project_path, 'images.json')
        if not io.file_exists(images_database_file) or self.rerun():
            files = []
            for ext in [
                    "JPG", "JPEG", "TIF", "TIFF", "jpg", "jpeg", "tif", "tiff"
            ]:
                image_wildcard = '*.{}'.format(ext)
                files += glob.glob(
                    os.path.join(outputs["images_dir"], image_wildcard))

            if files:
                photos = []
                with open(outputs["image_list_file"], 'w') as image_list:
                    log.ODM_INFO("Loading %s images" % len(files))
                    for f in files:
                        photos += [ODM_Photo(f)]
                        image_list.write(photos[-1].filename + '\n')

                # Save image database for faster restart
                save_images_database(photos, images_database_file)
            else:
                log.ODM_ERROR('Not enough supported images in %s' % images_dir)
                exit(1)
        else:
            # We have an images database, just load it
            photos = load_images_database(images_database_file)

        log.ODM_INFO('Found %s usable images' % len(photos))

        if len(photos) == 0:
            log.ODM_ERROR(
                "No images found (JPG or TIFF). Check that you placed some images in the images/ directory."
            )
            exit(1)

        utm_coords_file = os.path.join(args.project_path, "utm_coords.txt")
        if not os.path.exists(utm_coords_file) or self.rerun():
            extract_utm_coords(photos, outputs["images_dir"], utm_coords_file)
        else:
            log.ODM_WARNING("Found existing %s" % utm_coords_file)

        outputs["photos"] = photos
        outputs["utm_coords_file"] = utm_coords_file
示例#5
0
    def process(self, inputs, outputs):
        # check if the extension is supported
        def supported_extension(file_name):
            (pathfn, ext) = os.path.splitext(file_name)
            return ext.lower() in context.supported_extensions

        # Get supported images from dir
        def get_images(in_dir):
            # filter images for its extension type
            log.ODM_DEBUG(in_dir)
            return [
                f for f in io.get_files_list(in_dir) if supported_extension(f)
            ]

        log.ODM_INFO('Running ODM Load Dataset Cell')

        # get inputs
        tree = self.inputs.tree
        args = self.inputs.args

        # get images directory
        input_dir = tree.input_images
        images_dir = tree.dataset_raw

        if not io.dir_exists(images_dir):
            log.ODM_INFO(
                "Project directory %s doesn't exist. Creating it now. " %
                images_dir)
            system.mkdir_p(images_dir)
            copied = [
                copyfile(io.join_paths(input_dir, f),
                         io.join_paths(images_dir, f))
                for f in get_images(input_dir)
            ]

        # define paths and create working directories
        system.mkdir_p(tree.odm_georeferencing)
        if not args.use_3dmesh: system.mkdir_p(tree.odm_25dgeoreferencing)

        log.ODM_DEBUG('Loading dataset from: %s' % images_dir)

        # check if we rerun cell or not
        rerun_cell = (args.rerun is not None and
                      args.rerun == 'dataset') or \
                     (args.rerun_all) or \
                     (args.rerun_from is not None and
                      'dataset' in args.rerun_from)

        images_database_file = io.join_paths(tree.root_path, 'images.json')
        if not io.file_exists(images_database_file) or rerun_cell:
            files = get_images(images_dir)
            if files:
                # create ODMPhoto list
                path_files = [io.join_paths(images_dir, f) for f in files]

                photos = []
                with open(tree.dataset_list, 'w') as dataset_list:
                    for f in path_files:
                        photos += [types.ODM_Photo(f)]
                        dataset_list.write(photos[-1].filename + '\n')

                # Save image database for faster restart
                save_images_database(photos, images_database_file)
            else:
                log.ODM_ERROR('Not enough supported images in %s' % images_dir)
                return ecto.QUIT
        else:
            # We have an images database, just load it
            photos = load_images_database(images_database_file)

        log.ODM_INFO('Found %s usable images' % len(photos))

        # append photos to cell output
        if not self.params.proj:
            if tree.odm_georeferencing_gcp:
                outputs.reconstruction = types.ODM_Reconstruction(
                    photos, coords_file=tree.odm_georeferencing_gcp)
            else:
                # Generate UTM from images
                try:
                    if not io.file_exists(
                            tree.odm_georeferencing_coords) or rerun_cell:
                        location.extract_utm_coords(
                            photos, tree.dataset_raw,
                            tree.odm_georeferencing_coords)
                    else:
                        log.ODM_INFO("Coordinates file already exist: %s" %
                                     tree.odm_georeferencing_coords)
                except:
                    log.ODM_WARNING('Could not generate coordinates file. '
                                    'Ignore if there is a GCP file')

                outputs.reconstruction = types.ODM_Reconstruction(
                    photos, coords_file=tree.odm_georeferencing_coords)
        else:
            outputs.reconstruction = types.ODM_Reconstruction(
                photos, projstring=self.params.proj)

        # Save proj to file for future use (unless this
        # dataset is not georeferenced)
        if outputs.reconstruction.projection:
            with open(
                    io.join_paths(tree.odm_georeferencing,
                                  tree.odm_georeferencing_proj), 'w') as f:
                f.write(outputs.reconstruction.projection.srs)

        log.ODM_INFO('Running ODM Load Dataset Cell - Finished')
        return ecto.OK if args.end_with != 'dataset' else ecto.QUIT