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
bob
bob.bio.face
Commits
981c5a06
Commit
981c5a06
authored
Mar 13, 2018
by
Amir MOHAMMADI
Browse files
Make imports more readable and remove boundingbox to eyes
parent
009e21a8
Pipeline
#17623
passed with stage
in 22 minutes and 41 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bob/bio/face/annotator/Base.py
View file @
981c5a06
from
bob.bio.base.annotator
import
Annotator
from
bob.bio.face.preprocessor
import
FaceCrop
# import for documentation
import
bob.bio.base.annotator
import
bob.bio.face.preprocessor
# import for documentation
class
Base
(
Annotator
):
class
Base
(
bob
.
bio
.
base
.
annotator
.
Annotator
):
"""Base class for all face annotators"""
def
__init__
(
self
,
**
kwargs
):
...
...
@@ -12,7 +12,8 @@ class Base(Annotator):
"""Annotates an image and returns annotations in a dictionary. All
annotator should return at least the ``topleft`` and ``bottomright``
coordinates. Some currently known annotation points such as ``reye``
and ``leye`` are formalized in :any:`FaceCrop`.
and ``leye`` are formalized in
:any:`bob.bio.face.preprocessor.FaceCrop`.
Parameters
----------
...
...
bob/bio/face/annotator/__init__.py
View file @
981c5a06
...
...
@@ -47,7 +47,7 @@ def min_face_size_validator(annotations, min_face_size=(32, 32)):
# These imports should be here to avoid circular dependencies
from
.Base
import
Base
from
.bobipfacedetect
import
BobIpFacedetect
,
BoundingBoxToEyes
from
.bobipfacedetect
import
BobIpFacedetect
from
.bobipflandmark
import
BobIpFlandmark
from
.bobipdlib
import
BobIpDlib
from
.bobipmtcnn
import
BobIpMTCNN
...
...
@@ -75,7 +75,6 @@ def __appropriate__(*args):
__appropriate__
(
Base
,
BobIpFacedetect
,
BoundingBoxToEyes
,
BobIpFlandmark
,
BobIpDlib
,
BobIpMTCNN
,
...
...
bob/bio/face/annotator/bobipfacedetect.py
View file @
981c5a06
import
math
from
bob.io.base
import
HDF5File
from
bob.ip.color
import
rgb_to_gray
from
bob.ip.facedetect
import
(
detect_single_face
,
Sampler
,
default_cascade
,
Cascade
,
bounding_box_from_annotation
,
expected_eye_positions
)
import
bob.io.base
import
bob.ip.color
import
bob.ip.facedetect
from
.
import
Base
,
bounding_box_to_annotations
class
BobIpFacedetect
(
Base
):
"""Annotator using bob.ip.facedetect
Provides topleft and bottomright annoations.
Parameters
----------
cascade : :any:`bob.ip.facedetect.Cascade`
The file name, where a face detector cascade can be found. If ``None``,
the default cascade for frontal faces
:any:`bob.ip.facedetect.default_cascade` is used.
detection_overlap : float
See :any:`bob.ip.facedetect.detect_single_face`.
distance : int
See the Sampling section in the
:ref:`Users Guide of bob.ip.facedetect <bob.ip.facedetect>`.
scale_base : float
See the Sampling section in the
:ref:`Users Guide of bob.ip.facedetect <bob.ip.facedetect>`.
lowest_scale : float
See the Sampling section in the
:ref:`Users Guide of bob.ip.facedetect <bob.ip.facedetect>`.
eye_estimate : bool
If ``True``, expected eye locations are added to the annotations.
"""
def
__init__
(
self
,
cascade
=
None
,
detection_overlap
=
0.2
,
distance
=
2
,
scale_base
=
math
.
pow
(
2.
,
-
1.
/
16.
),
lowest_scale
=
0.125
,
eye_estimate
=
False
,
**
kwargs
):
super
(
BobIpFacedetect
,
self
).
__init__
(
**
kwargs
)
self
.
sampler
=
Sampler
(
self
.
sampler
=
bob
.
ip
.
facedetect
.
Sampler
(
scale_factor
=
scale_base
,
lowest_scale
=
lowest_scale
,
distance
=
distance
)
if
cascade
is
None
:
self
.
cascade
=
default_cascade
()
self
.
cascade
=
bob
.
ip
.
facedetect
.
default_cascade
()
else
:
self
.
cascade
=
Cascade
(
HDF5File
(
cascade
))
self
.
cascade
=
bob
.
ip
.
facedetect
.
Cascade
(
bob
.
io
.
base
.
HDF5File
(
cascade
))
self
.
detection_overlap
=
detection_overlap
self
.
eye_estimate
=
eye_estimate
def
annotate
(
self
,
image
,
**
kwargs
):
"""Return topleft and bottomright and expected eye positions
...
...
@@ -43,47 +69,13 @@ class BobIpFacedetect(Base):
quality, leye, reye.
"""
if
image
.
ndim
==
3
:
image
=
rgb_to_gray
(
image
)
b
ounding_bo
x
,
quality
=
detect_single_face
(
image
=
bob
.
ip
.
color
.
rgb_to_gray
(
image
)
b
b
x
,
quality
=
bob
.
ip
.
facedetect
.
detect_single_face
(
image
,
self
.
cascade
,
self
.
sampler
,
self
.
detection_overlap
)
landmarks
=
bounding_box_to_annotations
(
bounding_box
)
landmarks
[
'quality'
]
=
quality
return
landmarks
class
BoundingBoxToEyes
(
Base
):
"""Converts bounding box annotations to eye locations. The bounding box's
annotations is expected to have come from :any:`BobIpFacedetect`.
Example usage:
.. doctest::
>>> from bob.bio.base.annotator import FailSafe
>>> from bob.bio.face.annotator import (
... BobIpFacedetect, BoundingBoxToEyes)
>>> annotator = FailSafe(
... [BobIpFacedetect(), BoundingBoxToEyes()],
... required_keys=('reye', 'leye'))
"""
def
annotate
(
self
,
image
,
annotations
,
**
kwargs
):
"""Converts bounding boxes of bob.ip.facedetect to eye locations.
Parameters
----------
image : numpy.array
Ignored.
annotations : dict
The annotations that are given by :any:`BobIpFacedetect`.
**kwargs
Ignored.
landmarks
=
bounding_box_to_annotations
(
bbx
)
landmarks
[
'quality'
]
=
quality
if
self
.
eye_estimate
:
landmarks
.
update
(
bob
.
ip
.
facedetect
.
expected_eye_positions
(
bbx
))
Returns
-------
dict
The annotations with reye and leye locations added.
"""
bbx
=
bounding_box_from_annotation
(
source
=
'direct'
,
**
annotations
)
annotations
.
update
(
expected_eye_positions
(
bbx
))
return
annotations
return
landmarks
bob/bio/face/config/annotator/facedetect_eye_estimate.py
View file @
981c5a06
from
bob.bio.base.annotator
import
FailSafe
from
bob.bio.face.annotator
import
BobIpFacedetect
,
BoundingBoxToEyes
from
bob.bio.face.annotator
import
BobIpFacedetect
annotator
=
FailSafe
(
[
BobIpFacedetect
(),
BoundingBoxToEyes
()],
required_keys
=
(
'reye'
,
'leye'
))
annotator
=
BobIpFacedetect
(
eye_estimate
=
True
)
bob/bio/face/test/test_annotators.py
View file @
981c5a06
...
...
@@ -2,7 +2,7 @@ import bob.io.base
import
bob.io.base.test_utils
import
bob.io.image
from
bob.bio.face.annotator
import
(
BobIpFacedetect
,
BoundingBoxToEyes
,
BobIpFlandmark
,
BobIpFacedetect
,
BobIpFlandmark
,
min_face_size_validator
)
from
bob.bio.base.annotator
import
FailSafe
import
numpy
...
...
@@ -18,19 +18,12 @@ def _assert_bob_ip_facedetect(annot):
def
test_bob_ip_facedetect
():
from
bob.bio.face.annotator.bobipfacedetect
import
BobIpFacedetect
annot
=
BobIpFacedetect
()(
face_image
)
_assert_bob_ip_facedetect
(
annot
)
def
test_bob_ip_facedetect_eyes
():
annotator
=
FailSafe
(
[
BobIpFacedetect
(),
BoundingBoxToEyes
()],
required_keys
=
(
'reye'
,
'leye'
),
)
annot
=
annotator
(
face_image
)
annot
=
BobIpFacedetect
(
eye_estimate
=
True
)(
face_image
)
_assert_bob_ip_facedetect
(
annot
)
assert
[
int
(
x
)
for
x
in
annot
[
'reye'
]]
==
[
175
,
128
],
annot
assert
[
int
(
x
)
for
x
in
annot
[
'leye'
]]
==
[
175
,
221
],
annot
...
...
doc/implemented.rst
View file @
981c5a06
...
...
@@ -34,7 +34,6 @@ Face Image Annotators
.. autosummary::
bob.bio.face.annotator.Base
bob.bio.face.annotator.BobIpFacedetect
bob.bio.face.annotator.BoundingBoxToEyes
bob.bio.face.annotator.BobIpFlandmark
bob.bio.face.annotator.BobIpDlib
bob.bio.face.annotator.BobIpMTCNN
...
...
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