コード例 #1
0
    def clean_data(self):
        dataset_dir = self.config['dataset_dir']
        work_dir = self.config['work_dir']

        # set log file and timer
        log_file = os.path.join(work_dir, 'logs/log_clean_data.txt')
        self.logger.set_log_file(log_file)
        # create a local timer
        local_timer = Timer('Data cleaning Module')
        local_timer.start()

        # clean data
        cleaned_data_dir = os.path.join(work_dir, 'cleaned_data')
        if os.path.exists(cleaned_data_dir):  # remove cleaned_data_dir
            shutil.rmtree(cleaned_data_dir)
        os.mkdir(cleaned_data_dir)

        # check if dataset_dir is a list or tuple
        if not (isinstance(dataset_dir, list) or isinstance(dataset_dir, tuple)):
            dataset_dir = [dataset_dir, ]
        clean_data(dataset_dir, cleaned_data_dir)

        # stop local timer
        local_timer.mark('Data cleaning done')
        logging.info(local_timer.summary())
コード例 #2
0
    def run_inspect_sfm_perspective(self):
        work_dir = os.path.abspath(self.config['work_dir'])

        log_file = os.path.join(work_dir, 'logs/log_inspect_sfm_perspective.txt')
        self.logger.set_log_file(log_file)
        local_timer = Timer('inspect sfm')
        local_timer.start()

        # inspect sfm perspective
        sfm_dir = os.path.join(work_dir, 'colmap/sfm_perspective')

        for subdir in ['tri', 'tri_ba']:
            dir = os.path.join(sfm_dir, subdir)
            logging.info('\ninspecting {} ...'.format(dir))

            inspect_dir = os.path.join(sfm_dir, 'inspect_' + subdir)
            if os.path.exists(inspect_dir):
                shutil.rmtree(inspect_dir)

            db_path = os.path.join(sfm_dir, 'database.db')
            sfm_inspector = SparseInspector(dir, db_path, inspect_dir, camera_model='PERSPECTIVE')
            sfm_inspector.inspect_all()

        # stop local timer
        local_timer.mark('inspect sfm perspective done')
        logging.info(local_timer.summary())
コード例 #3
0
    def run_crop_image_general(
        self,
        ift,
        oft,
        execute_parallel,
        remove_aux_file,
        apply_tone_mapping,
        joint_tone_mapping,
    ):
        work_dir = self.config["work_dir"]

        # set log file
        log_file = os.path.join(work_dir, "logs/log_crop_image.txt")
        self.logger.set_log_file(log_file)

        # create a local timer
        local_timer = Timer("Image cropping module")
        local_timer.start()

        # crop image and tone map
        image_crop_general(
            work_dir,
            ift,
            oft,
            execute_parallel,
            remove_aux_file,
            apply_tone_mapping,
            joint_tone_mapping,
        )

        # stop local timer
        local_timer.mark("image cropping done")
        logging.info(local_timer.summary())
コード例 #4
0
    def clean_data_general(self, ift):
        dataset_dir = self.config["dataset_dir"]
        work_dir = self.config["work_dir"]

        # set log file and timer
        log_file = os.path.join(work_dir, "logs/log_clean_data.txt")
        self.logger.set_log_file(log_file)
        # create a local timer
        local_timer = Timer("Data cleaning Module")
        local_timer.start()

        # clean data
        cleaned_data_dir = os.path.join(work_dir, "cleaned_data")
        if os.path.exists(cleaned_data_dir):  # remove cleaned_data_dir
            shutil.rmtree(cleaned_data_dir)
        os.mkdir(cleaned_data_dir)

        # check if dataset_dir is a list or tuple
        if not (isinstance(dataset_dir, list)
                or isinstance(dataset_dir, tuple)):
            dataset_dir = [
                dataset_dir,
            ]
        clean_data_general(dataset_dir, cleaned_data_dir, ift=ift)

        # stop local timer
        local_timer.mark("Data cleaning done")
        logging.info(local_timer.summary())
コード例 #5
0
    def run_aggregate_3d(self):
        work_dir = self.config['work_dir']
        # set log file
        log_file = os.path.join(work_dir, 'logs/log_aggregate_3d.txt')
        self.logger.set_log_file(log_file)
        # create a local timer
        local_timer = Timer('3D aggregation module')
        local_timer.start()

        aggregate_3d.run_fuse(work_dir)

        # stop local timer
        local_timer.mark('3D aggregation done')
        logging.info(local_timer.summary())
コード例 #6
0
    def run_crop_image(self):
        work_dir = self.config['work_dir']

        # set log file
        log_file = os.path.join(work_dir, 'logs/log_crop_image.txt')
        self.logger.set_log_file(log_file)

        # create a local timer
        local_timer = Timer('Image cropping module')
        local_timer.start()

        # crop image and tone map
        image_crop(work_dir)

        # stop local timer
        local_timer.mark('image cropping done')
        logging.info(local_timer.summary())
コード例 #7
0
    def run_aggregate_2p5d(self):
        work_dir = self.config['work_dir']
        # set log file
        log_file = os.path.join(work_dir, 'logs/log_aggregate_2p5d.txt')
        self.logger.set_log_file(log_file)
        # create a local timer
        local_timer = Timer('2.5D aggregation module')
        local_timer.start()

        max_processes = -1
        if 'aggregate_max_processes' in self.config:
            max_processes = self.config['aggregate_max_processes']

        aggregate_2p5d.run_fuse(work_dir, max_processes=max_processes)

        # stop local timer
        local_timer.mark('2.5D aggregation done')
        logging.info(local_timer.summary())
