huikang / colmap-docker

Containerize COLMAP
0 stars 0 forks source link

Add openMVS for non-CUDA dense point cloud construction #2

Open huikang opened 5 years ago

huikang commented 5 years ago
DaniilSNikulin commented 3 years ago

In my case building a point cloud with OpenMVS is bad idea. OpenMVS in my case creates a cloud about 100 times larger than Colmap.

This is workaround for non-gpu depth map construction.

    def __build_depth_maps_colmap(self, image_names):
        max_num_src_images = 20
        config_fname = self.project.get_key() +'_patch-match.cfg'
        with open(os.path.join(self.root_path, 'stereo', config_fname), 'w') as f:
            for img_name in image_names:
                print(img_name, file=f)
                print('__auto__, {:d}'.format(max_num_src_images), file=f)
        self.runner.run([config.COLMAP_EXE, 'patch_match_stereo',
                        '--workspace_path', self.root_path,
                        '--workspace_format', 'COLMAP',
                        '--PatchMatchStereo.config_fname', config_fname,
                        '--PatchMatchStereo.geom_consistency', 'false',
                        '--PatchMatchStereo.filter', 'true',
                        '--PatchMatchStereo.window_radius', str(self.__get_pmvs_window_radius()),
                        '--PatchMatchStereo.num_samples', '5',
                        '--PatchMatchStereo.num_iterations', '4'])

    def __build_depth_maps_omvs(self):
        if os.path.exists(self.sparse_path + '_bin'):
            shutil.rmtree(self.sparse_path + '_bin')
        shutil.move(self.sparse_path, self.sparse_path + '_bin')
        os.makedirs(self.sparse_path, exist_ok=True)
        self.runner.run([config.COLMAP_EXE, 'model_converter',
                        '--input_path', self.sparse_path + '_bin',
                        '--output_path', self.sparse_path,
                        '--output_type', 'TXT'])
        omvs_path = os.path.join(self.root_path, 'omvs')
        os.makedirs(omvs_path, exist_ok=True)
        self.runner.run([os.path.join(config.OPEN_MVS_ROOT_DIR, 'InterfaceCOLMAP'),
                        '-i', self.root_path,
                        '--working-folder', omvs_path,
                        '-o', os.path.join(omvs_path, 'scene.mvs')])
        self.runner.run([os.path.join(config.OPEN_MVS_ROOT_DIR, 'DensifyPointCloud'),
                        '--input-file', os.path.join(omvs_path, 'scene.mvs'),
                        '--working-folder', omvs_path,
                        '--resolution-level', '0',
                        '--number-views', '5',
                        '--window-size', str(self.__get_pmvs_window_radius()),
                        '--fuse', '0'])
        self.runner.run([os.path.join(config.OPEN_MVS_ROOT_DIR, 'InterfaceCOLMAP'),
                        '-i', 'scene.mvs',
                        '--working-folder', omvs_path,
                        '-o', self.root_path])
        # shutil.rmtree(omvs_path)

    def build_depth_maps(self, *, image_names, use_gpu: bool):
        exists_image_names = {img.name for img in self.get_model().images.values()}
        image_names = sorted(exists_image_names & set(image_names))
        os.makedirs(self.root_path, exist_ok=True)
        if use_gpu:
            self.__build_depth_maps_colmap(image_names)
        else:
            if set(image_names) < exists_image_names:
                raise RuntimeError('FIXME: not allowed partial depth map build for omvs')
            self.__build_depth_maps_omvs()