Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
medienverarbeitung17.projectmood
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Frank Tjado Ihmels
medienverarbeitung17.projectmood
Commits
65c8bf7d
Commit
65c8bf7d
authored
Jan 30, 2018
by
Arne Gerdes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kommentare im face_detect und process_model fertig geschrieben
parent
fb7416b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
projectmood/face_detect.py
projectmood/face_detect.py
+27
-1
projectmood/process_model.py
projectmood/process_model.py
+12
-0
No files found.
projectmood/face_detect.py
View file @
65c8bf7d
import
cv2
# Haarcascades
faceDet_one
=
cv2
.
CascadeClassifier
(
'resources/haarcascade/haarcascade_frontalface_default.xml'
)
faceDet_two
=
cv2
.
CascadeClassifier
(
'resources/haarcascade/haarcascade_frontalface_alt2.xml'
)
faceDet_three
=
cv2
.
CascadeClassifier
(
'resources/haarcascade/haarcascade_frontalface_alt.xml'
)
...
...
@@ -8,18 +8,36 @@ faceDet_four = cv2.CascadeClassifier('resources/haarcascade/haarcascade_frontalf
def
extract_faces
(
image
,
resize
):
"""
Calls the method through which the face is to be found in the image and calls the
method on which the found face continues to be edited
:param image: Input
:param resize: Resize coordinates of the face
:return: The normalized face in the image
"""
faces
=
find_faces
(
image
)
normalized_faces
=
[
preprocess_face
(
face
,
resize
)
for
face
in
faces
]
return
normalized_faces
def
find_faces
(
image
):
"""
Calls the method to detect the face in the image and cuts it out
:param image: Input
:return: The cutted face
"""
faces_coordinates
=
locate_faces
(
image
)
cutted_faces
=
[
image
[
y
:
y
+
h
,
x
:
x
+
w
]
for
(
x
,
y
,
w
,
h
)
in
faces_coordinates
]
return
cutted_faces
def
preprocess_face
(
face
,
resize
):
"""
Edit the found face
:param face: Found face
:param resize: Resize coordinates of the face
:return: Edited face
"""
face
=
cv2
.
cvtColor
(
face
,
cv2
.
COLOR_BGR2GRAY
)
face
=
cv2
.
resize
(
face
,
(
resize
,
resize
))
clahe
=
cv2
.
createCLAHE
(
clipLimit
=
2.0
,
tileGridSize
=
(
8
,
8
))
...
...
@@ -28,6 +46,14 @@ def preprocess_face(face, resize):
def
locate_faces
(
image
,
scaleFactor
=
1.1
,
minNeighbors
=
6
,
minSize
=
(
350
,
350
)):
"""
Find the face in the image with Haarcascades
:param image: Input
:param scaleFactor: Parameter specifying how much the image size is reduced at each image scale
:param minNeighbors: Parameter specifying how many neighbors each candidate rectangle should have to retain it
:param minSize: Minimum possible object size. Objects smaller than that are ignored
:return: Found face
"""
face
=
faceDet_one
.
detectMultiScale
(
image
,
scaleFactor
,
minNeighbors
,
minSize
=
minSize
,
flags
=
cv2
.
CASCADE_SCALE_IMAGE
)
...
...
projectmood/process_model.py
View file @
65c8bf7d
...
...
@@ -76,6 +76,10 @@ def image_preprocessing(image):
def
make_sets
():
"""
Creates the training set
:return: The created training data
"""
training_data
=
[]
training_labels
=
[]
prediction_data
=
[]
...
...
@@ -99,6 +103,10 @@ def make_sets():
def
run_recognizer
():
"""
Performs the actual training with Fisherfaces and Logged the results
:return: The correctly recognized faces in percent
"""
training_data
,
training_labels
,
prediction_data
,
prediction_labels
=
make_sets
()
logging
.
debug
(
'Training...'
)
...
...
@@ -123,6 +131,7 @@ def run_recognizer():
fishface
=
cv2
.
face
.
FisherFaceRecognizer_create
()
metascore
=
[]
# Argument parser
for
i
in
range
(
1
,
arguments
.
iterations
+
1
):
correct
=
run_recognizer
()
logging
.
info
(
"{} : {}%"
.
format
(
i
,
int
(
correct
)))
...
...
@@ -131,6 +140,7 @@ for i in range(1, arguments.iterations + 1):
if
arguments
.
email
and
i
%
(
int
(
arguments
.
iterations
/
4
))
==
0
:
sendMail
(
str
(
i
)
+
' iterations done'
,
body
=
'up-to-date average: {}%'
.
format
(
np
.
mean
(
metascore
)))
# Argument parser
if
arguments
.
csv
:
file
=
open
(
"resources/csv/{}.csv"
.
format
(
'_'
.
join
(
arguments
.
properties
).
lower
()),
"w"
)
for
entry
in
metascore
:
...
...
@@ -140,9 +150,11 @@ if arguments.csv:
logging
.
info
(
"Fisherface training finished - {}% average
\n
"
.
format
(
np
.
mean
(
metascore
)))
# Argument parser
if
not
arguments
.
test
:
fishface
.
write
(
'resources/models/detection_model.xml'
)
logging
.
info
(
'saved trained classifier'
)
# Argument parser
if
arguments
.
email
:
sendMail
(
'Fisherface training finished'
,
filepath
=
'resources/models/detection_model.xml'
)
Write
Preview
Markdown
is supported
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