Commit bf1a7679 authored by tihmels's avatar tihmels

Projekt abgabebereit gemacht

parent 9f491647
# Created by https://www.gitignore.io/api/macos,python,windows
### macOS ###
......@@ -156,9 +155,15 @@ $RECYCLE.BIN/
*.msi
*.msm
*.msp
.idea/**
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/macos,python,windows
.idea/
projectmood/logs/
projectmood/resources/csv/
projectmood/resources/img_data/dataset/
projectmood/resources/img_data/sorted_set/
projectmood/resources/img_data/source_emotion/
projectmood/resources/img_data/source_images/
......@@ -34,3 +34,25 @@ Setup
5. Dependencies aus requirements.txt installieren::
pip3 install -r requirements.txt
***************
Model Injection
***************
Um das Hauptprogramm ``webcam.py`` auszuführen,
muss ein konkretes Model übergeben werden und die darin beschriebenen Emotionen als Parameter definiert sein.
Im Ordner ``projectmood/resources/models/`` befinden sich zwei verschiedene Models: ``five_emotions.xml`` sowie ``three_emotions.xml``
Die drei Emotionen behandeln *neutral*, *happy* und *sadness*.
Der Fünf-Klassen-Classifier außerdem noch *anger* und *sadness*.
Konsolenbefehl um die beiden Classifier zu injizieren und das Programm zu starten:
1. ``python3 webcam.py -013 -m resources/models/three_emotions.xml -r 250``
2. ``python3 webcam.py -01236 -m resources/models/five_emotions -r 250``
Für weitere Informationen ``python3 webcam.py -h``
\ No newline at end of file
......@@ -2,7 +2,6 @@ from threading import Thread
import cv2
class WebcamVideoStream:
def __init__(self, src=0):
......
# ***************************************************
# * Copyright (C) 2010-2011 Tjado Ihmels <tjado.ihmels@uni-oldenburg.de>
# *
# * This file is part of whiteboard-project-matcher.
# *
# * whiteboard-project-matcher can not be copied and/or distributed without the express
# * permission of Tjado Ihmels
# ***************************************************/
import argparse
import logging
import os
......@@ -29,7 +38,7 @@ logging.debug(arguments)
emotiondict = {0: 'neutral', 1: 'happy', 2: 'sadness', 3: 'surprise', 4: 'fear', 5: 'disgust', 6: 'anger', 7: 'contempt',
8: 'none', 9: 'uncertain', 10: 'noface'}
# count emotions
# count found emotions
emotioncounter = {}
for emotion in arguments.emotions:
emotioncounter[emotion] = 0
......
# ***************************************************
# * Copyright © 2010-2011 Tjado Ihmels <tjado.ihmels@uni-oldenburg.de>
# *
# * This file is part of whiteboard-project-matcher.
# *
# * whiteboard-project-matcher can not be copied and/or distributed without the express
# * permission of Tjado Ihmels
# *
# * Parts of this program are legally copied and adapted from
# * van Gent, P. (2016). Emotion Recognition With Python, OpenCV and a Face Dataset. A tech blog about fun things with Python and embedded electronics. Retrieved from:
# * http://www.paulvangent.com/2016/04/01/emotion-recognition-with-python-opencv-and-a-face-dataset/
# ***************************************************/
"""
This script maps the source_emotions to the source_images and creates a sorted set
"""
......
# ***************************************************
# * Copyright (C) 2010-2011 Tjado Ihmels <tjado.ihmels@uni-oldenburg.de>
# *
# * This file is part of whiteboard-project-matcher.
# *
# * whiteboard-project-matcher can not be copied and/or distributed without the express
# * permission of Tjado Ihmels
# ***************************************************/
import os
import smtplib
from email import encoders
......@@ -8,7 +19,7 @@ from email.mime.text import MIMEText
def sendMail(subject, to='tjado.ihmels@uni-oldenburg.de', body='', filepath=''):
"""
For a longer runtime on a remote server emails serve as feedback
For a longer runtime on a remote server, emails serve as feedback
:param subject: subject
:param to: email adress
:param body: email text
......
# ***************************************************
# * Copyright (C) 2010-2011 Tjado Ihmels <tjado.ihmels@uni-oldenburg.de>
# *
# * This file is part of whiteboard-project-matcher.
# *
# * whiteboard-project-matcher can not be copied and/or distributed without the express
# * permission of Tjado Ihmels
# *
# * Parts of this program are legally copied and adapted from
# * van Gent, P. (2016). Emotion Recognition With Python, OpenCV and a Face Dataset. A tech blog about fun things with Python and embedded electronics. Retrieved from:
# * http://www.paulvangent.com/2016/04/01/emotion-recognition-with-python-opencv-and-a-face-dataset/
# ***************************************************/
import cv2
# Haarcascades
......
"""
Utility Class for working with images in OpenCV
"""
# ***************************************************
# * Copyright (C) 2010-2011 Tjado Ihmels <tjado.ihmels@uni-oldenburg.de>
# *
# * This file is part of whiteboard-project-matcher.
# *
# * whiteboard-project-matcher can not be copied and/or distributed without the express
# * permission of Tjado Ihmels
# *
# * Parts of this program are legally copied and adapted from
# * van Gent, P. (2016). Emotion Recognition With Python, OpenCV and a Face Dataset. A tech blog about fun things with Python and embedded electronics. Retrieved from:
# * http://www.paulvangent.com/2016/04/01/emotion-recognition-with-python-opencv-and-a-face-dataset/
# ***************************************************/
import cv2
import numpy as np
from PIL import Image
# Utility Class for working with images in OpenCV
def image_as_nparray(image):
"""
......@@ -35,9 +45,9 @@ def load_image(source_path):
return cv2.cvtColor(source_image, cv2.COLOR_BGR2GRAY)
def draw_with_alpha(source_image, image_to_draw, coordinates):
def draw_alpha_3dim(source_image, image_to_draw, coordinates):
"""
Draw a partially transparent image on another image
Draws a partially transparent, three dimensional image on another image
:param source_image: Background image
:param image_to_draw: Overdraw image
:param coordinates: : Coordinates to which the image should be drawn
......@@ -48,9 +58,9 @@ def draw_with_alpha(source_image, image_to_draw, coordinates):
for c in range(0, 3):
source_image[y:y + h, x:x + w, c] = image_array[:, :, c] * (image_array[:, :, 3] / 255.0) + source_image[y:y + h, x:x + w, c] * (1.0 - image_array[:, :, 3] / 255.0)
def draw_img(source_image, image_to_draw, coordinates):
def draw_2dim(source_image, image_to_draw, coordinates):
"""
Draw an image to another image
Draws an two dimensional image to another image
:param source_image: Background image
:param image_to_draw: Overdraw image
:param coordinates: : Coordinates to which the image should be drawn
......
# This class makes the training of the model possible
# ***************************************************
# * Copyright © 2010-2011 Tjado Ihmels <tjado.ihmels@uni-oldenburg.de>
# *
# * This file is part of whiteboard-project-matcher.
# *
# * whiteboard-project-matcher can not be copied and/or distributed without the express
# * permission of Tjado Ihmels
# *
# * Parts of this program are legally copied and adapted from
# * van Gent, P. (2016). Emotion Recognition With Python, OpenCV and a Face Dataset. A tech blog about fun things with Python and embedded electronics. Retrieved from:
# * http://www.paulvangent.com/2016/04/01/emotion-recognition-with-python-opencv-and-a-face-dataset/
# ***************************************************/
import argparse
import glob
......@@ -10,6 +21,8 @@ import sys
from email_service import sendMail
# This program takes the pictures from the dataset and generates a trained model
logfile = 'logs/process_model.log'
# Creates and configures the logger
......@@ -28,6 +41,7 @@ parser.add_argument('-5', action='append_const', dest='emotions', const='disgust
parser.add_argument('-6', action='append_const', dest='emotions', const='anger', help='anger')
parser.add_argument('-d', '--dataset', action='store', dest='dataset', default='resources/img_data/dataset/',
help='path to dataset')
parser.add_argument('-r', '--ratio', action='store', dest='ratio', help='the relative size of the training set in float [0.1,1]', default=1, type=float)
parser.add_argument('-i' '--iterations', action='store', dest='iterations', type=int, default=1,
help='number of iterations')
parser.add_argument('-p', '--properties', nargs='*', dest='properties', help='pre-processing steps for logging')
......@@ -52,9 +66,9 @@ def _get_faces_from_emotion(emotion):
files = glob.glob(arguments.dataset + '{}/*'.format(emotion))
random.shuffle(files)
# Mix the dataset in training and comparison images in the ratio 80 to 20
training = files[:int(len(files) * 1)]
prediction = files[-int(len(files) * 0):]
# Mix the dataset in training and comparison images in the given ratio
training = files[:int(len(files) * arguments.ratio)]
prediction = files[-int(len(files) * (1 - arguments.ratio)):]
return training, prediction
......
This diff is collapsed.
# ***************************************************
# * Copyright © 2010-2011 Tjado Ihmels <tjado.ihmels@uni-oldenburg.de>
# *
# * This file is part of whiteboard-project-matcher.
# *
# * whiteboard-project-matcher can not be copied and/or distributed without the express
# * permission of Tjado Ihmels
# *
# * Parts of this program are legally copied and adapted from
# * van Gent, P. (2016). Emotion Recognition With Python, OpenCV and a Face Dataset. A tech blog about fun things with Python and embedded electronics. Retrieved from:
# * http://www.paulvangent.com/2016/04/01/emotion-recognition-with-python-opencv-and-a-face-dataset/
# ***************************************************/
import argparse
import glob
import logging
......
# ***************************************************
# * Copyright © 2010-2011 Tjado Ihmels <tjado.ihmels@uni-oldenburg.de>
# *
# * This file is part of whiteboard-project-matcher.
# *
# * whiteboard-project-matcher can not be copied and/or distributed without the express
# * permission of Tjado Ihmels
# *
# * Parts of this program are legally copied and adapted from
# * van Gent, P. (2016). Emotion Recognition With Python, OpenCV and a Face Dataset. A tech blog about fun things with Python and embedded electronics. Retrieved from:
# * http://www.paulvangent.com/2016/04/01/emotion-recognition-with-python-opencv-and-a-face-dataset/
# ***************************************************/
import argparse
import os
import cv2
import cv2.face
......@@ -19,7 +31,7 @@ parser.add_argument('-4', action='append_const', dest='emotions', const='fear',
parser.add_argument('-5', action='append_const', dest='emotions', const='disgust', help='disgust')
parser.add_argument('-6', action='append_const', dest='emotions', const='anger', help='anger')
parser.add_argument('-b', '--buffer', action='store', dest='buffer', default=12, type=int, help='size of ringbuffer')
parser.add_argument('-m', '--model', action='store', dest='model', default='resources/models/detection_model.xml',
parser.add_argument('-m', '--model', action='store', dest='model', default='resources/models/five_emotions.xml',
help='path to model')
parser.add_argument('-r', '--resize', action='store', type=int, dest='resizefactor')
arguments = parser.parse_args()
......@@ -34,9 +46,10 @@ def _load_emoticons(emotions):
return [nparray_as_image(cv2.imread('resources/emojis/{}.png'.format(emotion), -1), mode=None) for emotion in
emotions]
def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name=parser.description, update_time=1):
"""
Shows a webcam image, recognizes faces and emotions in real time and draws emoticons next to the faces.
Shows a webcam input, recognizes faces and emotions in real time and draws emoticons next to the faces.
: param model: Trained Model
: param emoticons: list of emoticons.
: param window_size: Size of the webcam window.
......@@ -75,7 +88,7 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name=pa
processed_image = nparray_as_image(normalized_face[:, :], mode='L')
w, h = vc.size()
# And print it to the frame
draw_img(frame, processed_image, (w-300, h-300, 250, 250))
draw_img(frame, processed_image, (w - 300, h - 300, 250, 250))
# No entry in the ring buffer is None
if not (any(x is None for x in predictions)):
......
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