(self, src_image, face_box=None, pre_pts=None, iterations=3)
| 49 | return landmark, euler_rad, prob |
| 50 | |
| 51 | def forward(self, src_image, face_box=None, pre_pts=None, iterations=3): |
| 52 | if pre_pts is None: |
| 53 | if face_box is None: |
| 54 | # Detect max size face |
| 55 | bounding_boxes, _, score = self.face_detector.detect(src_image) |
| 56 | print("facedet score", score) |
| 57 | if len(bounding_boxes) == 0: |
| 58 | return None |
| 59 | bbox = np.zeros(4, dtype=np.float32) |
| 60 | if len(bounding_boxes) >= 1: |
| 61 | max_area = 0.0 |
| 62 | for each_bbox in bounding_boxes: |
| 63 | area = (each_bbox[2] - each_bbox[0]) * ( |
| 64 | each_bbox[3] - each_bbox[1] |
| 65 | ) |
| 66 | if area > max_area: |
| 67 | bbox[:4] = each_bbox[:4] |
| 68 | max_area = area |
| 69 | else: |
| 70 | bbox = bounding_boxes[0, :4] |
| 71 | else: |
| 72 | bbox = face_box.copy() |
| 73 | M_Face = get_warp_mat_bbox( |
| 74 | bbox, 0, self.face_image_size, expand_ratio=self.expand_ratio |
| 75 | ) |
| 76 | else: |
| 77 | left_eye_corner = pre_pts[74] |
| 78 | right_eye_corner = pre_pts[96] |
| 79 | |
| 80 | radian = np.arctan2( |
| 81 | right_eye_corner[1] - left_eye_corner[1], |
| 82 | right_eye_corner[0] - left_eye_corner[0] + 0.00000001, |
| 83 | ) |
| 84 | M_Face = get_warp_mat_bbox_by_gt_pts_float( |
| 85 | pre_pts, |
| 86 | np.rad2deg(radian), |
| 87 | self.face_image_size, |
| 88 | expand_ratio=self.expand_ratio, |
| 89 | ) |
| 90 | |
| 91 | face_input = cv2.warpAffine( |
| 92 | src_image, M_Face, (self.face_image_size, self.face_image_size) |
| 93 | ) |
| 94 | landmarks, euler, prob = self.onnx_infer(face_input) |
| 95 | landmarks = transform_points(landmarks, M_Face, invert=True) |
| 96 | |
| 97 | # Repeat |
| 98 | for i in range(iterations - 1): |
| 99 | M_Face = get_warp_mat_bbox_by_gt_pts_float( |
| 100 | landmarks, |
| 101 | np.rad2deg(euler[2]), |
| 102 | self.face_image_size, |
| 103 | expand_ratio=self.expand_ratio, |
| 104 | ) |
| 105 | face_input = cv2.warpAffine( |
| 106 | src_image, M_Face, (self.face_image_size, self.face_image_size) |
| 107 | ) |
| 108 | landmarks, euler, prob = self.onnx_infer(face_input) |
nothing calls this directly
no test coverage detected