Commit 0e4410dd authored by tihmels's avatar tihmels
Browse files

kleine Verbesserungen

parent 3dc1384f
...@@ -6,9 +6,9 @@ faceDet_three = cv2.CascadeClassifier('resources/haarcascade/haarcascade_frontal ...@@ -6,9 +6,9 @@ faceDet_three = cv2.CascadeClassifier('resources/haarcascade/haarcascade_frontal
faceDet_four = cv2.CascadeClassifier('resources/haarcascade/haarcascade_frontalface_alt_tree.xml') faceDet_four = cv2.CascadeClassifier('resources/haarcascade/haarcascade_frontalface_alt_tree.xml')
def extract_faces(image): def extract_faces(image, resize):
faces = find_faces(image) faces = find_faces(image)
normalized_faces = [preprocess_face(face) for face in faces] normalized_faces = [preprocess_face(face, resize) for face in faces]
return normalized_faces return normalized_faces
def find_faces(image): def find_faces(image):
...@@ -17,9 +17,9 @@ def find_faces(image): ...@@ -17,9 +17,9 @@ def find_faces(image):
return cutted_faces return cutted_faces
def preprocess_face(face): def preprocess_face(face, resize):
face = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY) face = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
face = cv2.resize(face, (250, 250)) face = cv2.resize(face, (resize, resize))
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8)) clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
face = clahe.apply(face) face = clahe.apply(face)
return face return face
......
...@@ -14,7 +14,7 @@ emotions = ["neutral", "anger", "contempt", "disgust", "fear", "happy", "sadness ...@@ -14,7 +14,7 @@ emotions = ["neutral", "anger", "contempt", "disgust", "fear", "happy", "sadness
""" """
Liste mit den Dateiordnern aller Teilnehmer Liste mit den Dateiordnern aller Teilnehmer
""" """
participants = glob.glob("img_data/source_emotion/*") participants = glob.glob("resources/img_data/source_emotion/*")
for x in participants: for x in participants:
...@@ -27,7 +27,7 @@ for x in participants: ...@@ -27,7 +27,7 @@ for x in participants:
""" """
Sessionnummer Sessionnummer
""" """
current_session = files[31:-30] current_session = files[39:-30]
""" """
Öffnet die zur aktuellen Emotion korrelierende .txt Datei Öffnet die zur aktuellen Emotion korrelierende .txt Datei
...@@ -35,11 +35,11 @@ for x in participants: ...@@ -35,11 +35,11 @@ for x in participants:
file = open(files, 'r') file = open(files, 'r')
""" """
In der Datei steht die aktuell betrachtete Emotion, kodiert als folat-Wert In der Datei steht die aktuell betrachtete Emotion, kodiert als float-Wert
""" """
emotion = int(float(file.readline())) emotion = int(float(file.readline()))
source_emotions = glob.glob("img_data/source_images/%s/%s/*.png" % (number, current_session)) source_emotions = glob.glob("resources/img_data/source_images/%s/%s/*.png" % (number, current_session))
source_emotions.sort() source_emotions.sort()
""" """
...@@ -58,8 +58,8 @@ for x in participants: ...@@ -58,8 +58,8 @@ for x in participants:
Für den neutralen Ausdruck Für den neutralen Ausdruck
Für die Emotion Für die Emotion
""" """
dest_neut = "img_data/sorted_set/neutral/%s" % sourcefile_neutral[36:] dest_neut = "resources/img_data/sorted_set/neutral/%s" % sourcefile_neutral[44:]
dest_emot = "img_data/sorted_set/%s/%s" % (emotions[emotion], sourcefile_emotion[36:]) dest_emot = "resources/img_data/sorted_set/%s/%s" % (emotions[emotion], sourcefile_emotion[44:])
"""Kopiert Dateien""" """Kopiert Dateien"""
copyfile(sourcefile_neutral, dest_neut) copyfile(sourcefile_neutral, dest_neut)
......
...@@ -28,9 +28,9 @@ Argument Parser erlaubt Parameter für die Verarbeitung anzugeben. ...@@ -28,9 +28,9 @@ Argument Parser erlaubt Parameter für die Verarbeitung anzugeben.
parser = argparse.ArgumentParser(description='Process Model Application') parser = argparse.ArgumentParser(description='Process Model Application')
parser.add_argument('--dataset', action='store', dest='dataset', default='resources/img_data/dataset/', help='path to dataset') parser.add_argument('--dataset', action='store', dest='dataset', default='resources/img_data/dataset/', help='path to dataset')
parser.add_argument('-i', action='store', dest='iterations', type=int, default=30, help='number of iterations') parser.add_argument('-i', action='store', dest='iterations', type=int, default=30, help='number of iterations')
parser.add_argument('-e', action='append', dest='emotions', default=['happy', 'neutral', 'surprise'], help='declare emotions that should be processed') parser.add_argument('-e', action='append', dest='emotions', default=['happy', 'neutral', 'sadness', 'surprise'], help='declare emotions that should be processed')
parser.add_argument('-p', action='append', dest='properties', help='pre-processing steps for logging') parser.add_argument('-p', action='append', dest='properties', help='pre-processing steps for logging')
parser.add_argument('--test', action='store_true', help='prevent writing new model to file system') parser.add_argument('--test', action='store_true', help='prevent writing new model to classifier')
parser.add_argument('--csv', action='store_true', help='activate csv processing') parser.add_argument('--csv', action='store_true', help='activate csv processing')
parser.add_argument('--email', action='store_true', help='activate email notifications') parser.add_argument('--email', action='store_true', help='activate email notifications')
arguments = parser.parse_args() arguments = parser.parse_args()
...@@ -78,9 +78,9 @@ def image_preprocessing(image): ...@@ -78,9 +78,9 @@ def image_preprocessing(image):
""" """
img = cv2.imread(image) # open image img = cv2.imread(image) # open image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8)) clahe = cv2.createCLAHE(2.0, (8,8))
face = clahe.apply(gray) norm = clahe.apply(gray)
return face return norm
def make_sets(): def make_sets():
...@@ -146,7 +146,7 @@ if csv: ...@@ -146,7 +146,7 @@ if csv:
logging.info("Fisherface training finished - {}% average\n".format(np.mean(metascore))) logging.info("Fisherface training finished - {}% average\n".format(np.mean(metascore)))
if not test: if not test:
fishface.write('img_data/models/detection_model.xml') fishface.write('resources/models/detection_model.xml')
if email: if email:
sendMail('Fisherface training finished') sendMail('Fisherface training finished')
...@@ -24,7 +24,7 @@ parser = argparse.ArgumentParser(description='Sorted Set Face Creator Applicatio ...@@ -24,7 +24,7 @@ parser = argparse.ArgumentParser(description='Sorted Set Face Creator Applicatio
parser.add_argument('--source', action='store', dest='img_source', default='resources/img_data/sorted_set/', parser.add_argument('--source', action='store', dest='img_source', default='resources/img_data/sorted_set/',
help='path to image source') help='path to image source')
parser.add_argument('--dataset', action='store', dest='dataset', default='resources/img_data/dataset/', help='path to dataset') parser.add_argument('--dataset', action='store', dest='dataset', default='resources/img_data/dataset/', help='path to dataset')
parser.add_argument('--r', action='store', dest='resize', default=150, type=int, help='resize factor') parser.add_argument('-r', action='store', dest='resize', default=150, type=int, help='resize factor')
parser.add_argument('-e', action='append', dest='emotions', default=['happy', 'neutral', 'surprise'], help='declare emotions that should be processed') parser.add_argument('-e', action='append', dest='emotions', default=['happy', 'neutral', 'surprise'], help='declare emotions that should be processed')
parser.add_argument('-c', action='store', dest='scaleFactor', default=1.1, type=float, parser.add_argument('-c', action='store', dest='scaleFactor', default=1.1, type=float,
help='scale factor - haar') help='scale factor - haar')
...@@ -79,7 +79,7 @@ def detect_faces(emotion): ...@@ -79,7 +79,7 @@ def detect_faces(emotion):
facefeatures = locate_faces(gray, scaleFactor, minNeighbors, (minSize, minSize)) facefeatures = locate_faces(gray, scaleFactor, minNeighbors, (minSize, minSize))
if facefeatures is '': if facefeatures is '':
logging.info('No face detected ' + f) logging.info('No face detected in ' + f)
undetected.append(f) undetected.append(f)
if len(undetected) % 200 == 0 and email: if len(undetected) % 200 == 0 and email:
sendMail('Already ' + str(len(undetected)) + ' not detected faces', filepath=logfile) sendMail('Already ' + str(len(undetected)) + ' not detected faces', filepath=logfile)
...@@ -94,7 +94,7 @@ def detect_faces(emotion): ...@@ -94,7 +94,7 @@ def detect_faces(emotion):
if not success: if not success:
logging.error('Problem while writing file ' + f + ' occurred...' ) logging.error('Problem while writing file ' + f + ' occurred...' )
if email: if email:
sendMail('Problem while writing file', body=f + ' to ' + datasetPath + '{}/{}.jpg'.format(emotion, fileNumber)) sendMail('Problem while writing file', body=f + ' to ' + dataset_path + '{}/{}.jpg'.format(emotion, fileNumber))
except: except:
logging.error('Some error with ' + f) logging.error('Some error with ' + f)
if email: if email:
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
Diese Klasse 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. erkennt das Gesicht und seine Emotionen und zeichnet ein Emoticon in das Bild.
""" """
import argparse
import cv2 import cv2
...@@ -11,6 +12,12 @@ from face_detect import extract_faces ...@@ -11,6 +12,12 @@ from face_detect import extract_faces
from image_commons import nparray_as_image, draw_with_alpha from image_commons import nparray_as_image, draw_with_alpha
import numpy as np import numpy as np
parser = argparse.ArgumentParser(description='ProjectMood Camplication')
parser.add_argument('-b', action='store', dest='buffer', default=10, type=int, help='size of ringbuffer')
parser.add_argument('-e', action='append', dest='emotions', default=['happy', 'neutral', 'sadness', 'surprise'], help='declare emotions that should be detected')
parser.add_argument('-r', action='append', dest='resize', default=150, help='resize factor')
parser.add_argument('--model', action='store', dest='model', default='resources/models/detection_model.xml', help='path to model')
arguments = parser.parse_args()
def _load_emoticons(emotions): def _load_emoticons(emotions):
""" """
...@@ -37,14 +44,14 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name='P ...@@ -37,14 +44,14 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name='P
vc = WebcamVideoStream().start() vc = WebcamVideoStream().start()
""" """
Der RingBuffer speichert die letzten 7 Predictions Der RingBuffer speichert die letzten x Predictions
""" """
buffer = RingBuffer(7) buffer = RingBuffer(arguments.buffer)
frame = vc.read() frame = vc.read()
while True: while True:
for normalized_face in extract_faces(frame): for normalized_face in extract_faces(frame, arguments.resize):
prediction = model.predict(normalized_face) # do prediction prediction = model.predict(normalized_face) # do prediction
""" """
...@@ -56,6 +63,7 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name='P ...@@ -56,6 +63,7 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name='P
Holt die Einträge als Array Holt die Einträge als Array
""" """
predictions = buffer.get() predictions = buffer.get()
print(predictions)
""" """
Kein Eintrag im RingBuffer ist None Kein Eintrag im RingBuffer ist None
...@@ -84,11 +92,11 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name='P ...@@ -84,11 +92,11 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name='P
if __name__ == '__main__': if __name__ == '__main__':
emotions = ['happy', 'neutral', 'surprise'] emotions = arguments.emotions
emoticons = _load_emoticons(emotions) emoticons = _load_emoticons(emotions)
fisher_face = cv2.face.FisherFaceRecognizer_create() fisher_face = cv2.face.FisherFaceRecognizer_create()
"""Lädt das trainierte Model""" """Lädt das trainierte Model"""
fisher_face.read('resources/models/detection_model.xml') fisher_face.read(arguments.model)
show_webcam_and_run(fisher_face, emoticons) show_webcam_and_run(fisher_face, emoticons)
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