コード例 #8
0
    def run_colmap_mvs(self, window_radius=3):
        work_dir = self.config['work_dir']
        mvs_dir = os.path.join(work_dir, 'colmap/mvs')

        # set log file
        log_file = os.path.join(work_dir, 'logs/log_mvs.txt')
        self.logger.set_log_file(log_file)
        # create a local timer
        local_timer = Timer('Colmap MVS Module')
        local_timer.start()

        # first run PMVS without filtering
        run_photometric_mvs(mvs_dir, window_radius)

        # next do forward-backward checking and filtering
        run_consistency_check(mvs_dir, window_radius)

        # stop local timer
        local_timer.mark('Colmap MVS done')
        logging.info(local_timer.summary())
コード例 #9
0
    def run_derive_approx(self):
        work_dir = self.config['work_dir']

        # set log file to 'logs/log_derive_approx.txt'
        log_file = os.path.join(work_dir, 'logs/log_derive_approx.txt')
        self.logger.set_log_file(log_file)

        # create a local timer
        local_timer = Timer('Derive Approximation Module')
        local_timer.start()

        # derive approximations for later uses
        appr = CameraApprox(work_dir)

        appr.approx_affine_latlonalt()
        appr.approx_perspective_enu()

        # stop local timer
        local_timer.mark('Derive approximation done')
        logging.info(local_timer.summary())
コード例 #10
0
    def run_colmap_sfm_perspective(self, weight=0.01):
        work_dir = os.path.abspath(self.config['work_dir'])
        sfm_dir = os.path.join(work_dir, 'colmap/sfm_perspective')
        if not os.path.exists(sfm_dir):
            os.mkdir(sfm_dir)

        log_file = os.path.join(work_dir, 'logs/log_sfm_perspective.txt')
        self.logger.set_log_file(log_file)
        # create a local timer
        local_timer = Timer('Colmap SfM Module, perspective camera')
        local_timer.start()

        # create a hard link to avoid copying of images
        if os.path.exists(os.path.join(sfm_dir, 'images')):
            os.unlink(os.path.join(sfm_dir, 'images'))
        os.symlink(os.path.relpath(os.path.join(work_dir, 'colmap/subset_for_sfm/images'), sfm_dir),
                   os.path.join(sfm_dir, 'images'))
        init_camera_file = os.path.join(work_dir, 'colmap/subset_for_sfm/perspective_dict.json')
        colmap_sfm_perspective.run_sfm(work_dir, sfm_dir, init_camera_file, weight)

        # stop local timer
        local_timer.mark('Colmap SfM done')
        logging.info(local_timer.summary())
コード例 #11
0
    def run_reparam_depth(self):
        work_dir = self.config['work_dir']

        # set log file
        log_file = os.path.join(work_dir, 'logs/log_reparam_depth.txt')
        self.logger.set_log_file(log_file)
        # create a local timer
        local_timer = Timer('reparametrize depth')
        local_timer.start()

        # prepare dense reconstruction
        colmap_dir = os.path.join(work_dir, 'colmap')

        mvs_dir = os.path.join(colmap_dir, 'mvs')
        if not os.path.exists(mvs_dir):
            os.mkdir(mvs_dir)

        # link to sfm_perspective
        if os.path.exists(os.path.join(mvs_dir, 'images')):
           os.unlink(os.path.join(mvs_dir, 'images'))
        os.symlink(os.path.relpath(os.path.join(colmap_dir, 'sfm_perspective/images'), mvs_dir),
                  os.path.join(mvs_dir, 'images'))

        if os.path.exists(os.path.join(mvs_dir, 'sparse')):
           os.unlink(os.path.join(mvs_dir, 'sparse'))
        os.symlink(os.path.relpath(os.path.join(colmap_dir, 'sfm_perspective/tri_ba'), mvs_dir),
                   os.path.join(mvs_dir, 'sparse'))

        # compute depth ranges and generate last_rows.txt
        reparam_depth(os.path.join(mvs_dir, 'sparse'), mvs_dir, camera_model='perspective')

        # prepare stereo directory
        stereo_dir = os.path.join(mvs_dir, 'stereo')
        for subdir in [stereo_dir, 
                       os.path.join(stereo_dir, 'depth_maps'),
                       os.path.join(stereo_dir, 'normal_maps'),
                       os.path.join(stereo_dir, 'consistency_graphs')]:
            if not os.path.exists(subdir):
                os.mkdir(subdir)

        # write patch-match.cfg and fusion.cfg
        image_names = sorted(os.listdir(os.path.join(mvs_dir, 'images')))

        with open(os.path.join(stereo_dir, 'patch-match.cfg'), 'w') as fp:
            for img_name in image_names:
                fp.write(img_name + '\n__auto__, 20\n')
                
                # use all images
                # fp.write(img_name + '\n__all__\n')

                # randomly choose 20 images
                # from random import shuffle
                # candi_src_images = [x for x in image_names if x != img_name]
                # shuffle(candi_src_images)
                # max_src_images = 10
                # fp.write(img_name + '\n' + ', '.join(candi_src_images[:max_src_images]) + '\n')

        with open(os.path.join(stereo_dir, 'fusion.cfg'), 'w') as fp:
            for img_name in image_names:
                fp.write(img_name + '\n')

        # stop local timer
        local_timer.mark('reparam depth done')
        logging.info(local_timer.summary())