added date for unknown faces

This commit is contained in:
HeshamTB 2018-12-04 19:03:00 +00:00
parent 29fa3a3335
commit d11220d70c

11
main.py
View File

@ -1,11 +1,11 @@
from time import sleep from time import sleep
from io import BytesIO
from PIL import Image from PIL import Image
import os import os
import serial import serial
import sys import sys
import json import json
import datetime
try: try:
import numpy as np import numpy as np
@ -67,8 +67,8 @@ def start( camera, face_cascade):
roi_gray = gray[y:y+h, x:x+w] roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w] roi_color = img[y:y+h, x:x+w]
person = recognize(roi_gray, face_recognizer, names) person = recognize(roi_gray, face_recognizer, names)
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),1)
cv2.putText(img, person, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.7, (255, 0, 0), 2) cv2.putText(img, person, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.7, (0,255,0), 2)
except: except:
print('[ Error ] Recognition fail') print('[ Error ] Recognition fail')
if person == 'unknown': if person == 'unknown':
@ -76,9 +76,10 @@ def start( camera, face_cascade):
try: try:
RGBImage = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) RGBImage = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
image = Image.fromarray(RGBImage) image = Image.fromarray(RGBImage)
image.save('lastUnknown.png') image.save('unknown/'+str(datetime.datetime.now())+'.png')
except: except Exception as ex :
print('[ Error ] Saving unkown fail') print('[ Error ] Saving unkown fail')
print(ex)
else: else:
print('Found '+person) print('Found '+person)
OpenShifter() OpenShifter()