updated trainer

This commit is contained in:
HeshamTB 2018-11-23 13:02:32 +00:00
parent 202a3e81d8
commit 9c6e3999b5
2 changed files with 24 additions and 14 deletions

View File

@ -98,15 +98,15 @@ def recognize(image):
subjects = ['','Hesham','Saeed']
face_recognizer = cv2.createLBPHFaceRecognizer()
face_recognizer.load('faces/Hesham-Saeed2')
face_recognizer.load('faces/m')
img = image.copy()
label= face_recognizer.predict(img)
print(label)
if label[0] == 1 and int(label[1]) < 120:
return 'Hesham'
elif label[0] == 2 and int(label[1]) < 90:
return 'Saeed'
elif label[0] == 3 and int(label[1]) < 120:
elif label[0] == 2 and int(label[1]) < 120:
return 'Safwan'
elif label[0] == 4 and int(label[1]) < 120:
return 'Hesham2'
else:
return 'Unknown'

View File

@ -7,12 +7,14 @@ import os
import sys
picCount = 0
picCount = 0
new = False
def start():
print('Starting training..')
label = int(input('Label (Integer): '))
picCount = int(input('Number of Photos: '))
global new
new = promptNew()
if new:
newFileName = str(raw_input('New File name: '))
@ -23,8 +25,8 @@ def start():
oldFileName = str(raw_input('Old File name: '))
newFileName = str(raw_input('New File name: '))
clearTrainFolder()
print('Press any key to start capture')
cv2.waitKey(500)
print('Press any key to start capture..')
dum = input('')
capture(picCount)
addPerson(label, newFileName, oldFileName)
@ -39,7 +41,12 @@ def addPerson(label, newFileName, oldFileName):
#faceFilePath = '/faces/hesham-saeed2'
faceFile = 'faces/'+ oldFileName
face_recognizer = cv2.createLBPHFaceRecognizer()
face_recognizer.load(faceFile)
global new
if new:
print 'new file. skipping load function'
else:
print 'loading old file'
face_recognizer.load(faceFile)
except:
print('[ Error ] Problem in init/loading LBPHfacerecognizer')
sys.exit()
@ -57,8 +64,11 @@ def addPerson(label, newFileName, oldFileName):
for (x,y,w,h) in faces:
images.append(gray[y:y+h, x:x+w])
labels.append(label)
print('Learned '+ image_name)
face_recognizer.update(images, np.array(labels))
print('Learning '+ image_name)
if new:
face_recognizer.train(images, np.array(labels))
else:
face_recognizer.update(images, np.array(labels))
face_recognizer.save('faces/'+newFileName)
print('Updated and saved file in faces/'+newFileName)
@ -84,11 +94,11 @@ def capture(count):
print('Done!')
def promptNew():
new = raw_input('Make new File? (y/n): ')
if new == 'y':
filemode = raw_input('Make new File? (y/n): ')
if filemode == 'y':
return True
elif new == 'n':
return = False
elif filemode == 'n':
return False
else:
print('incorrect input')
promptNew()