def process_3d(self, data_dir):
        new_data_dir = '{}_new'.format(data_dir.rstrip('/'))
        if os.path.exists(new_data_dir):
            shutil.rmtree(new_data_dir)

        os.makedirs(new_data_dir)

        for filename in FileHelper.list_dir(data_dir):
            if not ImageHelper.is_img(filename) or 'depth' in filename:
                Log.info('Image Path: {}'.format(os.path.join(data_dir, filename)))
                continue

            file_path = os.path.join(data_dir, filename)
            img = io.imread(file_path)
            kpts = self.detect_face(img)
            if kpts is None:
                Log.info('Invliad face detected in {}'.format(file_path))
                continue

            depth = np.array(io.imread(os.path.join(data_dir, filename.replace('rgb', 'depth'))))
            face_depth, kpts = self.align_face([np.array(img), np.array(depth)], kpts)
            if face_depth is None:
                Log.info('Invliad face detected in {}'.format(file_path))
                continue
            ImageHelper.save(ImageHelper.rgb2bgr(face_depth[0]), os.path.join(new_data_dir, filename))
            ImageHelper.save(ImageHelper.rgb2bgr(face_depth[1]), os.path.join(new_data_dir, filename.replace('rgb', 'depth')))
Exemplo n.º 2
0
    def vis_bboxes(self,
                   image_in,
                   bboxes_list,
                   name='default',
                   sub_dir='bbox'):
        """
          Show the diff bbox of individuals.
        """
        base_dir = os.path.join(self.configer.get('project_dir'), DET_DIR,
                                sub_dir)

        if isinstance(image_in, Image.Image):
            image = ImageHelper.rgb2bgr(ImageHelper.to_np(image_in))

        else:
            image = image_in.copy()

        if not os.path.exists(base_dir):
            log.error('Dir:{} not exists!'.format(base_dir))
            os.makedirs(base_dir)

        img_path = os.path.join(
            base_dir,
            name if ImageHelper.is_img(name) else '{}.jpg'.format(name))

        for bbox in bboxes_list:
            image = cv2.rectangle(image, (bbox[0], bbox[1]),
                                  (bbox[2], bbox[3]), (0, 255, 0), 2)

        cv2.imwrite(img_path, image)
    def process(self, data_dir):
        new_data_dir = '{}_new'.format(data_dir.rstrip('/'))
        if os.path.exists(new_data_dir):
            shutil.rmtree(new_data_dir)

        os.makedirs(new_data_dir)

        for filename in FileHelper.list_dir(data_dir):
            if not ImageHelper.is_img(filename):
                Log.info('Image Path: {}'.format(os.path.join(data_dir, filename)))
                continue

            file_path = os.path.join(data_dir, filename)
            img = io.imread(file_path)
            kpts = self.detect_face(img)
            if kpts is None:
                Log.info('Invliad face detected in {}'.format(file_path))
                continue

            face, kpts = self.align_face(img, kpts)
            cv2.imwrite(os.path.join(new_data_dir, filename), ImageHelper.rgb2bgr(face))