Detect biggest face in image :param img: cv::mat HxWx3 RGB :return: 4
(img)
| 19 | yield x, y, (right - x), (bottom - y) |
| 20 | |
| 21 | def detect_biggest_face(img): |
| 22 | ''' |
| 23 | Detect biggest face in image |
| 24 | :param img: cv::mat HxWx3 RGB |
| 25 | :return: 4 <x,y,w,h> |
| 26 | ''' |
| 27 | # detect faces |
| 28 | bbs = face_recognition.face_locations(img) |
| 29 | |
| 30 | max_area = float('-inf') |
| 31 | max_area_i = 0 |
| 32 | for i, (y, right, bottom, x) in enumerate(bbs): |
| 33 | area = (right - x) * (bottom - y) |
| 34 | if max_area < area: |
| 35 | max_area = area |
| 36 | max_area_i = i |
| 37 | |
| 38 | if max_area != float('-inf'): |
| 39 | y, right, bottom, x = bbs[max_area_i] |
| 40 | return x, y, (right - x), (bottom - y) |
| 41 | |
| 42 | return None |
| 43 | |
| 44 | def crop_face_with_bb(img, bb): |
| 45 | ''' |
nothing calls this directly
no outgoing calls
no test coverage detected