Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
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
c2e98706
Commit
c2e98706
authored
Jan 13, 2018
by
tihmels
Browse files
Sorted_Set Facedetector für Cluster Einsatz vorbereitet
parent
23de87a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
projectmood/email_service.py
View file @
c2e98706
...
...
@@ -31,7 +31,4 @@ def sendMail(subject, to = 'tjado.ihmels@uni-oldenburg.de', body = '', filepath=
server
.
login
(
fromaddr
,
"kR2-zgY-BTf-gRT"
)
text
=
msg
.
as_string
()
server
.
sendmail
(
fromaddr
,
to
,
text
)
server
.
quit
()
sendMail
(
'logs/sorted_set_facedetector.log'
,
body
=
'TESTX'
)
\ No newline at end of file
server
.
quit
()
\ No newline at end of file
projectmood/sorted_set_facedetector.py
View file @
c2e98706
...
...
@@ -7,41 +7,42 @@ import sys
import
os
from
email_service
import
sendMail
from
face_detect
import
locate_faces
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
'%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
,
datefmt
=
'%m-%d %H:%M'
,
filename
=
'logs/sorted_set_facedetector.log'
,
filemode
=
'w'
)
"""
Argument Parser erlaubt Parameter für die Verarbeitung anzugeben.
"""
parser
=
argparse
.
ArgumentParser
(
description
=
'Sorted Set Face Creator Application'
)
parser
.
add_argument
(
'-
s
'
,
action
=
'store'
,
dest
=
'img_source'
,
default
=
'resources/img_data/sorted_set/'
,
help
=
'
Pfad zu den Bilddateien
'
)
parser
.
add_argument
(
'-
b
'
,
action
=
'store'
,
dest
=
'dataset'
,
default
=
'resources/img_data/dataset/'
,
help
=
'
Pfad zum D
ataset'
)
parser
.
add_argument
(
'-
e
'
,
action
=
'
append
'
,
dest
=
'
emotions
'
,
default
=
[
'happy'
,
'neutral'
,
'surprised'
],
help
=
'
E
motion
en die verarbeitet werden sollen
'
)
parser
.
add_argument
(
'-
r
'
,
action
=
'store'
,
dest
=
'
resize
'
,
default
=
1
50
,
type
=
int
,
help
=
'Resize Factor'
)
parser
.
add_argument
(
'-f'
,
action
=
'store'
,
dest
=
'scale
F
actor
'
,
default
=
1.1
,
type
=
float
,
help
=
'Skalierungsfaktor für Haarcascade
'
)
parser
.
add_argument
(
'-
n
'
,
action
=
'store'
,
dest
=
'min
Neighbors
'
,
default
=
6
,
type
=
int
,
help
=
'
M
in
Neighbors für Haarcascade
'
)
parser
.
add_argument
(
'-
m
'
,
action
=
'store
'
,
dest
=
'minSize'
,
default
=
40
,
type
=
int
,
help
=
'MinSize für Haarcascade
'
)
parser
.
add_argument
(
'-
-source
'
,
action
=
'store'
,
dest
=
'img_source'
,
default
=
'resources/img_data/sorted_set/'
,
help
=
'
path to image source
'
)
parser
.
add_argument
(
'-
-dataset
'
,
action
=
'store'
,
dest
=
'dataset'
,
default
=
'resources/img_data/dataset/'
,
help
=
'
path to d
ataset'
)
parser
.
add_argument
(
'-
-r
'
,
action
=
'
store
'
,
dest
=
'
resize
'
,
default
=
150
,
type
=
int
,
help
=
'resize factor'
)
parser
.
add_argument
(
'-e'
,
action
=
'append'
,
dest
=
'
e
motion
s'
,
default
=
[
'happy'
,
'neutral'
,
'surprised'
],
help
=
'declare emotions that should be processed
'
)
parser
.
add_argument
(
'-
c
'
,
action
=
'store'
,
dest
=
'
scaleFactor
'
,
default
=
1
.1
,
type
=
float
,
help
=
'scale
f
actor
- haar'
)
parser
.
add_argument
(
'-n'
,
action
=
'store'
,
dest
=
'minNeighbors'
,
default
=
6
,
type
=
int
,
help
=
'min neighbors - haar
'
)
parser
.
add_argument
(
'-
s
'
,
action
=
'store'
,
dest
=
'min
Size
'
,
default
=
40
,
type
=
int
,
help
=
'
m
in
size - haar
'
)
parser
.
add_argument
(
'-
x
'
,
action
=
'store
_true'
,
help
=
'activate email notifications
'
)
arguments
=
parser
.
parse_args
()
logging
.
debug
(
arguments
)
logging
.
DEBUG
(
arguments
)
datasetPath
=
arguments
.
dataset
if
len
(
glob
.
glob
(
datasetPath
+
'*'
))
>
0
:
deleteDataset
=
input
(
'Im Dataset befinden sich Dateien. Durch diesen
Prozess
werden die existierenden Daten gelöscht. Fortfahren (y/n): '
)
'Im Dataset befinden sich Dateien. Durch diesen
Vorgang
werden die existierenden Daten gelöscht. Fortfahren (y/n): '
)
if
deleteDataset
==
'y'
:
for
file
in
glob
.
glob
(
datasetPath
+
'*'
):
shutil
.
rmtree
(
file
)
else
:
logging
.
info
(
'Execution canceled from user'
)
sys
.
exit
()
totalFiles
:
int
=
0
...
...
@@ -60,7 +61,7 @@ def detect_faces(emotion):
global
totalFaces
global
totalFiles
logging
.
debug
(
"
f
ound {} {} files"
.
format
(
len
(
files
),
emotion
))
logging
.
info
(
"
F
ound {} {} files"
.
format
(
len
(
files
),
emotion
))
fileNumber
=
0
for
f
in
files
:
...
...
@@ -70,7 +71,11 @@ def detect_faces(emotion):
facefeatures
=
locate_faces
(
gray
,
arguments
.
scaleFactor
,
arguments
.
minNeighbors
,
(
arguments
.
minSize
,
arguments
.
minSize
))
if
facefeatures
is
''
:
logging
.
info
(
'No face detected '
+
f
)
undetected
.
append
(
f
)
if
len
(
undetected
)
==
150
and
arguments
.
x
:
sendMail
(
'Already 150 not detected faces'
,
filepath
=
'logs/sorted_set_facedetector.log'
)
else
:
# Cut and save face
for
(
x
,
y
,
w
,
h
)
in
facefeatures
:
# get coordinates and size of rectangle containing face
...
...
@@ -80,16 +85,20 @@ def detect_faces(emotion):
out
=
cv2
.
resize
(
gray
,
(
arguments
.
resize
,
arguments
.
resize
))
# Resize face so all images have same size
success
=
cv2
.
imwrite
(
datasetPath
+
'{}/{}.jpg'
.
format
(
emotion
,
fileNumber
),
out
)
# Write image
if
not
success
:
logging
.
error
(
'A problem while writing file occurred'
)
sys
.
exit
()
logging
.
error
(
'Problem while writing file occurred...'
)
if
arguments
.
x
:
sendMail
(
'Problem while writing file'
,
body
=
f
+
' to '
+
datasetPath
+
'{}/{}.jpg'
.
format
(
emotion
,
fileNumber
))
except
:
logging
.
error
(
'Some error with '
+
f
)
if
arguments
.
x
:
sendMail
(
'Problem while writing file'
,
body
=
f
)
pass
# If error, pass file
totalFiles
+=
1
# Increment image number
fileNumber
+=
1
logging
.
debug
(
"
\n
"
)
if
arguments
.
x
:
sendMail
(
'Facedetector started notification'
)
for
emotion
in
arguments
.
emotions
:
...
...
@@ -98,8 +107,11 @@ for emotion in arguments.emotions:
detect_faces
(
emotion
)
# Call functional
logging
.
debug
(
'{} faces in {} files found'
.
format
(
totalFaces
,
totalFiles
))
logging
.
debug
(
'
i
n {} files no face could be detected'
.
format
(
totalFiles
-
totalFaces
))
logging
.
info
(
'{} faces in {} files found'
.
format
(
totalFaces
,
totalFiles
))
logging
.
info
(
'
I
n {} files no face could be detected'
.
format
(
totalFiles
-
totalFaces
))
for
f
in
undetected
:
logging
.
debug
(
f
)
logging
.
info
(
f
)
if
arguments
.
x
:
sendMail
(
'Facedetector finished notification'
,
filepath
=
'logs/sorted_set_facedetector.log'
)
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