forked from Nishant2907/Godseye
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testCode[efficient].py
29 lines (24 loc) · 985 Bytes
/
testCode[efficient].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
# THIS IS A SHORTENED CODE
# WE ARE ALSO CHECKING THE TIME TAKEN BY THE CODE IF IMAGE IS NOT SHOWN
from cv2 import cv2
import face_recognition
import os
import time
# FOR CHECKING THE CPU TIME
startTimer = time.process_time()
# FUNCTION TO GET FACE LOCATION AND FACE ENCODINGS
def returnImageDetails(imagePath):
image = face_recognition.load_image_file(imagePath)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
location = face_recognition.face_locations(image)[0]
encode = face_recognition.face_encodings(image)[0]
return [location, encode]
imagePath = os.listdir('assets')
testImageDetails = returnImageDetails('testAssets/johnny-depp.jpg')
for i in range(len(imagePath)):
imageDetails = returnImageDetails('assets/' + imagePath[i])
result = []
result = face_recognition.compare_faces([imageDetails[1]], testImageDetails[1])
print(imagePath[i], result)
# FOR PRINTING THE TIME TAKEN TO EXECUTE THE CODE
print(time.process_time() - startTimer)