Commit c2e98706 authored by tihmels's avatar tihmels
Browse files

Sorted_Set Facedetector für Cluster Einsatz vorbereitet

parent 23de87a0
......@@ -32,6 +32,3 @@ def sendMail(subject, to = '', body = '', filepath=
text = msg.as_string()
server.sendmail(fromaddr, to, text)
\ No newline at end of file
sendMail('logs/sorted_set_facedetector.log', body='TESTX')
\ No newline at end of file
......@@ -7,41 +7,42 @@ import sys
import os
from email_service import sendMail
from face_detect import locate_faces
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
Argument Parser erlaubt Parameter für die Verarbeitung anzugeben.
parser = argparse.ArgumentParser(description='Sorted Set Face Creator Application')
parser.add_argument('-s', action='store', dest='img_source', default='resources/img_data/sorted_set/',
help='Pfad zu den Bilddateien')
parser.add_argument('-b', action='store', dest='dataset', default='resources/img_data/dataset/', help='Pfad zum Dataset')
parser.add_argument('-e', action='append', dest='emotions', default=['happy', 'neutral', 'surprised'],
help='Emotionen die verarbeitet werden sollen')
parser.add_argument('-r', action='store', dest='resize', default=150, type=int, help='Resize Factor')
parser.add_argument('-f', action='store', dest='scaleFactor', default=1.1, type=float,
help='Skalierungsfaktor für Haarcascade')
parser.add_argument('-n', action='store', dest='minNeighbors', default=6, type=int, help='MinNeighbors für Haarcascade')
parser.add_argument('-m', action='store', dest='minSize', default=40, type=int, help='MinSize für Haarcascade')
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('--r', action='store', dest='resize', default=150, type=int, help='resize factor')
parser.add_argument('-e', action='append', dest='emotions', default=['happy', 'neutral', 'surprised'], 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')
parser.add_argument('-s', action='store', dest='minSize', default=40, type=int, help='min size - haar')
parser.add_argument('-x', action='store_true', help='activate email notifications')
arguments = parser.parse_args()
datasetPath = arguments.dataset
if len(glob.glob(datasetPath + '*')) > 0:
deleteDataset = input(
'Im Dataset befinden sich Dateien. Durch diesen Prozess 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): ')
if deleteDataset == 'y':
for file in glob.glob(datasetPath + '*'):
else:'Execution canceled from user')
totalFiles: int = 0
......@@ -60,7 +61,7 @@ def detect_faces(emotion):
global totalFaces
global totalFiles
logging.debug("found {} {} files".format(len(files), emotion))"Found {} {} files".format(len(files), emotion))
fileNumber = 0
for f in files:
......@@ -70,7 +71,11 @@ def detect_faces(emotion):
facefeatures = locate_faces(gray, arguments.scaleFactor, arguments.minNeighbors, (arguments.minSize, arguments.minSize))
if facefeatures is '':'No face detected ' + f)
if len(undetected) == 150 and arguments.x:
sendMail('Already 150 not detected faces', filepath='logs/sorted_set_facedetector.log')
# Cut and save face
for (x, y, w, h) in facefeatures: # get coordinates and size of rectangle containing face
......@@ -80,16 +85,20 @@ def detect_faces(emotion):
out = cv2.resize(gray, (arguments.resize, arguments.resize)) # Resize face so all images have same size
success = cv2.imwrite(datasetPath + '{}/{}.jpg'.format(emotion, fileNumber), out) # Write image
if not success:
logging.error('A problem while writing file occurred')
logging.error('Problem while writing file occurred...')
if arguments.x:
sendMail('Problem while writing file', body=f + ' to ' + datasetPath + '{}/{}.jpg'.format(emotion, fileNumber))
logging.error('Some error with ' + f)
if arguments.x:
sendMail('Problem while writing file', body=f)
pass # If error, pass file
totalFiles += 1 # Increment image number
fileNumber += 1
if arguments.x:
sendMail('Facedetector started notification')
for emotion in arguments.emotions:
......@@ -98,8 +107,11 @@ for emotion in arguments.emotions:
detect_faces(emotion) # Call functional
logging.debug('{} faces in {} files found'.format(totalFaces, totalFiles))
logging.debug('in {} files no face could be detected'.format(totalFiles - totalFaces))'{} faces in {} files found'.format(totalFaces, totalFiles))'In {} files no face could be detected'.format(totalFiles - totalFaces))
for f in undetected:
if arguments.x:
sendMail('Facedetector finished notification', filepath='logs/sorted_set_facedetector.log')
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