diff --git a/FaceRecognition-python.pyproj b/FaceRecognition-python.pyproj
index 59872e9..050cd6e 100644
--- a/FaceRecognition-python.pyproj
+++ b/FaceRecognition-python.pyproj
@@ -20,6 +20,7 @@
+
\ No newline at end of file
diff --git a/Trainer.py b/Trainer.py
index 51bf47f..f4a80fe 100644
--- a/Trainer.py
+++ b/Trainer.py
@@ -3,26 +3,29 @@ from io import BytesIO
import cv2
import numpy as np
-def train(label, path):
+def addPerson(label, ImagesPath, newFileName, oldFileName):
try:
+ #faceFilePath = '/faces/hesham-saeed2'
+ faceFile = '/faces/'+ oldFileName
face_recognizer = cv2.createLBPHFaceRecognizer()
- face_recognizer.load('/faces/hesham-saeed2')
+ face_recognizer.load(faceFile)
except:
print('[ Error ] Problem in init/loading LBPHfacerecognizer')
images = []
labels = []
- image_names = os.listdir(path)
+ image_names = os.listdir(ImagesPath)
for image_name in image_names:
if image_name.startswith('.'):
continue;
image_path = train_path + image_name
- image = cv2.imread(image_path)
+ image = cv2.imread(image_path)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
images.append(gray[y:y+h, x:x+w])
labels.append(label)
- face_recognizer.train(images, np.array(labels))
-
-
\ No newline at end of file
+ face_recognizer.train(images, np.array(labels))
+ face_recognizer.save('/faces/'+newFileName)
+
+
\ No newline at end of file
diff --git a/main.py b/main.py
index fc2761a..fc4d449 100644
--- a/main.py
+++ b/main.py
@@ -12,11 +12,8 @@ try:
except Exception as ex:
print('[ Error ] some depandincies are missing\n'+ str(ex.args))
-
def init():
go = True
- #OpenShifter()
- #if Sensors():
print('Initilizing Camera and cascade components..')
try:
camera = PiCamera()
@@ -115,25 +112,22 @@ def recognize(image):
return 'Saeed'
else:
return 'Unknown'
-
-def Sensors():
-
- while 1:
- try:
- line = ser.readline()
- print(line)
- if 'A' in line:
- return True
- else:
- print('Sensors not OK..')
-
- except:
- print('[ Error ] Can not connect with arduino. Retrying..')
def OpenShifter():
- ser = serial.Serial('/dev/ttyUSB1',9600)
- ser.open()
- ser.write('O')
- ser.close()
+ try:
+ ser = serial.Serial('/dev/ttyUSB1',9600)
+ ser.open()
+ ser.write('O')
+ ser.close()
+ except Exception as ex:
+ print('[ Error ] Can not connect to Arduino at /dev/ttyUSB1 .. \n Trying /dev/ttyUSB0')
+ try:
+ ser = serial.Serial('/dev/ttyUSB0',9600)
+ ser.open()
+ ser.write('O')
+ ser.close()
+ except Exception as ex:
+ print('[ Error ] Can not connect to Arduino at /dev/ttyUSB0')
+
init()