mirror of
https://github.com/serengil/deepface.git
synced 2025-06-06 11:35:21 +00:00
streaming code refactored
This commit is contained in:
parent
bef2cc9151
commit
20b990ac07
File diff suppressed because it is too large
Load Diff
55
tests/overlay.py
Normal file
55
tests/overlay.py
Normal file
@ -0,0 +1,55 @@
|
||||
import cv2
|
||||
import matplotlib.pyplot as plt
|
||||
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, target_size=(112, 112))
|
||||
overlay_img = face_objs[0]["face"][:, :, ::-1] * 255
|
||||
|
||||
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()
|
Loading…
x
Reference in New Issue
Block a user