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
dd124872
Commit
dd124872
authored
Nov 04, 2017
by
Arne Gerdes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Haarcascade und Landmarks zu Main eingefügt
parent
1c3a028e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
projectmood/main.py
projectmood/main.py
+26
-1
No files found.
projectmood/main.py
View file @
dd124872
import
cv2
import
sys
import
cvhelper
import
dlib
from
projectmood
import
cvhelper
def
main
():
# Set up some required objects
detector
=
dlib
.
get_frontal_face_detector
()
# Face detector
detectors
=
cv2
.
CascadeClassifier
(
'haarcascade_frontalface_default.xml'
)
predictor
=
dlib
.
shape_predictor
(
"shape_predictor_68_face_landmarks.dat"
)
# Landmark identifier. Set the filename to whatever you named the downloaded file
if
len
(
sys
.
argv
)
>
1
:
cap
=
cv2
.
VideoCapture
(
str
(
sys
.
argv
[
1
]))
...
...
@@ -16,6 +24,23 @@ def main():
# Our operations on the frame come here
gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
clahe
=
cv2
.
createCLAHE
(
clipLimit
=
2.0
,
tileGridSize
=
(
8
,
8
))
clahe_image
=
clahe
.
apply
(
gray
)
faces
=
detectors
.
detectMultiScale
(
gray
,
1.3
,
5
)
detections
=
detector
(
clahe_image
,
1
)
# Detect the faces in the image
for
k
,
d
in
enumerate
(
detections
):
# For each detected face
shape
=
predictor
(
clahe_image
,
d
)
# Get coordinates
for
i
in
range
(
1
,
68
):
# There are 68 landmark points on each face
cv2
.
circle
(
gray
,
(
shape
.
part
(
i
).
x
,
shape
.
part
(
i
).
y
),
1
,
(
0
,
0
,
255
),
thickness
=
2
)
# For each point, draw a red circle with thickness2 on the original frame
for
(
x
,
y
,
w
,
h
)
in
faces
:
cv2
.
rectangle
(
gray
,
(
x
,
y
),
(
x
+
w
,
y
+
h
),
(
255
,
0
,
0
),
2
)
roi_gray
=
gray
[
y
:
y
+
h
,
x
:
x
+
w
]
roi_color
=
frame
[
y
:
y
+
h
,
x
:
x
+
w
]
cvhelper
.
createwindow
(
'Grayscale'
,
gray
)
...
...
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