-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (26 loc) · 1.01 KB
/
main.py
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
import cv2
import numpy as np
from insightface.app import FaceAnalysis
from numpy.linalg import norm
def distance(feat1, feat2):
feat1 = feat1.ravel()
feat2 = feat2.ravel()
return abs(np.dot(feat1, feat2) / (norm(feat1) * norm(feat2)))
def main():
app = FaceAnalysis()
app.prepare(ctx_id=0, det_size=(640, 640))
img1 = cv2.imread("ross1.jpg")
img2 = cv2.imread("ross2.jpg")
img3 = cv2.imread("chandler1.jpg")
img4 = cv2.imread("chandler2.jpg")
[person1] = app.get(img1)
[person2] = app.get(img2)
[person3] = app.get(img3)
[person4] = app.get(img4)
people = [("Ross 1", person1), ("Ross 2", person2), ("Chandler 1", person3), ("Chandler 2", person4)]
for i in range(len(people) - 1):
for j in range(i + 1, len(people)):
dist = distance(people[i][1]['embedding'], people[j][1]['embedding'])
print(f"{people[i][0]} vs {people[j][0]}: {'Different' if dist < 0.1 else 'Same'}. Distance: {dist}")
if __name__ == '__main__':
main()