Commit 53c5fa46 authored by tihmels's avatar tihmels

Änderungen

parent f6c4094e
...@@ -54,8 +54,8 @@ def _get_faces_from_emotion(emotion): ...@@ -54,8 +54,8 @@ def _get_faces_from_emotion(emotion):
random.shuffle(files) random.shuffle(files)
# Mix the dataset in training and comparison images in the ratio 80 to 20 # Mix the dataset in training and comparison images in the ratio 80 to 20
training = files[:int(len(files) * 0.8)] training = files[:int(len(files) * 1)]
prediction = files[-int(len(files) * 0.2):] prediction = files[-int(len(files) * 0):]
return training, prediction return training, prediction
......
...@@ -33,9 +33,10 @@ parser.add_argument('-d', '--dataset', action='store', dest='dataset', default=' ...@@ -33,9 +33,10 @@ parser.add_argument('-d', '--dataset', action='store', dest='dataset', default='
help='path to dataset') help='path to dataset')
parser.add_argument('-r', '--resize', action='store', dest='resize', default=250, type=int, help='resize factor') parser.add_argument('-r', '--resize', action='store', dest='resize', default=250, type=int, help='resize factor')
parser.add_argument('-c', '--scale', action='store', dest='scaleFactor', default=1.1, type=float, parser.add_argument('-c', '--scale', action='store', dest='scaleFactor', default=1.1, type=float,
help='scale factor (haar)') help='scale factor (ViolaJ)')
parser.add_argument('-n', '--minneighbors', action='store', dest='minNeighbors', default=6, type=int, help='min neighbors (haar)') parser.add_argument('-n', '--minneighbors', action='store', dest='minNeighbors', default=6, type=int, help='min neighbors (ViolaJ)')
parser.add_argument('-m', '--minsize', action='store', dest='minSize', default=50, type=int, help='min size (haar)') parser.add_argument('-m', '--minsize', action='store', dest='minSize', default=50, type=int, help='min size (ViolaJ)')
parser.add_argument('-p', '--prefix', action='store', dest='prefix', default='', help='prefix for files')
parser.add_argument('-x', '--email', action='store_true', help='activate email notifications') parser.add_argument('-x', '--email', action='store_true', help='activate email notifications')
arguments = parser.parse_args() arguments = parser.parse_args()
logging.debug(arguments) logging.debug(arguments)
...@@ -81,7 +82,7 @@ def detect_faces(emotion): ...@@ -81,7 +82,7 @@ def detect_faces(emotion):
logging.info("Found {} {} files".format(len(files), emotion)) logging.info("Found {} {} files".format(len(files), emotion))
fileNumber = 0 file_name_number = 0
for f in files: for f in files:
frame = cv2.imread(f) # Open image frame = cv2.imread(f) # Open image
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Convert image to grayscale gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Convert image to grayscale
...@@ -92,32 +93,29 @@ def detect_faces(emotion): ...@@ -92,32 +93,29 @@ def detect_faces(emotion):
logging.info('No face detected in ' + 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)) + ' undetected faces', filepath=logfile)
else: else:
# Cut and save face # Cut and save face
for (x, y, w, h) in facefeatures: # get coordinates and size of rectangle containing face for (x, y, w, h) in facefeatures: # get coordinates and size of rectangle containing face
totalFaces += 1 totalFaces += 1
gray = gray[y:y + h, x:x + w] # Cut the frame to size gray = gray[y:y + h, x:x + w] # Cut the frame to size
try: try:
save_file = dataset_path + '{}/{}{}.jpg'.format(emotion, arguments.prefix, file_name_number)
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(save_file, out) # Write image
if not success: if not success:
logging.error('Problem while writing file ' + f + ' occurred...') logging.error('Problem while writing file ' + str(f) + ' occurred...')
if email: if email:
sendMail('Problem while writing file', sendMail('Problem while writing file',
body=f + ' to ' + dataset_path + '{}/{}.jpg'.format(emotion, fileNumber)) body=str(f) + ' to ' + save_file)
except: except:
logging.error('Some error with ' + f) logging.error('Some error with ' + f)
if email: if email:
sendMail('Problem while writing file', body=f) sendMail('Some error occured', body=f, filepath=logfile)
pass # If error, pass file pass # If error, pass file
totalFiles += 1 # Increment image number totalFiles += 1 # Increment image number
fileNumber += 1 file_name_number += 1
if email:
sendMail('Facedetector started notification')
for emotion in emotions: for emotion in emotions:
......
...@@ -71,8 +71,6 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name=pa ...@@ -71,8 +71,6 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name=pa
# Get the entries as an array # Get the entries as an array
predictions = buffer.get() predictions = buffer.get()
print(predictions)
# Read the processed input image # Read the processed input image
processed_image = nparray_as_image(normalized_face[:, :], mode='L') processed_image = nparray_as_image(normalized_face[:, :], mode='L')
w, h = vc.size() w, h = vc.size()
......
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