File size: 1,241 Bytes
3888132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 3rd party dependencies
import cv2
import matplotlib.pyplot as plt

# project dependencies
from deepface.modules import streaming
from deepface import DeepFace

img_path = "dataset/img1.jpg"
img = cv2.imread(img_path)

overlay_img_path = "dataset/img6.jpg"
face_objs = DeepFace.extract_faces(overlay_img_path)
overlay_img = face_objs[0]["face"][:, :, ::-1] * 255

overlay_img = cv2.resize(overlay_img, (112, 112))

raw_img = img.copy()

demographies = DeepFace.analyze(img_path=img_path, actions=("age", "gender", "emotion"))
demography = demographies[0]

x = demography["region"]["x"]
y = demography["region"]["y"]
w = demography["region"]["w"]
h = demography["region"]["h"]

img = streaming.highlight_facial_areas(img=img, faces_coordinates=[(x, y, w, h)])

img = streaming.overlay_emotion(
    img=img,
    emotion_probas=demography["emotion"],
    x=x,
    y=y,
    w=w,
    h=h,
)

img = streaming.overlay_age_gender(
    img=img,
    apparent_age=demography["age"],
    gender=demography["dominant_gender"][0:1],
    x=x,
    y=y,
    w=w,
    h=h,
)

img = streaming.overlay_identified_face(
    img=img,
    target_img=overlay_img,
    label="angelina",
    x=x,
    y=y,
    w=w,
    h=h,
)

plt.imshow(img[:, :, ::-1])
plt.show()