Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.pad.face
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.pad.face
Commits
9442e6e4
There was a problem fetching the pipeline summary.
Commit
9442e6e4
authored
7 years ago
by
Anjith GEORGE
Browse files
Options
Downloads
Patches
Plain Diff
Added facelandmark detection in utils!
parent
ed38bcbc
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!22
Facedet utils
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/pad/face/utils/face_detection_utils.py
+132
-0
132 additions, 0 deletions
bob/pad/face/utils/face_detection_utils.py
with
132 additions
and
0 deletions
bob/pad/face/utils/face_detection_utils.py
+
132
−
0
View file @
9442e6e4
...
...
@@ -8,6 +8,7 @@ This file contains face detection utils.
# Import here:
import
importlib
import
numpy
as
np
#==============================================================================
...
...
@@ -96,8 +97,139 @@ def detect_faces_in_video(frame_container, method = "dlib"):
annotations
[
str
(
idx
)]
=
frame_annotations
return
annotations
def
getEyePos
(
lm
):
"""
This function returns the locations of left and right eyes
**Parameters:**
``lm`` : :py:class:`array`
A numpy array containing the coordinates of facial landmarks, (68X2)
**Returns:**
``right_eye``
A tuple containing the location of right eye,
``left_eye``
A tuple containing the location of left eye
"""
# Mean position of eye corners as eye centers , casted to int()
left_eye_t
=
(
lm
[
36
,:]
+
lm
[
39
,:])
/
2.0
right_eye_t
=
(
lm
[
42
,:]
+
lm
[
45
,:])
/
2.0
right_eye
=
(
int
(
left_eye_t
[
1
]),
int
(
left_eye_t
[
0
]))
left_eye
=
(
int
(
right_eye_t
[
1
]),
int
(
right_eye_t
[
0
]))
return
right_eye
,
left_eye
def
detect_face_landmarks_in_image
(
image
,
method
=
"
dlib
"
):
"""
This function detects a face and facial landmarks in the input image.
**Parameters:**
``image`` : 3D :py:class:`numpy.ndarray`
A color image to detect the face in.
``method`` : :py:class:`str`
A package to be used for face detection. Options supported by this
package:
"
dlib
"
(dlib is a dependency of this package).
**Returns:**
``annotations`` : :py:class:`dict`
A dictionary containing the annotations for an image.
Dictionary must be as follows ``{
'
topleft
'
: (row, col),
'
bottomright
'
: (row, col),
'
left_eye
'
: (row, col),
'
right_eye
'
: (row, col),
'
landmarks
'
: [(row1,col1), (row2,col2), ...]}``
Where (rowK,colK) is the location of Kth facial landmark (K=0,...,67).
If no annotations found an empty dictionary is returned.
"""
try
:
face_landmark_detection_module
=
importlib
.
import_module
(
"
bob.ip.facelandmarks
"
);
except
ImportError
:
raise
ImportError
(
"
No module named bob.ip.facelandmarks
"
)
if
not
hasattr
(
face_landmark_detection_module
,
'
detect_landmarks
'
):
raise
AttributeError
(
"
bob.ip.facelandmarks module has no attribute detect_landmarks
"
)
key_points
=
face_landmark_detection_module
.
detect_landmarks
(
image
,
1
);
annotations
=
{}
try
:
kp
=
key_points
[
0
]
except
:
kp
=
None
if
kp
is
not
None
:
lm
=
np
.
vstack
((
kp
.
landmarks
[:,
1
],
kp
.
landmarks
[:,
0
])).
T
right_eye
,
left_eye
=
getEyePos
(
lm
)
points
=
[]
for
i
in
range
(
lm
.
shape
[
0
]):
points
.
append
((
int
(
lm
[
i
,
0
]),
int
(
lm
[
i
,
1
])))
annotations
[
'
topleft
'
]
=
kp
.
bounding_box
.
topleft
annotations
[
'
bottomright
'
]
=
kp
.
bounding_box
.
bottomright
annotations
[
'
landmarks
'
]
=
points
# list of landmarks
annotations
[
'
left_eye
'
]
=
left_eye
annotations
[
'
right_eye
'
]
=
right_eye
return
annotations
def
detect_face_landmarks_in_video
(
frame_container
,
method
=
"
dlib
"
):
"""
This function detects a face and face landmarks in each farme of the input video.
**Parameters:**
``frame_container`` : FrameContainer
FrameContainer containing the frames data.
``method`` : :py:class:`str`
A package to be used for face detection. Options supported by this
package:
"
dlib
"
(dlib is a dependency of this package).
**Returns:**
``annotations`` : :py:class:`dict`
A dictionary containing the annotations for each frame in the video.
Dictionary structure: ``annotations = {
'
1
'
: frame1_dict,
'
2
'
: frame1_dict, ...}``.
Where ``frameN_dict = {
'
topleft
'
: (row, col),
'
bottomright
'
: (row, col),
'
left_eye
'
: (row, col),
'
right_eye
'
: (row, col),
'
landmarks
'
: [(row1,col1), (row2,col2), ...]}``
is the dictionary defining the coordinates of the face bounding box in frame N.
Where (rowK,colK) is the location of Kth facial landmark (K=0,...,67).
If no annotations found an empty dictionary is returned.
"""
annotations
=
{}
for
idx
,
frame
in
enumerate
(
frame_container
):
image
=
frame
[
1
]
frame_annotations
=
detect_face_landmarks_in_image
(
image
,
method
);
if
frame_annotations
:
annotations
[
str
(
idx
)]
=
frame_annotations
return
annotations
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment