Compare commits

..

No commits in common. "master" and "ard-refactor" have entirely different histories.

3 changed files with 106 additions and 113 deletions

View File

@ -1 +1 @@
### Python code to run in Raspberry Pi with PiCamera to recognize certin faces.
### Python code to run in Raspberry Pi with PiCamera to recognize certin faces and send a Serial signal 'o' to be received by arduino.

View File

@ -64,7 +64,7 @@ def start( camera, face_cascade):
img = rawCapture.array
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3,5)
i = 0
i = 0;
for (x,y,w,h) in faces:
i += 1
j += 1
@ -110,8 +110,6 @@ def recognize(image,face_recognizer, names):
print(str(label) + ' >>'+names[label[0]])
return names[label[0]]
#def DrawSquares(image,gray,faces,color):
def OpenShifter():
try:
ser = serial.Serial('/dev/ttyUSB0',9600)

View File

@ -7,10 +7,10 @@ import os
import sys
import json
picCount = 0
new = False
def start():
print('Starting training..')
label = int(input('Label (Integer): '))
@ -32,14 +32,12 @@ def start():
addPerson(label, newFileName, oldFileName)
addName(name)
def clearTrainFolder():
print('clearing train folder')
filelist = [ f for f in os.listdir('train/') if f.endswith(".jpg") ]
for f in filelist:
os.remove(os.path.join('train/', f))
def addPerson(label, newFileName, oldFileName):
try:
#faceFilePath = '/faces/hesham-saeed2'
@ -47,9 +45,9 @@ def addPerson(label, newFileName, oldFileName):
face_recognizer = cv2.createLBPHFaceRecognizer()
global new
if new:
print('new file. skipping load function')
print 'new file. skipping load function'
else:
print('loading old file')
print 'loading old file'
face_recognizer.load(faceFile)
except:
print('[ Error ] Problem in init/loading LBPHfacerecognizer')
@ -78,7 +76,6 @@ def addPerson(label, newFileName, oldFileName):
face_recognizer.save('faces/'+newFileName)
print('Updated and saved file in faces/'+newFileName)
def capture(count):
try:
print('Initializing camera')
@ -100,7 +97,6 @@ def capture(count):
cv2.destroyAllWindows()
print('Done!')
def promptNew():
filemode = raw_input('Make new File? (y/n): ')
if filemode == 'y':
@ -111,8 +107,8 @@ def promptNew():
print('incorrect input')
promptNew()
def addName(newName):
with open("faces/names.json", "r") as read_file:
exist = False
namesJson = json.load(read_file)
@ -129,5 +125,4 @@ def addName(newName):
with open("faces/names.json","w") as write_file:
json.dump(names,write_file)
start()