Toggle navigation
Toggle navigation
This project
Loading...
Sign in
조수연
/
Find_your_own_personal_color
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
starbucksdolcelatte
2019-04-05 14:29:49 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2ce4e5546bc18e150322f3cc21c9aa9f52dfd1e4
2ce4e554
1 parent
dae3acde
Create extracted_face_part() function
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
4 deletions
detect_face.py
detect_face.py
View file @
2ce4e55
...
...
@@ -23,6 +23,7 @@ class DetectFace:
# detect faces in the grayscale image
self
.
rects
=
self
.
detector
(
self
.
gray
,
1
)
# init face parts
self
.
mouth
=
[]
self
.
right_eyebrow
=
[]
self
.
left_eyebrow
=
[]
...
...
@@ -31,7 +32,7 @@ class DetectFace:
self
.
nose
=
[]
self
.
jaw
=
[]
# detect the face parts and s
ave the value
# detect the face parts and s
et the variables
self
.
detect_face_part
()
...
...
@@ -80,12 +81,36 @@ class DetectFace:
cv2
.
imshow
(
"Image"
,
output
)
cv2
.
waitKey
(
0
)
# set the variables
# Caution: this coordinates fits on the
resized
image.
# Caution: this coordinates fits on the
RESIZED
image.
self
.
mouth
=
face_parts
[
0
]
self
.
right_eyebrow
=
face_parts
[
1
]
self
.
left_eyebrow
=
face_parts
[
2
]
self
.
left_eyebrow
=
face_parts
[
2
]
self
.
right_eye
=
face_parts
[
3
]
self
.
left_eye
=
face_parts
[
4
]
self
.
left_eye
=
face_parts
[
4
]
self
.
nose
=
face_parts
[
5
]
self
.
jaw
=
face_parts
[
6
]
# parameter example : self.right_eye
def
extract_face_part
(
self
,
part
):
pts
=
part
# Create an mask
mask
=
np
.
zeros
((
self
.
img
.
shape
[
0
],
self
.
img
.
shape
[
1
]))
cv2
.
fillConvexPoly
(
mask
,
pts
,
1
)
mask
=
mask
.
astype
(
np
.
bool
)
# extract right eye by applying polygon mask
out
=
np
.
zeros_like
(
self
.
img
)
out
[
mask
]
=
self
.
img
[
mask
]
#cv2.imshow("Image2", out)
#cv2.waitKey(0)
# crop the image
(
x
,
y
,
w
,
h
)
=
cv2
.
boundingRect
(
pts
)
extracted_part
=
out
[
y
:
y
+
h
,
x
:
x
+
w
]
#cv2.imshow("Image2", extracted_part)
#cv2.waitKey(0)
return
extracted_part
...
...
Please
register
or
login
to post a comment