Arguments: image: an instance of PIL.Image. min_face_size: a float number. thresholds: a list of length 3. nms_thresholds: a list of length 3. Returns: two float numpy arrays of shapes [n_boxes, 5] and [n_boxes, 10],
(
self,
image,
min_face_size=20.0,
thresholds=[0.6, 0.7, 0.8],
nms_thresholds=[0.7, 0.7, 0.7],
)
| 36 | self.onet.eval() |
| 37 | |
| 38 | def detect( |
| 39 | self, |
| 40 | image, |
| 41 | min_face_size=20.0, |
| 42 | thresholds=[0.6, 0.7, 0.8], |
| 43 | nms_thresholds=[0.7, 0.7, 0.7], |
| 44 | ): |
| 45 | """ |
| 46 | Arguments: |
| 47 | image: an instance of PIL.Image. |
| 48 | min_face_size: a float number. |
| 49 | thresholds: a list of length 3. |
| 50 | nms_thresholds: a list of length 3. |
| 51 | |
| 52 | Returns: |
| 53 | two float numpy arrays of shapes [n_boxes, 5] and [n_boxes, 10], |
| 54 | bounding boxes and facial landmarks. |
| 55 | """ |
| 56 | |
| 57 | # this detector only support RGB Image input !!!!!!!!! # todo: fix eas |
| 58 | if type(image) == np.ndarray: |
| 59 | image = Image.fromarray(image) |
| 60 | #image = Image.fromarray(cv2.cvtColor(image,cv2.COLOR_BGR2RGB)) |
| 61 | |
| 62 | # detector need Image Input |
| 63 | |
| 64 | # BUILD AN IMAGE PYRAMID |
| 65 | width, height = image.size |
| 66 | min_length = min(height, width) |
| 67 | |
| 68 | min_detection_size = 12 |
| 69 | factor = 0.707 # sqrt(0.5) |
| 70 | |
| 71 | # scales for scaling the image |
| 72 | scales = [] |
| 73 | |
| 74 | # scales the image so that |
| 75 | # minimum size that we can detect equals to |
| 76 | # minimum face size that we want to detect |
| 77 | m = min_detection_size / min_face_size |
| 78 | min_length *= m |
| 79 | |
| 80 | factor_count = 0 |
| 81 | while min_length > min_detection_size: |
| 82 | scales.append(m * factor ** factor_count) |
| 83 | min_length *= factor |
| 84 | factor_count += 1 |
| 85 | |
| 86 | # STAGE 1 |
| 87 | |
| 88 | # it will be returned |
| 89 | bounding_boxes = [] |
| 90 | |
| 91 | # run P-Net on different scales |
| 92 | for s in scales: |
| 93 | boxes = self.__run_first_stage(image, scale=s, threshold=thresholds[0]) |
| 94 | bounding_boxes.append(boxes) |
| 95 |