Skip to content
GitLab
Menu
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
36ac2db8
Commit
36ac2db8
authored
Dec 19, 2017
by
Arne Gerdes
Browse files
Kommentare hinzugefügt
parent
7ab441c1
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
projectmood/resources/experiments/bild1.jpg
deleted
100644 → 0
View file @
7ab441c1
192 KB
projectmood/resources/experiments/bild2.jpg
deleted
100644 → 0
View file @
7ab441c1
162 KB
projectmood/resources/experiments/trump.jpg
deleted
100644 → 0
View file @
7ab441c1
316 KB
projectmood/resources/haarcascade_eye.xml
deleted
100644 → 0
View file @
7ab441c1
This diff is collapsed.
Click to expand it.
projectmood/resources/haarcascade_frontalface_alt.xml
deleted
100644 → 0
View file @
7ab441c1
This diff is collapsed.
Click to expand it.
projectmood/resources/haarcascade_frontalface_alt2.xml
deleted
100644 → 0
View file @
7ab441c1
This diff is collapsed.
Click to expand it.
projectmood/resources/haarcascade_frontalface_alt_tree.xml
deleted
100644 → 0
View file @
7ab441c1
This diff is collapsed.
Click to expand it.
projectmood/resources/haarcascade_frontalface_default.xml
deleted
100644 → 0
View file @
7ab441c1
This diff is collapsed.
Click to expand it.
projectmood/resources/shape_predictor_68_face_landmarks.dat
deleted
100644 → 0
View file @
7ab441c1
File deleted
projectmood/webcam.py
View file @
36ac2db8
"""
"""
Thi
s
m
odul
e
is
the m
ain
m
odul
e in this package. It loads emotion recognition model from a f
il
e
,
Diese
s
M
odul is
t das M
ain
-M
odul
. Es lädt das Modell aus models, zeigt ein Webcam-B
il
d
,
shows a webcam image, recognizes face and it's emotion and draw e
motion
o
n
the image
.
erkennt das Gesicht und seine Emotionen und zeichnet ein E
moti
c
on
i
n
das Bild
.
"""
"""
import
cv2
import
cv2
...
@@ -14,21 +14,21 @@ import numpy as np
...
@@ -14,21 +14,21 @@ import numpy as np
def
_load_emoticons
(
emotions
):
def
_load_emoticons
(
emotions
):
"""
"""
Loads e
motions
images fro
m graphics
fold
er.
Lädt die E
moti
c
ons
aus de
m graphics
Ordn
er.
:param emotions: Array
of e
motion
s names
.
:param
emotions: Array
von E
motion
en
.
:return: Array
of e
motions
g
ra
phics
.
:return: Array
von E
motions
G
ra
fiken
.
"""
"""
return
[
nparray_as_image
(
cv2
.
imread
(
'resources/graphics/%s.png'
%
emotion
,
-
1
),
mode
=
None
)
for
emotion
in
emotions
]
return
[
nparray_as_image
(
cv2
.
imread
(
'resources/graphics/%s.png'
%
emotion
,
-
1
),
mode
=
None
)
for
emotion
in
emotions
]
def
show_webcam_and_run
(
model
,
emoticons
,
window_size
=
(
600
,
600
),
window_name
=
'Mood Expression'
,
update_time
=
1
):
def
show_webcam_and_run
(
model
,
emoticons
,
window_size
=
(
600
,
600
),
window_name
=
'Mood Expression'
,
update_time
=
1
):
"""
"""
Shows webcam image, detects faces and its e
motion
s
in
real time and draw emoticons over those faces
.
Zeigt ein Webcam-Bild, erkennt Gesichter und E
motion
en
in
Echtzeit und zeichnet Emoticons neben die Gesichter
.
:param model:
Learnt emotion detection m
odel
.
:param model:
Trainiertes M
odel
:param emoticons: List
of e
motions
images
.
:param emoticons: List
e von E
moti
c
ons.
:param window_size:
Size of webcam image window
.
:param window_size:
Grösse des Webcam-Fensters
.
:param window_name: Name
of webcam image window
.
:param window_name: Name
des Webcam-Fensters
.
:param update_time:
Image update time interval
.
:param update_time:
Bildaktualisierungzeit
.
"""
"""
cv2
.
namedWindow
(
window_name
,
cv2
.
WINDOW_NORMAL
)
cv2
.
namedWindow
(
window_name
,
cv2
.
WINDOW_NORMAL
)
if
window_size
:
if
window_size
:
...
@@ -37,19 +37,39 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name='M
...
@@ -37,19 +37,39 @@ def show_webcam_and_run(model, emoticons, window_size=(600, 600), window_name='M
vc
=
WebcamVideoStream
().
start
()
vc
=
WebcamVideoStream
().
start
()
frame
=
vc
.
read
()
frame
=
vc
.
read
()
"""
puffer
=
RingBuffer
(
7
)
# Der RingBuffer speichert die letzten Predictions
Der RingBuffer speichert die letzten 7 Predictions
"""
puffer
=
RingBuffer
(
7
)
while
True
:
while
True
:
for
normalized_face
,
(
x
,
y
,
w
,
h
)
in
find_faces
(
frame
):
for
normalized_face
,
(
x
,
y
,
w
,
h
)
in
find_faces
(
frame
):
prediction
=
model
.
predict
(
normalized_face
)
# do prediction
puffer
.
append
(
prediction
[
0
])
# Speichere letzte Prediction
prediction
=
model
.
predict
(
normalized_face
)
# do prediction
preds
=
puffer
.
get
()
# Hole Einträge als Array
if
not
(
any
(
x
is
None
for
x
in
preds
)):
# Kein Eintrag im RingBuffer ist None
"""
unique
,
counts
=
np
.
unique
(
preds
,
return_counts
=
True
)
# Vorkommen der Predictions zählen
Seichert die Predictions
image_to_draw
=
emoticons
[
unique
[
0
]]
# häufigster Wert wird dargestellt
"""
puffer
.
append
(
prediction
[
0
])
"""
Holt die Einträge als Array
"""
preds
=
puffer
.
get
()
"""
Kein Eintrag im RingBuffer ist None
"""
if
not
(
any
(
x
is
None
for
x
in
preds
)):
"""
Vorkommen der Predictions zählen
"""
unique
,
counts
=
np
.
unique
(
preds
,
return_counts
=
True
)
"""
Häufigster Wert wird dargestellt
"""
image_to_draw
=
emoticons
[
unique
[
0
]]
draw_with_alpha
(
frame
,
image_to_draw
,
(
40
,
40
,
200
,
200
))
draw_with_alpha
(
frame
,
image_to_draw
,
(
40
,
40
,
200
,
200
))
cv2
.
imshow
(
window_name
,
frame
)
cv2
.
imshow
(
window_name
,
frame
)
...
@@ -67,8 +87,9 @@ if __name__ == '__main__':
...
@@ -67,8 +87,9 @@ if __name__ == '__main__':
emotions
=
[
'happy'
,
'neutral'
,
'surprise'
]
emotions
=
[
'happy'
,
'neutral'
,
'surprise'
]
emoticons
=
_load_emoticons
(
emotions
)
emoticons
=
_load_emoticons
(
emotions
)
# load mode
fisher_face
=
cv2
.
face
.
FisherFaceRecognizer_create
()
fisher_face
=
cv2
.
face
.
FisherFaceRecognizer_create
()
"""Läadt das trainierte Model"""
fisher_face
.
read
(
'basis_data/models/detection_model.xml'
)
fisher_face
.
read
(
'basis_data/models/detection_model.xml'
)
# use learnt model
show_webcam_and_run
(
fisher_face
,
emoticons
)
show_webcam_and_run
(
fisher_face
,
emoticons
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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