コード例 #1
0
ファイル: is_open.py プロジェクト: ivomarvan/quick_faces
    def _process_body(self, img: Image = None) -> Image:
        """
        Face coordinates an landmarks was found in orig_img_array.
        Use landmarks for desicion if mouth/eye/... is open.
        """
        result = ImageProcessorResult(processor=self)
        landmark_results = img.get_results().get_results_for_processor_super_class(LandmarksDetectorResult)  # [FaceLandmarsks]
        for landmark_result in landmark_results: # FaceLandmarsks
            for face_landmarks in landmark_result.get_face_landmark_couples():
                landmarks = face_landmarks.get_landmarks()  # [Point]
                # registre landmarks
                for point_number, landmark_point in enumerate(landmarks):
                    self._is_open_manager.add(point_number=point_number, point=landmark_point)
                # calculate result
                rate, percents, is_open = self._is_open_manager.get_rate_rate_percents_is_open()
                result = IsOpenResult(
                    processor=self,
                    rate=rate,
                    open_percents=percents,
                    is_open=is_open,
                    face_landmarks=face_landmarks,
                    threshold_percents = self._is_open_manager.get_threshold_percents()
                )
                # print('XXX', result.rate, result.open_percents, result.is_open)

        return img, result
コード例 #2
0
    def _process_body(self, img: Image = None) -> Image:

        img.set_work_img_array(
            self._rotate(img_array=img.get_work_img_array()))
        if self._rotate_both:
            img.set_orig_img_array(
                self._rotate(img_array=img.get_orig_img_array()))

        return img, ImageProcessorResult(self)
コード例 #3
0
    def _process_body(self, img: Image = None) -> Image:
        img.set_work_img_array(
            imutils.resize(
                image=img.get_work_img_array(),
                width=self.get_option('width'),
                height=self.get_option('width'),
                inter=self.get_option('inter'),
            )
        )

        if self.get_option('resize_both'):
            img.set_orig_img_array(
                imutils.resize(
                    image=img.get_orig_img_array(),
                    width=self.get_option('width'),
                    height=self.get_option('width'),
                    inter=self.get_option('inter'),
                )
            )
        return img, ImageProcessorResult(self)
コード例 #4
0
ファイル: decolorizer.py プロジェクト: ivomarvan/quick_faces
 def _process_body(self, img: Image = None) -> Image:
     img.set_work_img_array(
         cv2.cvtColor(src=img.get_work_img_array(),
                      code=self.get_option('code')))
     return img, ImageProcessorResult(self)
コード例 #5
0
    def _process_body(self, img: Image = None) -> Image:
        '''
        Face coordinates an landmarks was found in orig_img_array.
        But work_img was created by resizing of work_img_array
        We want to mark found points in orig_img_array.
        '''
        orig_img_array = img.get_orig_img_array()
        work_img_array = img.get_work_img_array()

        orig_shape = orig_img_array.shape
        h_orig = orig_shape[0]
        w_orig = orig_shape[1]

        work_shape = work_img_array.shape
        h_work = work_shape[0]
        w_work = work_shape[1]

        reformat_result = img.get_results().get_results_for_processor_super_class(SquereCropResult)
        if reformat_result:
            img_scale = reformat_result[0].get_img_scale()
            mx, my = img_scale, img_scale
        else:
            mx, my = w_orig / w_work, h_orig / h_work

        def r_x(x: int) -> int:
            return int(round(mx * x, 0))

        def r_y(y: int) -> int:
            return int(round(my * y, 0))

        faces_results = img.get_results().get_results_for_processor_super_class(FaceDetectorResult)
        for face_result in faces_results:
            face_color = face_result.get_processor().get_option('color')
            for face_rectangle in face_result.get_rectangles():
                # draw face
                l_t = face_rectangle.left_top()
                x1 = l_t.x()
                y1 = l_t.y()
                r_b = face_rectangle.right_bottom()
                x2 = r_b.x()
                y2 = r_b.y()
                pt1 = (r_x(x1), r_y(y1))
                pt2 = (r_x(x2), r_y(y2))
                try:
                    cv2.rectangle(img=orig_img_array, pt1=pt1, pt2=pt2, color=face_color, thickness=2)
                except Exception as e:
                    print('!' * 5, e)


        landmark_results = img.get_results().get_results_for_processor_super_class(LandmarksDetectorResult)  # [FaceLandmarsks]
        for landmark_result in landmark_results: # FaceLandmarsks
            for face_landmarks in landmark_result.get_face_landmark_couples():
                landmarks = face_landmarks.get_landmarks()  # [Point]
                face_result =  face_landmarks.get_face_result()  # FaceDetectorResult
                landmarks_color = landmark_result.get_processor().get_option('color')
                face_color = face_result.get_processor().get_option('color')

                # draw landmarks
                for landmark_point in landmarks:
                    x, y = landmark_point.x(), landmark_point.y()
                    try:
                        cv2.circle(orig_img_array, (r_x(x), r_y(y)), 1, face_color, 2)
                        cv2.circle(orig_img_array, (r_x(x), r_y(y)), 2, landmarks_color, -1)
                    except Exception as e:
                        print('$' * 5, e)

        return img, ImageProcessorResult(self)
