Commit f6c4094e authored by tihmels's avatar tihmels

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	projectmood/process_model.py
parents 95e70429 65c8bf7d
import cv2
# Haarcascades
faceDet_one = cv2.CascadeClassifier('resources/haarcascade/haarcascade_frontalface_default.xml')
faceDet_two = cv2.CascadeClassifier('resources/haarcascade/haarcascade_frontalface_alt2.xml')
faceDet_three = cv2.CascadeClassifier('resources/haarcascade/haarcascade_frontalface_alt.xml')
......@@ -8,18 +8,36 @@ faceDet_four = cv2.CascadeClassifier('resources/haarcascade/haarcascade_frontalf
def extract_faces(image, resize):
"""
Calls the method through which the face is to be found in the image and calls the
method on which the found face continues to be edited
:param image: Input
:param resize: Resize coordinates of the face
:return: The normalized face in the image
"""
faces = find_faces(image)
normalized_faces = [preprocess_face(face, resize) for face in faces]
return normalized_faces
def find_faces(image):
"""
Calls the method to detect the face in the image and cuts it out
:param image: Input
:return: The cutted face
"""
faces_coordinates = locate_faces(image)
cutted_faces = [image[y:y + h, x:x + w] for (x, y, w, h) in faces_coordinates]
return cutted_faces
def preprocess_face(face, resize):
"""
Edit the found face
:param face: Found face
:param resize: Resize coordinates of the face
:return: Edited face
"""
face = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
face = cv2.resize(face, (resize, resize))
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
......@@ -28,6 +46,14 @@ def preprocess_face(face, resize):
def locate_faces(image, scaleFactor=1.1, minNeighbors=6, minSize=(350, 350)):
"""
Find the face in the image with Haarcascades
:param image: Input
:param scaleFactor: Parameter specifying how much the image size is reduced at each image scale
:param minNeighbors: Parameter specifying how many neighbors each candidate rectangle should have to retain it
:param minSize: Minimum possible object size. Objects smaller than that are ignored
:return: Found face
"""
face = faceDet_one.detectMultiScale(image, scaleFactor, minNeighbors, minSize=minSize,
flags=cv2.CASCADE_SCALE_IMAGE)
......
......@@ -73,6 +73,10 @@ def image_preprocessing(image):
def make_sets():
"""
Creates the training set
:return: The created training data
"""
training_data = []
training_labels = []
prediction_data = []
......@@ -96,6 +100,10 @@ def make_sets():
def run_recognizer():
"""
Performs the actual training with Fisherfaces and Logged the results
:return: The correctly recognized faces in percent
"""
training_data, training_labels, prediction_data, prediction_labels = make_sets()
logging.debug('Training...')
......@@ -120,11 +128,13 @@ def run_recognizer():
fishface = cv2.face.FisherFaceRecognizer_create()
metascore = []
# Argument parser
for i in range(1, arguments.iterations + 1):
correct = run_recognizer()
logging.info("{} : {}%".format(i, int(correct)))
metascore.append(correct)
# Argument parser
if arguments.csv:
file = open("resources/csv/{}.csv".format('_'.join(arguments.properties).lower()), "w")
for entry in metascore:
......@@ -134,8 +144,10 @@ if arguments.csv:
logging.info("Fisherface training finished - {}% average\n".format(np.mean(metascore)))
# Argument parser
if not arguments.test:
fishface.write('resources/models/detection_model.xml')
# Argument parser
if arguments.email:
sendMail('Fisherface training finished', body=str(arguments), filepath='resources/models/detection_model.xml')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment