-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecognition.py
32 lines (26 loc) · 991 Bytes
/
Recognition.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
import os
import cv2
import joblib
from datetime import datetime
from PIL import Image
from face_recognition import preprocessing
file_loc = os.path.dirname(os.path.abspath(__file__))
face_recogniser = joblib.load(os.path.join(
file_loc, 'model', 'pretrainedModel.pkl'))
preprocess = preprocessing.ExifOrientationNormalize()
def cv2ToImage(frame):
date = datetime.now()
image_name = "{}.jpg".format(date.isoformat())
image = cv2.imencode(frame, cv2.IMREAD_UNCHANGED)[1]
print(image)
return image.tobytes()
# return (image_name, image[1].tobytes(), 'image/jpeg', {'Expires': '0'})
def recognize_cv2(frame):
pil_img = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
# pil_img = Image.open(cv2ToImage(frame))
img = preprocess(pil_img)
faces = face_recogniser(img)
return [{
'top_prediction': face['top_prediction'],
'bounding_box': face['bb']
} for face in faces]