Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/learnopencv
Path: blob/master/Face-Recognition-with-ArcFace/align/visualization_utils.py
3142 views
1
from PIL import ImageDraw
2
3
4
def show_results(img, bounding_boxes, facial_landmarks = []):
5
"""Draw bounding boxes and facial landmarks.
6
Arguments:
7
img: an instance of PIL.Image.
8
bounding_boxes: a float numpy array of shape [n, 5].
9
facial_landmarks: a float numpy array of shape [n, 10].
10
Returns:
11
an instance of PIL.Image.
12
"""
13
img_copy = img.copy()
14
draw = ImageDraw.Draw(img_copy)
15
16
for b in bounding_boxes:
17
draw.rectangle([
18
(b[0], b[1]), (b[2], b[3])
19
], outline = 'white')
20
21
inx = 0
22
for p in facial_landmarks:
23
for i in range(5):
24
draw.ellipse([
25
(p[i] - 1.0, p[i + 5] - 1.0),
26
(p[i] + 1.0, p[i + 5] + 1.0)
27
], outline = 'blue')
28
29
return img_copy
30