Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Frank Tjado Ihmels
medienverarbeitung17.projectmood
Commits
95e70429
Commit
95e70429
authored
Jan 30, 2018
by
tihmels
Browse files
Änderungen
parent
fb7416b7
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
95e70429
...
...
@@ -98,6 +98,9 @@ instance/
# Sphinx documentation
docs/_build/
resources/csv
resources/img_data/models/
# PyBuilder
target/
...
...
projectmood/process_model.py
View file @
95e70429
...
...
@@ -29,9 +29,9 @@ 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
(
'-i'
'--iterations'
,
action
=
'store'
,
dest
=
'iterations'
,
type
=
int
,
default
=
30
,
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'
)
parser
.
add_argument
(
'-p'
,
'--properties'
,
nargs
=
'
*
'
,
dest
=
'properties'
,
help
=
'pre-processing steps for logging'
)
parser
.
add_argument
(
'-t'
,
'--test'
,
action
=
'store_true'
,
dest
=
'test'
,
help
=
'prevent writing new model to classifier'
)
parser
.
add_argument
(
'-c'
,
'--csv'
,
action
=
'store_true'
,
dest
=
'csv'
,
help
=
'activate csv output'
)
parser
.
add_argument
(
'-x'
,
'--email'
,
action
=
'store_true'
,
dest
=
'email'
,
help
=
'activate email notifications'
)
...
...
@@ -44,9 +44,6 @@ if not arguments.emotions:
logging
.
info
(
'Fisherface training started'
)
if
arguments
.
email
:
sendMail
(
'Fisherface training started'
)
def
_get_faces_from_emotion
(
emotion
):
"""
Get all the files to an emotion from the dataset, mix them, and split them into a training and test set.
...
...
@@ -70,9 +67,9 @@ 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
))
norm
=
clahe
.
apply
(
gray
)
return
norm
clahe
=
cv2
.
createCLAHE
(
clipLimit
=
2.0
,
tileGridSize
=
(
8
,
8
))
face
=
clahe
.
apply
(
gray
)
return
face
def
make_sets
():
...
...
@@ -128,9 +125,6 @@ for i in range(1, arguments.iterations + 1):
logging
.
info
(
"{} : {}%"
.
format
(
i
,
int
(
correct
)))
metascore
.
append
(
correct
)
if
arguments
.
email
and
i
%
(
int
(
arguments
.
iterations
/
4
))
==
0
:
sendMail
(
str
(
i
)
+
' iterations done'
,
body
=
'up-to-date average: {}%'
.
format
(
np
.
mean
(
metascore
)))
if
arguments
.
csv
:
file
=
open
(
"resources/csv/{}.csv"
.
format
(
'_'
.
join
(
arguments
.
properties
).
lower
()),
"w"
)
for
entry
in
metascore
:
...
...
@@ -142,7 +136,6 @@ logging.info("Fisherface training finished - {}% average\n".format(np.mean(metas
if
not
arguments
.
test
:
fishface
.
write
(
'resources/models/detection_model.xml'
)
logging
.
info
(
'saved trained classifier'
)
if
arguments
.
email
:
sendMail
(
'Fisherface training finished'
,
filepath
=
'resources/models/detection_model.xml'
)
sendMail
(
'Fisherface training finished'
,
body
=
str
(
arguments
),
filepath
=
'resources/models/detection_model.xml'
)
projectmood/resources/models/detection_model.xml
0 → 100644
View file @
95e70429
This diff is collapsed.
Click to expand it.
projectmood/webcam.py
View file @
95e70429
...
...
@@ -11,9 +11,17 @@ from face_detect import extract_faces
from
image_commons
import
nparray_as_image
,
draw_with_alpha
,
draw_img
parser
=
argparse
.
ArgumentParser
(
description
=
'ProjectMood Emotion Detection'
)
parser
.
add_argument
(
'-0'
,
action
=
'append_const'
,
dest
=
'emotions'
,
const
=
'neutral'
,
help
=
'neutral'
)
parser
.
add_argument
(
'-1'
,
action
=
'append_const'
,
dest
=
'emotions'
,
const
=
'happy'
,
help
=
'happy'
)
parser
.
add_argument
(
'-2'
,
action
=
'append_const'
,
dest
=
'emotions'
,
const
=
'sadness'
,
help
=
'sadness'
)
parser
.
add_argument
(
'-3'
,
action
=
'append_const'
,
dest
=
'emotions'
,
const
=
'surprise'
,
help
=
'surprise'
)
parser
.
add_argument
(
'-4'
,
action
=
'append_const'
,
dest
=
'emotions'
,
const
=
'fear'
,
help
=
'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'
,
help
=
'path to model'
)
parser
.
add_argument
(
'-r'
,
'--resize'
,
action
=
'store'
,
type
=
int
,
dest
=
'resizefactor'
)
arguments
=
parser
.
parse_args
()
...
...
@@ -26,7 +34,6 @@ 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.
...
...
@@ -42,9 +49,12 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name=pa
vc
=
WebcamVideoStream
().
start
()
# a random image from the dataset to determine the image format (important for Fisherface)
random
=
cv2
.
imread
(
'resources/img_data/dataset/{}/0.jpg'
.
format
(
emotions
[
0
]))
resizefactor
=
np
.
size
(
random
,
0
)
if
not
arguments
.
resizefactor
:
# a random image from the dataset to determine the image format (important for Fisherface)
random
=
cv2
.
imread
(
'resources/img_data/dataset/{}/0.jpg'
.
format
(
arguments
.
emotions
[
0
]))
resizefactor
=
np
.
size
(
random
,
0
)
else
:
resizefactor
=
arguments
.
resizefactor
# The RingBuffer stores the last x Predictions
buffer
=
RingBuffer
(
arguments
.
buffer
)
...
...
@@ -61,6 +71,8 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name=pa
# Get the entries as an array
predictions
=
buffer
.
get
()
print
(
predictions
)
# Read the processed input image
processed_image
=
nparray_as_image
(
normalized_face
[:,
:],
mode
=
'L'
)
w
,
h
=
vc
.
size
()
...
...
@@ -89,10 +101,7 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name=pa
if
__name__
==
'__main__'
:
# The emotions in the Dataset folder should also be loaded in the application
_
,
emotions
,
_
=
next
(
os
.
walk
(
'resources/img_data/dataset'
),
(
None
,
[],
None
))
emoticons
=
_load_emoticons
(
emotions
)
emoticons
=
_load_emoticons
(
arguments
.
emotions
)
fisher_face
=
cv2
.
face
.
FisherFaceRecognizer_create
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment