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
f3924df7
Commit
f3924df7
authored
6 years ago
by
Olegs NIKISINS
Browse files
Options
Downloads
Patches
Plain Diff
Added the configuration file to assess teh quality for 128x128 images
parent
ad9ff9f7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!83
Preprocessing and quality check
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/pad/face/config/quality_assessment/celeb_a/quality_assessment_config_128.py
+162
-0
162 additions, 0 deletions
...ality_assessment/celeb_a/quality_assessment_config_128.py
with
162 additions
and
0 deletions
bob/pad/face/config/quality_assessment/celeb_a/quality_assessment_config_128.py
0 → 100644
+
162
−
0
View file @
f3924df7
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Quality assessment configuration file for the CelebA database to be used
with quality assessment script.
Note: this config checks the quality of the preprocessed(!) data. Here the
preprocessed data is sored in ``.hdf5`` files, as a frame container with
one frame. Frame contains a BW image of the facial regions of the size
128x128 pixels.
The config file MUST contain at least the following functions:
``load_datafile(file_name)`` - returns the ``data`` given ``file_name``, and
``assess_quality(data, **assess_quality_kwargs)`` - returns ``True`` for good
quality ``data``, and ``False`` for low quality data, and
``assess_quality_kwargs`` - a dictionary with kwargs for ``assess_quality()``
function.
@author: Olegs Nikisins
"""
# =============================================================================
# Import here:
import
pkg_resources
import
cv2
from
bob.bio.video.preprocessor
import
Wrapper
import
numpy
as
np
import
bob.ip.color
# =============================================================================
def
detect_eyes_in_bw_image
(
image
):
"""
Detect eyes in the image using OpenCV.
**Parameters:**
``image`` : 2D :py:class:`numpy.ndarray`
A BW image to detect the eyes in.
**Returns:**
``eyes`` : 2D :py:class:`numpy.ndarray`
An array containing coordinates of the bounding boxes of detected eyes.
The dimensionality of the array:
``num_of_detected_eyes x coordinates_of_bbx``
"""
eye_model
=
pkg_resources
.
resource_filename
(
'
bob.pad.face.config
'
,
'
quality_assessment/models/eye_detector.xml
'
)
eye_cascade
=
cv2
.
CascadeClassifier
(
eye_model
)
if
len
(
image
.
shape
)
==
3
:
image
=
bob
.
ip
.
color
.
rgb_to_gray
(
image
)
eyes
=
eye_cascade
.
detectMultiScale
(
image
)
return
eyes
# =============================================================================
def
load_datafile
(
file_name
):
"""
Load data from file given filename. Here the data file is an hdf5 file
containing a framecontainer with one frame. The data in the frame is
a BW image of the facial region.
**Parameters:**
``file_name`` : str
Absolute name of the file.
**Returns:**
``data`` : 2D :py:class:`numpy.ndarray`
Data array containing the image of the facial region.
"""
frame_container
=
Wrapper
().
read_data
(
file_name
)
data
=
frame_container
[
0
][
1
]
return
data
# =============================================================================
face_size
=
128
eyes_distance
=
((
face_size
+
1
)
/
2.
)
eyes_center
=
(
face_size
/
4.
,
(
face_size
-
0.5
)
/
2.
)
eyes_expected
=
[[
eyes_center
[
0
],
eyes_center
[
1
]
-
eyes_distance
/
2.
],
[
eyes_center
[
0
],
eyes_center
[
1
]
+
eyes_distance
/
2.
]]
assess_quality_kwargs
=
{}
assess_quality_kwargs
[
"
eyes_expected
"
]
=
eyes_expected
assess_quality_kwargs
[
"
threshold
"
]
=
10
# =============================================================================
def
assess_quality
(
data
,
eyes_expected
,
threshold
):
"""
Assess the quality of the data sample, which in this case is an image of
the face of the size 128x128 pixels. The quality assessment is based on the
eye detection. If two eyes are detected, and they are located in the
pre-defined positions, then quality is good, otherwise the quality is low.
**Parameters:**
``data`` : 2D :py:class:`numpy.ndarray`
Data array containing the image of the facial region. The size of the
image is 128x128.
``eyes_expected`` : list
A list containing expected coordinates of the eyes. The format is
as follows:
[ [left_y, left_x], [right_y, right_x] ]
``threshold`` : int
A maximum allowed distance between expected and detected centers of
the eyes.
**Returns:**
``quality_flag`` : bool
``True`` for good quality data, ``False`` otherwise.
"""
quality_flag
=
False
eyes
=
detect_eyes_in_bw_image
(
data
)
if
isinstance
(
eyes
,
np
.
ndarray
):
if
eyes
.
shape
[
0
]
==
2
:
# only consider the images with two eyes detected
# coordinates of detected centers of the eyes: [ [left_y, left_x], [right_y, right_x] ]:
eyes_detected
=
[]
for
(
ex
,
ey
,
ew
,
eh
)
in
eyes
:
eyes_detected
.
append
(
[
ey
+
eh
/
2.
,
ex
+
ew
/
2.
]
)
dists
=
[]
# dits between detected and expected:
for
a
,
b
in
zip
(
eyes_detected
,
eyes_expected
):
dists
.
append
(
np
.
linalg
.
norm
(
np
.
array
(
a
)
-
np
.
array
(
b
))
)
max_dist
=
np
.
max
(
dists
)
if
max_dist
<
threshold
:
quality_flag
=
True
return
quality_flag
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