-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathface_recognition.py
More file actions
30 lines (23 loc) · 975 Bytes
/
face_recognition.py
File metadata and controls
30 lines (23 loc) · 975 Bytes
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
import capybara as cb
from fire import Fire
import pyface as pf
RESOURCE_DIR = cb.get_curdir(__file__).parent / "tests" / "resources"
def main(
src_path: str = str(RESOURCE_DIR / "EmmaWatson1.jpg"),
tgt_path: str = str(RESOURCE_DIR / "face_bank" / "EmmaWatson.jpg"),
):
face_detection = pf.build_face_detection()
face_recognition = pf.build_face_recognition()
face_compare = pf.FaceCompare(face_recognition.mapping_table)
src_img = cb.imread(src_path)
tgt_img = cb.imread(tgt_path)
lmks = [p["lmk5pts"][0] for p in face_detection([src_img, tgt_img])]
out_folder = cb.get_curdir(__file__) / "output"
out_folder.mkdir(exist_ok=True, parents=True)
results = face_recognition([src_img, tgt_img], lmks)
src_emb = results[0]["embeddings"]
tgt_emb = results[1]["embeddings"]
sim, is_same = face_compare(src_emb, tgt_emb)
print(f"Similarity: {sim:.5f}, Is same: {is_same}")
if __name__ == "__main__":
Fire(main)