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
5ba868c9
Commit
5ba868c9
authored
7 years ago
by
Olegs NIKISINS
Browse files
Options
Downloads
Patches
Plain Diff
Added alignment option to normalize_image_size_in_grayscale in ImageFaceCrop
parent
e0fc9e9b
No related branches found
No related tags found
1 merge request
!57
Preprocessor refactoring, VideoFaceCrop+ImageFaceCrop replaced with FaceCropAlign+Wrapper
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/pad/face/preprocessor/ImageFaceCrop.py
+34
-15
34 additions, 15 deletions
bob/pad/face/preprocessor/ImageFaceCrop.py
with
34 additions
and
15 deletions
bob/pad/face/preprocessor/ImageFaceCrop.py
+
34
−
15
View file @
5ba868c9
...
...
@@ -51,14 +51,14 @@ class ImageFaceCrop(Preprocessor):
self
.
rgb_output_flag
=
rgb_output_flag
#==========================================================================
def
normalize_image_size_in_grayscale
(
self
,
image
,
annotations
,
face_size
):
def
normalize_image_size_in_grayscale
(
self
,
image
,
annotations
,
face_size
,
use_face_alignment
):
"""
This function crops the face in the input Gray-scale image given annotations
defining the face bounding box
. The size of the face is also normalized to the
pre-defined dimensions.
defining the face bounding box
, and eye positions.
The size of the face is also normalized to the
pre-defined dimensions.
T
he algorithm is identical to the following paper:
"
On the Effectiveness of Local Binary Patterns in Face Anti-spoofing
"
T
wo normalization options are available, which are controlled by
``use_face_alignment`` flag, see below.
**Parameters:**
...
...
@@ -66,27 +66,46 @@ class ImageFaceCrop(Preprocessor):
Gray-scale input image.
``annotations`` : :py:class:`dict`
A dictionary containing annotations of the face bounding box.
Dictionary must be as follows ``{
'
topleft
'
: (row, col),
'
bottomright
'
: (row, col)}``
A dictionary containing annotations of the face bounding box,
eye locations and facial landmarks.
Dictionary must be as follows ``{
'
topleft
'
: (row, col),
'
bottomright
'
: (row, col),
'
left_eye
'
: (row, col),
'
right_eye
'
: (row, col)``.
``face_size`` : :py:class:`int`
The size of the face after normalization.
``use_face_alignment`` : :py:class:`bool`
If ``False``, the re-sizing from this publication is used:
"
On the Effectiveness of Local Binary Patterns in Face Anti-spoofing
"
If ``True`` the facial image is both re-sized and aligned using
positions of the eyes, which are given in the annotations.
**Returns:**
``normbbx`` : 2D :py:class:`numpy.ndarray`
An image of the cropped face of the size (self.face_size, self.face_size).
"""
cutframe
=
image
[
annotations
[
'
topleft
'
][
0
]:
annotations
[
'
bottomright
'
][
0
],
annotations
[
'
topleft
'
][
1
]:
annotations
[
'
bottomright
'
][
1
]]
if
use_face_alignment
:
face_eyes_norm
=
bob
.
ip
.
base
.
FaceEyesNorm
(
eyes_distance
=
32.5
,
crop_size
=
(
face_size
,
face_size
),
eyes_center
=
(
16
,
31.75
))
# Add more params,
right_eye
,
left_eye
=
annotations
[
'
right_eye
'
],
annotations
[
'
left_eye
'
]
normalized_image
=
face_eyes_norm
(
image
,
right_eye
=
right_eye
,
left_eye
=
left_eye
)
normbbx
=
normalized_image
.
astype
(
'
uint8
'
)
else
:
cutframe
=
image
[
annotations
[
'
topleft
'
][
0
]:
annotations
[
'
bottomright
'
][
0
],
annotations
[
'
topleft
'
][
1
]:
annotations
[
'
bottomright
'
][
1
]]
tempbbx
=
np
.
ndarray
((
face_size
,
face_size
),
'
float64
'
)
normbbx
=
np
.
ndarray
((
face_size
,
face_size
),
'
uint8
'
)
bob
.
ip
.
base
.
scale
(
cutframe
,
tempbbx
)
# normalization
tempbbx_
=
tempbbx
+
0.5
tempbbx_
=
np
.
floor
(
tempbbx_
)
normbbx
=
np
.
cast
[
'
uint8
'
](
tempbbx_
)
tempbbx
=
np
.
ndarray
((
face_size
,
face_size
),
'
float64
'
)
normbbx
=
np
.
ndarray
((
face_size
,
face_size
),
'
uint8
'
)
bob
.
ip
.
base
.
scale
(
cutframe
,
tempbbx
)
# normalization
tempbbx_
=
tempbbx
+
0.5
tempbbx_
=
np
.
floor
(
tempbbx_
)
normbbx
=
np
.
cast
[
'
uint8
'
](
tempbbx_
)
return
normbbx
...
...
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