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

Code formatiert

parent 666f8d03
......@@ -7,4 +7,4 @@ class RingBuffer:
self.data.append(x)
def get(self):
return self.data
\ No newline at end of file
return self.data
from threading import Thread
import cv2
......
import os
import smtplib
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
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"
msg = MIMEMultipart()
......@@ -31,4 +32,4 @@ def sendMail(subject, to = 'tjado.ihmels@uni-oldenburg.de', body = '', filepath=
server.login(fromaddr, "kR2-zgY-BTf-gRT")
text = msg.as_string()
server.sendmail(fromaddr, to, text)
server.quit()
\ No newline at end of file
server.quit()
......@@ -11,6 +11,7 @@ def extract_faces(image, resize):
normalized_faces = [preprocess_face(face, resize) for face in faces]
return normalized_faces
def find_faces(image):
faces_coordinates = locate_faces(image)
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):
def locate_faces(image, scaleFactor=1.2, minNeighbors=6, minSize=(100, 100)):
face = faceDet_one.detectMultiScale(image, scaleFactor, minNeighbors, minSize=minSize,
flags=cv2.CASCADE_SCALE_IMAGE)
......@@ -34,19 +34,19 @@ def locate_faces(image, scaleFactor=1.2, minNeighbors=6, minSize=(100, 100)):
return face
face = faceDet_two.detectMultiScale(image, scaleFactor, minNeighbors, minSize=minSize,
flags=cv2.CASCADE_SCALE_IMAGE)
flags=cv2.CASCADE_SCALE_IMAGE)
if len(face) == 1:
return face
face = faceDet_three.detectMultiScale(image, scaleFactor, minNeighbors, minSize=minSize,
flags=cv2.CASCADE_SCALE_IMAGE)
flags=cv2.CASCADE_SCALE_IMAGE)
if len(face) == 1:
return face
face = faceDet_four.detectMultiScale(image, scaleFactor, minNeighbors, minSize=minSize,
flags=cv2.CASCADE_SCALE_IMAGE)
flags=cv2.CASCADE_SCALE_IMAGE)
if len(face) == 1:
return face
......
......@@ -2,14 +2,12 @@
Diese Klasse macht das Training des Models möglich
"""
import argparse
import cv2
import glob
import random
import numpy as np
import sys
import logging
import random
import cv2
import numpy as np
from email_service import sendMail
logfile = 'logs/process_model.log'
......@@ -26,9 +24,11 @@ Argument Parser erlaubt Parameter für die Verarbeitung anzugeben.
"""
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('-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('--test', action='store_true', help='prevent writing new model to classifier')
parser.add_argument('--csv', action='store_true', help='activate csv processing')
......@@ -52,6 +52,7 @@ logging.info('Fisherface training started')
if email:
sendMail('Fisherface training started')
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.
......@@ -78,7 +79,7 @@ def image_preprocessing(image):
"""
img = cv2.imread(image) # open image
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)
return norm
......@@ -122,18 +123,19 @@ def run_recognizer():
cnt += 1
return ((100 * correct) / (correct + incorrect))
"""
Emotions Liste
"""
fishface = cv2.face.FisherFaceRecognizer_create()
metascore = []
for i in range(1, iterations+1):
for i in range(1, iterations + 1):
correct = run_recognizer()
logging.info("{} : {}%".format(i, int(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)))
if csv:
......
import cv2
import argparse
import glob
import logging
import argparse
import os
import shutil
import sys
import os
import cv2
from email_service import sendMail
from face_detect import locate_faces
......@@ -23,9 +22,11 @@ Argument Parser erlaubt Parameter für die Verarbeitung anzugeben.
parser = argparse.ArgumentParser(description='Sorted Set Face Creator Application')
parser.add_argument('--source', action='store', dest='img_source', default='resources/img_data/sorted_set/',
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('-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,
help='scale factor - haar')
parser.add_argument('-n', action='store', dest='minNeighbors', default=6, type=int, help='min neighbors - haar')
......@@ -43,7 +44,6 @@ minNeighbors = arguments.minNeighbors
minSize = arguments.minSize
email = arguments.email
if len(glob.glob(dataset_path + '*')) > 0:
deleteDataset = input(
'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):
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
if not success:
logging.error('Problem while writing file ' + f + ' occurred...' )
logging.error('Problem while writing file ' + f + ' occurred...')
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:
logging.error('Some error with ' + f)
if email:
......@@ -104,6 +105,7 @@ def detect_faces(emotion):
totalFiles += 1 # Increment image number
fileNumber += 1
if email:
sendMail('Facedetector started notification')
......
......@@ -5,20 +5,22 @@ erkennt das Gesicht und seine Emotionen und zeichnet ein Emoticon in das Bild.
import argparse
import cv2
import numpy as np
from RingBuffer import RingBuffer
from WebcamVideoStream import WebcamVideoStream
from face_detect import extract_faces
from image_commons import nparray_as_image, draw_with_alpha
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('-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')
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):
"""
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