Commit 8efe83f4 authored by Arne Gerdes's avatar Arne Gerdes
Browse files

Code formatiert

parent 666f8d03
from threading import Thread from threading import Thread
import cv2 import cv2
......
import os
import smtplib import smtplib
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import os
def sendMail(subject, to = 'tjado.ihmels@uni-oldenburg.de', body = '', filepath=''):
def sendMail(subject, to='tjado.ihmels@uni-oldenburg.de', body='', filepath=''):
fromaddr = "projectmood18@gmail.com" fromaddr = "projectmood18@gmail.com"
msg = MIMEMultipart() msg = MIMEMultipart()
......
...@@ -11,6 +11,7 @@ def extract_faces(image, resize): ...@@ -11,6 +11,7 @@ def extract_faces(image, resize):
normalized_faces = [preprocess_face(face, resize) 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):
faces_coordinates = locate_faces(image) faces_coordinates = locate_faces(image)
cutted_faces = [image[y:y + h, x:x + w] for (x, y, w, h) in faces_coordinates] cutted_faces = [image[y:y + h, x:x + w] for (x, y, w, h) in faces_coordinates]
...@@ -26,7 +27,6 @@ def preprocess_face(face, resize): ...@@ -26,7 +27,6 @@ def preprocess_face(face, resize):
def locate_faces(image, scaleFactor=1.2, minNeighbors=6, minSize=(100, 100)): def locate_faces(image, scaleFactor=1.2, minNeighbors=6, minSize=(100, 100)):
face = faceDet_one.detectMultiScale(image, scaleFactor, minNeighbors, minSize=minSize, face = faceDet_one.detectMultiScale(image, scaleFactor, minNeighbors, minSize=minSize,
flags=cv2.CASCADE_SCALE_IMAGE) flags=cv2.CASCADE_SCALE_IMAGE)
......
...@@ -2,14 +2,12 @@ ...@@ -2,14 +2,12 @@
Diese Klasse macht das Training des Models möglich Diese Klasse macht das Training des Models möglich
""" """
import argparse import argparse
import cv2
import glob import glob
import random
import numpy as np
import sys
import logging import logging
import random
import cv2
import numpy as np
from email_service import sendMail from email_service import sendMail
logfile = 'logs/process_model.log' logfile = 'logs/process_model.log'
...@@ -26,9 +24,11 @@ Argument Parser erlaubt Parameter für die Verarbeitung anzugeben. ...@@ -26,9 +24,11 @@ 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', 'sadness', '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 classifier') 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')
...@@ -52,6 +52,7 @@ logging.info('Fisherface training started') ...@@ -52,6 +52,7 @@ logging.info('Fisherface training started')
if email: if email:
sendMail('Fisherface training started') sendMail('Fisherface training started')
def _get_faces_from_emotion(emotion): 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. Holt alle Dateien zu einer Emotion aus dem Dataset, mischt sie und teilt sie in ein Trainings- und Prognoseset.
...@@ -78,7 +79,7 @@ def image_preprocessing(image): ...@@ -78,7 +79,7 @@ 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(2.0, (8,8)) clahe = cv2.createCLAHE(2.0, (8, 8))
norm = clahe.apply(gray) norm = clahe.apply(gray)
return norm return norm
...@@ -122,18 +123,19 @@ def run_recognizer(): ...@@ -122,18 +123,19 @@ def run_recognizer():
cnt += 1 cnt += 1
return ((100 * correct) / (correct + incorrect)) return ((100 * correct) / (correct + incorrect))
""" """
Emotions Liste Emotions Liste
""" """
fishface = cv2.face.FisherFaceRecognizer_create() fishface = cv2.face.FisherFaceRecognizer_create()
metascore = [] metascore = []
for i in range(1, iterations+1): for i in range(1, iterations + 1):
correct = run_recognizer() correct = run_recognizer()
logging.info("{} : {}%".format(i, int(correct))) logging.info("{} : {}%".format(i, int(correct)))
metascore.append(correct) metascore.append(correct)
if i % (int(iterations/4)) == 0 and email: if i % (int(iterations / 4)) == 0 and email:
sendMail(str(i) + ' iterations done', body='up-to-date average: {}%'.format(np.mean(metascore))) sendMail(str(i) + ' iterations done', body='up-to-date average: {}%'.format(np.mean(metascore)))
if csv: if csv:
......
import cv2 import argparse
import glob import glob
import logging import logging
import argparse import os
import shutil import shutil
import sys import sys
import os import cv2
from email_service import sendMail from email_service import sendMail
from face_detect import locate_faces from face_detect import locate_faces
...@@ -23,9 +22,11 @@ Argument Parser erlaubt Parameter für die Verarbeitung anzugeben. ...@@ -23,9 +22,11 @@ Argument Parser erlaubt Parameter für die Verarbeitung anzugeben.
parser = argparse.ArgumentParser(description='Sorted Set Face Creator Application') parser = argparse.ArgumentParser(description='Sorted Set Face Creator Application')
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')
parser.add_argument('-n', action='store', dest='minNeighbors', default=6, type=int, help='min neighbors - haar') parser.add_argument('-n', action='store', dest='minNeighbors', default=6, type=int, help='min neighbors - haar')
...@@ -43,7 +44,6 @@ minNeighbors = arguments.minNeighbors ...@@ -43,7 +44,6 @@ minNeighbors = arguments.minNeighbors
minSize = arguments.minSize minSize = arguments.minSize
email = arguments.email email = arguments.email
if len(glob.glob(dataset_path + '*')) > 0: if len(glob.glob(dataset_path + '*')) > 0:
deleteDataset = input( deleteDataset = input(
'Im Dataset befinden sich Dateien. Durch diesen Vorgang werden die existierenden Daten gelöscht. Fortfahren (y/n): ') 'Im Dataset befinden sich Dateien. Durch diesen Vorgang werden die existierenden Daten gelöscht. Fortfahren (y/n): ')
...@@ -92,9 +92,10 @@ def detect_faces(emotion): ...@@ -92,9 +92,10 @@ def detect_faces(emotion):
out = cv2.resize(gray, (resizeFactor, resizeFactor)) # Resize face so all images have same size out = cv2.resize(gray, (resizeFactor, resizeFactor)) # Resize face so all images have same size
success = cv2.imwrite(dataset_path + '{}/{}.jpg'.format(emotion, fileNumber), out) # Write image success = cv2.imwrite(dataset_path + '{}/{}.jpg'.format(emotion, fileNumber), out) # Write image
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 ' + dataset_path + '{}/{}.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:
...@@ -104,6 +105,7 @@ def detect_faces(emotion): ...@@ -104,6 +105,7 @@ def detect_faces(emotion):
totalFiles += 1 # Increment image number totalFiles += 1 # Increment image number
fileNumber += 1 fileNumber += 1
if email: if email:
sendMail('Facedetector started notification') sendMail('Facedetector started notification')
......
...@@ -5,20 +5,22 @@ erkennt das Gesicht und seine Emotionen und zeichnet ein Emoticon in das Bild. ...@@ -5,20 +5,22 @@ erkennt das Gesicht und seine Emotionen und zeichnet ein Emoticon in das Bild.
import argparse import argparse
import cv2 import cv2
import numpy as np
from RingBuffer import RingBuffer from RingBuffer import RingBuffer
from WebcamVideoStream import WebcamVideoStream from WebcamVideoStream import WebcamVideoStream
from face_detect import extract_faces 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
parser = argparse.ArgumentParser(description='ProjectMood Camplication') 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('-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('-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('-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') parser.add_argument('--model', action='store', dest='model', default='resources/models/detection_model.xml',
help='path to model')
arguments = parser.parse_args() arguments = parser.parse_args()
def _load_emoticons(emotions): def _load_emoticons(emotions):
""" """
Lädt die Emoticons aus dem emojis Ordner. Lädt die Emoticons aus dem emojis Ordner.
......
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