2 Copyright (c) 2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
19 from ..config import BoolField
20 from ..postprocessor.postprocessor import Postprocessor, BasePostprocessorConfig
21 from ..representation import FacialLandmarksAnnotation, FacialLandmarksPrediction
24 class NormalizeLandmarksPoints(Postprocessor):
25 __provider__ = 'normalize_landmarks_points'
27 annotation_types = (FacialLandmarksAnnotation, )
28 prediction_types = (FacialLandmarksPrediction, )
30 def validate_config(self):
31 class _ConfigValidator(BasePostprocessorConfig):
32 use_annotation_rect = BoolField(optional=True)
34 config_validator = _ConfigValidator(
35 self.__provider__, on_extra_argument=_ConfigValidator.ERROR_ON_EXTRA_ARGUMENT
37 config_validator.validate(self.config)
40 self.use_annotation_rect = self.config.get('use_annotation_rect', False)
42 def process_image(self, annotation, prediction):
43 for target in annotation:
44 height, width, _ = self.image_size
45 x_start, y_start = 0, 0
46 if self.use_annotation_rect:
47 resized_box = annotation[0].metadata.get('rect')
48 x_start, y_start, x_max, y_max = resized_box
49 width = x_max - x_start
50 height = y_max - y_start
53 (np.array(target.x_values, dtype=float) - x_start) / np.maximum(width, np.finfo(np.float64).eps)
56 (np.array(target.y_values, dtype=float) - y_start) / np.maximum(height, np.finfo(np.float64).eps)
59 return annotation, prediction