Exemple #1
0
    def run_python(self):
        if process.setting.is_cali():
            return

        from pathlib import Path
        from concurrent.futures import ProcessPoolExecutor, as_completed

        # start
        folder = Path(process.setting.shot_path)
        export_path = self.get_folder_path()
        (Path(export_path) / 'matte').mkdir(parents=True, exist_ok=True)

        with ProcessPoolExecutor() as executor:
            future_list = []

            for image_file in folder.glob(
                    f'*_{process.setting.frame:06d}.jpg'
            ):
                future = executor.submit(
                    MaskImages.mask_image, str(image_file), export_path
                )
                future_list.append(future)

            for future in as_completed(future_list):
                result = future.result()
                process.log_info(result)
Exemple #2
0
    def run_python(self):
        from pathlib import Path
        from concurrent.futures import ProcessPoolExecutor, as_completed

        # start
        depth_folder = DepthMapEstimation.get_folder_path()
        export_path = self.get_folder_path()
        mask_folder = Path(PrepareDenseSceneOnlyMask.get_folder_path())

        with ProcessPoolExecutor() as executor:
            future_list = []

            for mask_path in mask_folder.glob('*.png'):
                for suffix, mask_value in (('depthMap', -1), ('simMap', 1)):
                    camera_id = mask_path.stem
                    filename = f'{camera_id}_{suffix}.exr'
                    exr_path = f'{depth_folder}{filename}'
                    output_path = f'{export_path}{filename}'
                    future = executor.submit(
                        DepthMapMasking.apply_mask_to_exr,
                        exr_path, str(mask_path), mask_value, output_path
                    )
                    future_list.append(future)

            for future in as_completed(future_list):
                result = future.result()
                process.log_info(result)
Exemple #3
0
    def clean_cache(cls, *args):
        process.log_info(f'> Clean flow: {cls.get_name()}')
        import glob
        import os
        files = []
        for ext in args:
            files.extend(
                glob.glob(
                    cls.get_folder_path() +
                    ext
                )
            )

        for f in files:
            os.remove(f)
Exemple #4
0
    def _run(self):
        command = self._make_command()
        if command is None:
            return

        command_list = command.to_list()

        process.log_info(f'Command: {command_list}')
        cmd = subprocess.Popen(
            command_list,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            bufsize=0,
            env=process.setting.get_environment()
        )

        force_quit = False
        for line in iter(cmd.stdout.readline, b''):
            try:
                line = line.decode('utf-8').rstrip()
            except:
                line = line.decode('cp950').rstrip()
            process.log_cmd(line)
            force_quit = self._check_force_quit(line)
            if force_quit:
                process.log_warning('Force QUIT!')
                cmd.kill()
                break

        return_code = cmd.wait()
        if return_code != 0 and not force_quit:
            error_log = (
                f'Return Code: {return_code}\n'
                f'Error Workflow: {self.get_name()}'
            )
            process.log_warning(error_log)
            process.fail(error_log)
Exemple #5
0
    def run(self):
        process.log_info(f'\n> Flow [{self.get_name()}] Start')

        # folder
        if not self._no_folder:
            if not self._skip_clean_folder:
                self._clean_folder()

            def make_folder():
                Path(self.get_folder_path()).mkdir(parents=True, exist_ok=True)

            try:
                make_folder()
            except WindowsError:
                process.log_info('Create folder error, wait 3 secs.')
                time.sleep(3)
                make_folder()

        Path(process.setting.export_path).mkdir(parents=True, exist_ok=True)

        # run
        self._run()

        process.log_info(f'> Flow [{self.get_name()}] Done')
Exemple #6
0
 def _clean_folder(cls):
     if os.path.isdir(cls.get_folder_path()):
         process.log_info('Output folder already exists, clean it.')
         shutil.rmtree(cls.get_folder_path())
         while os.path.exists(cls.get_folder_path()):
             pass