Commit c2e98706 authored by tihmels's avatar tihmels

Sorted_Set Facedetector für Cluster Einsatz vorbereitet

parent 23de87a0
......@@ -31,7 +31,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()
sendMail('logs/sorted_set_facedetector.log', body='TESTX')
\ No newline at end of file
server.quit()
\ 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',
filename='logs/sorted_set_facedetector.log',
filemode='w')
"""
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()
logging.debug(arguments)
logging.DEBUG(arguments)
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 + '*'):
shutil.rmtree(file)
else:
logging.info('Execution canceled from user')
sys.exit()
totalFiles: int = 0
......@@ -60,7 +61,7 @@ def detect_faces(emotion):
global totalFaces
global totalFiles
logging.debug("found {} {} files".format(len(files), emotion))
logging.info("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 '':
logging.info('No face detected ' + f)
undetected.append(f)
if len(undetected) == 150 and arguments.x:
sendMail('Already 150 not detected faces', filepath='logs/sorted_set_facedetector.log')
else:
# 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')
sys.exit()
logging.error('Problem while writing file occurred...')
if arguments.x:
sendMail('Problem while writing file', body=f + ' to ' + datasetPath + '{}/{}.jpg'.format(emotion, fileNumber))
except:
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
logging.debug("\n")
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))
logging.info('{} faces in {} files found'.format(totalFaces, totalFiles))
logging.info('In {} files no face could be detected'.format(totalFiles - totalFaces))
for f in undetected:
logging.debug(f)
logging.info(f)
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