Commit 4918b88e authored by Arne Gerdes's avatar Arne Gerdes

Weiter Kommentare hinzugefügt

parent 36ac2db8
"""
Diese Klasse macht das Training des Models möglich
"""
import cv2
import glob
import random
......@@ -5,15 +9,22 @@ import numpy as np
import sys
import logging
"""
Erstellt und gibt das Log-File aus
"""
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename='logs/process_model.log')
args = sys.argv # liest Input Parameter
"""
Liest Input Parameter
"""
args = sys.argv
logging.debug('Fisherface training initialized')
file = open("{}.csv".format('_'.join(args[1:]).lower()), "w")
def _get_faces_from_emotion(emotion):
"""
Holt alle Dateien zu einer Emotion aus dem Dataset, mischt sie und teilt sie in ein Trainings- und Prognoseset.
......@@ -22,10 +33,16 @@ def _get_faces_from_emotion(emotion):
"""
files = glob.glob('basis_data/dataset/{}/*'.format(emotion))
random.shuffle(files)
training = files[:int(len(files) * 0.8)] # get first 80% of file list
prediction = files[-int(len(files) * 0.2):] # get last 20% of file list
"""
Mischt das Dataset in Trainings- und Vergleichsbilder im Verhältnis 80 zu 20
"""
training = files[:int(len(files) * 0.8)]
prediction = files[-int(len(files) * 0.2):]
return training, prediction
def image_preprocessing(image):
"""
Preprocessing der Dateien
......@@ -37,6 +54,7 @@ def image_preprocessing(image):
blur = cv2.GaussianBlur(gray, (5, 5), 0)
return blur
def make_sets():
training_data = []
training_labels = []
......@@ -55,9 +73,9 @@ def make_sets():
prediction_data.append(img)
prediction_labels.append(emotions.index(emotion))
return training_data, training_labels, prediction_data, prediction_labels
def run_recognizer():
training_data, training_labels, prediction_data, prediction_labels = make_sets()
......@@ -76,14 +94,18 @@ def run_recognizer():
cnt += 1
return ((100 * correct) / (correct + incorrect))
if len(args) > 1:
tags = ', '.join(args[1:])
logging.debug(tags.upper())
emotions = ["happy", "neutral", "surprise"] # Emotion list
"""
Emotions Liste
"""
emotions = ["happy", "neutral", "surprise"]
fishface = cv2.face.FisherFaceRecognizer_create()
# Now run it
metascore = []
for i in range(0, 10):
......@@ -92,8 +114,7 @@ for i in range(0, 10):
logging.debug("{} : {}%".format(i, int(correct)))
metascore.append(correct)
file.close()
logging.debug("{} iterations - {}% average\n".format(len(metascore), np.mean(metascore)))
fishface.write('basis_data/models/detection_model.xml')
\ No newline at end of file
fishface.write('basis_data/models/detection_model.xml')
"""
Dieses Modul ist das Main-Modul. Es lädt das Modell aus models, zeigt ein Webcam-Bild,
Diese Klasse ist das Main-Modul. Es lädt das Modell aus models, zeigt ein Webcam-Bild,
erkennt das Gesicht und seine Emotionen und zeichnet ein Emoticon in das Bild.
"""
......
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