save unknown & exception handling & performance
This commit is contained in:
parent
7d37fa8d91
commit
3660a2e9eb
23
main.py
23
main.py
@ -1,6 +1,7 @@
|
||||
|
||||
from time import sleep
|
||||
from io import BytesIO
|
||||
from PIL import Image
|
||||
import os
|
||||
import serial
|
||||
import sys
|
||||
@ -62,19 +63,27 @@ def start( camera, face_cascade):
|
||||
for (x,y,w,h) in faces:
|
||||
i += 1
|
||||
j += 1
|
||||
roi_gray = gray[y:y+h, x:x+w]
|
||||
roi_color = img[y:y+h, x:x+w]
|
||||
person = recognize(roi_gray, face_recognizer, names)
|
||||
try:
|
||||
roi_gray = gray[y:y+h, x:x+w]
|
||||
roi_color = img[y:y+h, x:x+w]
|
||||
person = recognize(roi_gray, face_recognizer, names)
|
||||
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
|
||||
cv2.putText(img, person, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.7, (255, 0, 0), 2)
|
||||
except:
|
||||
print('[ Error ] Recognition fail')
|
||||
if person == 'unknown':
|
||||
print('Found unknown person')
|
||||
try:
|
||||
RGBImage = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
||||
image = Image.fromarray(RGBImage)
|
||||
image.save('lastUnknown.png')
|
||||
except:
|
||||
print('[ Error ] Saving unkown fail')
|
||||
else:
|
||||
print('Found '+person)
|
||||
OpenShifter()
|
||||
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
|
||||
cv2.putText(img, person, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.7, (255, 0, 0), 2)
|
||||
|
||||
cv2.imshow('image',img)
|
||||
cv2.waitKey(100)
|
||||
cv2.waitKey(1)
|
||||
rawCapture.truncate(0)
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
cv2.destroyAllWindows()
|
||||
|
Loading…
Reference in New Issue
Block a user