コード例 #6
0
    def _process_body(self, img: Image = None) -> Image:
        '''
        Face coordinates an landmarks was found in orig_img_array.
        But work_img was created by resizing of work_img_array
        We want to mark found points in orig_img_array.
        '''
        orig_img_array = img.get_orig_img_array()
        work_img_array = img.get_work_img_array()

        orig_shape = orig_img_array.shape
        h_orig = orig_shape[0]
        w_orig = orig_shape[1]

        work_shape = work_img_array.shape
        h_work = work_shape[0]
        w_work = work_shape[1]

        reformat_result = img.get_results(
        ).get_results_for_processor_super_class(SquereCropResult)
        if reformat_result:
            img_scale = reformat_result[0].get_img_scale()
            mx, my = img_scale, img_scale
        else:
            mx, my = w_orig / w_work, h_orig / h_work

        def r_x(x: int) -> int:
            return int(round(mx * x, 0))

        def r_y(y: int) -> int:
            return int(round(my * y, 0))

            # get the width and height of the text box

        landmark_results = img.get_results(
        ).get_results_for_processor_super_class(
            LandmarksDetectorResult)  # [FaceLandmarsks]
        for landmark_result in landmark_results:  # FaceLandmarsks
            for face_landmarks in landmark_result.get_face_landmark_couples():
                landmarks = face_landmarks.get_landmarks()  # [Point]
                face_result = face_landmarks.get_face_result(
                )  # FaceDetectorResult
                landmarks_color = landmark_result.get_processor().get_option(
                    'color')
                face_color = face_result.get_processor().get_option('color')

                # draw landmarks
                print('*******', len(landmarks))
                for i, landmark_point in enumerate(landmarks):
                    '''
                    if i % 2 == 0: 
                        continue
                    '''
                    x, y = landmark_point.x(), landmark_point.y()
                    try:
                        text = str(i)
                        # cv2.getTextSize(text, self.FONT, fontScale=self.FONT_SCALE, thickness=self.THICKNESS)[0]
                        (text_width, text_height) = cv2.getTextSize(
                            text,
                            fontFace=self.FONT,
                            fontScale=self.FONT_SCALE,
                            thickness=self.THICKNESS)[0]
                        #                         # set the text start position
                        text_offset_x = max(0, r_x(x))
                        text_offset_y = r_y(y) - int(text_height / 2)
                        cv2.putText(orig_img_array,
                                    text, (text_offset_x, text_offset_y),
                                    self.FONT,
                                    fontScale=self.FONT_SCALE,
                                    color=landmarks_color,
                                    thickness=self.THICKNESS)

                    except Exception as e:
                        raise e
                        print('$' * 5, e)

        return img, ImageProcessorResult(self)
コード例 #7
0
ファイル: results.py プロジェクト: ivomarvan/quick_faces
 def add(self, result: ImageProcessorResult):
     self._results_by_history.append(result)
     self._total_time_ms += result.get_time_ms()
コード例 #8
0
    def _process_body(self, img: Image = None) -> Image:
        '''
        Face coordinates an landmarks was found in orig_img_array.
        But work_img was created by resizing of work_img_array
        We want to mark found points in orig_img_array.
        '''
        orig_img_array = img.get_orig_img_array()
        work_img_array = img.get_work_img_array()

        orig_shape = orig_img_array.shape
        h_orig = orig_shape[0]
        w_orig = orig_shape[1]

        work_shape = work_img_array.shape
        h_work = work_shape[0]
        w_work = work_shape[1]

        reformat_result = img.get_results(
        ).get_results_for_processor_super_class(SquereCropResult)
        if reformat_result:
            img_scale = reformat_result[0].get_img_scale()
            mx, my = img_scale, img_scale
        else:
            mx, my = w_orig / w_work, h_orig / h_work

        def r_x(x: int) -> int:
            return int(round(mx * x, 0))

        def r_y(y: int) -> int:
            return int(round(my * y, 0))

        is_open_results = img.get_results(
        ).get_results_for_processor_super_class(IsOpenResult)
        start_y = 0
        for i, is_open_result in enumerate(is_open_results):
            face_landmarks = is_open_result.face_landmarks  # FaceLandmarsks
            try:
                result_short_name = is_open_result.get_processor().get_name(
                ).split('.')[-2]
                lt = face_landmarks.get_actual_face().left_top()
                face_result = face_landmarks.get_face_result(
                )  # FaceDetectorResult:
                face_processor = face_result.get_processor()
                face_color = face_processor.get_option('color')
                if not face_color:
                    face_color = self.DEFAULT_COLOR
                text = f'{result_short_name:15}: {round(is_open_result.rate, 2)}, {round(is_open_result.open_percents, 2)} %, open={is_open_result.is_open}'
                (text_width,
                 text_height) = cv2.getTextSize(text,
                                                fontFace=self.FONT,
                                                fontScale=self.FONT_SCALE,
                                                thickness=self.THICKNESS)[0]
                # set the text start position
                text_offset_x = int(max(0, r_x(lt.x())))
                text_offset_y = int(
                    max(0,
                        r_y(lt.y()) - ((i + 1) * (text_height + 5))))
                cv2.putText(orig_img_array,
                            text, (text_offset_x, text_offset_y),
                            self.FONT,
                            fontScale=self.FONT_SCALE,
                            color=face_color,
                            thickness=self.THICKNESS)
                start_y = self._draw_indicator(start_y=start_y,
                                               img=orig_img_array,
                                               is_open_result=is_open_result,
                                               name=result_short_name)

            except Exception as e:
                raise e
                print('$' * 5, e)

        return img, ImageProcessorResult(self)
コード例 #9
0
 def _process_body(self, img:Image = None) -> Image:
     return self.get_next_image(), ImageProcessorResult(self)
コード例 #10
0
ファイル: base.py プロジェクト: ivomarvan/quick_faces
 def _process_body(self, img:Image = None) -> Image:
     return self.store(img), ImageProcessorResult(self)