|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XSolve\FaceValidatorBundle\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
|
6
|
|
|
use XSolve\FaceValidatorBundle\Calculator\FaceToImageRatioCalculator; |
|
7
|
|
|
use XSolve\FaceValidatorBundle\Result\Accessory; |
|
8
|
|
|
use XSolve\FaceValidatorBundle\Result\Blur; |
|
9
|
|
|
use XSolve\FaceValidatorBundle\Result\BlurLevel; |
|
10
|
|
|
use XSolve\FaceValidatorBundle\Result\Exposure; |
|
11
|
|
|
use XSolve\FaceValidatorBundle\Result\ExposureLevel; |
|
12
|
|
|
use XSolve\FaceValidatorBundle\Result\FaceDetectionResult; |
|
13
|
|
|
use XSolve\FaceValidatorBundle\Result\Glasses; |
|
14
|
|
|
use XSolve\FaceValidatorBundle\Result\Makeup; |
|
15
|
|
|
use XSolve\FaceValidatorBundle\Result\Noise; |
|
16
|
|
|
use XSolve\FaceValidatorBundle\Result\NoiseLevel; |
|
17
|
|
|
use XSolve\FaceValidatorBundle\Result\Rotation; |
|
18
|
|
|
|
|
19
|
|
|
class FaceDetectionResultFactory |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var PropertyAccessorInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $propertyAccessor; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var FaceToImageRatioCalculator |
|
28
|
|
|
*/ |
|
29
|
|
|
private $faceToImageRatioCalculator; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct(PropertyAccessorInterface $propertyAccessor, FaceToImageRatioCalculator $faceToImageRatioCalculator) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->propertyAccessor = $propertyAccessor; |
|
34
|
|
|
$this->faceToImageRatioCalculator = $faceToImageRatioCalculator; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function create(string $imagePath, array $data): FaceDetectionResult |
|
38
|
|
|
{ |
|
39
|
|
|
return new FaceDetectionResult( |
|
40
|
|
|
$this->faceToImageRatioCalculator->calculate( |
|
41
|
|
|
$imagePath, |
|
42
|
|
|
$this->propertyAccessor->getValue($data, '[faceRectangle][width]'), |
|
43
|
|
|
$this->propertyAccessor->getValue($data, '[faceRectangle][height]') |
|
44
|
|
|
), |
|
45
|
|
|
new Rotation( |
|
46
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][headPose][pitch]'), |
|
47
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][headPose][roll]'), |
|
48
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][headPose][yaw]') |
|
49
|
|
|
), |
|
50
|
|
|
new Glasses( |
|
51
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][glasses]') |
|
52
|
|
|
), |
|
53
|
|
|
new Blur( |
|
54
|
|
|
new BlurLevel( |
|
55
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][blur][blurLevel]') |
|
56
|
|
|
), |
|
57
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][blur][value]') |
|
58
|
|
|
), |
|
59
|
|
|
new Exposure( |
|
60
|
|
|
new ExposureLevel( |
|
61
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][exposure][exposureLevel]') |
|
62
|
|
|
), |
|
63
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][exposure][value]') |
|
64
|
|
|
), |
|
65
|
|
|
new Noise( |
|
66
|
|
|
new NoiseLevel( |
|
67
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][noise][noiseLevel]') |
|
68
|
|
|
), |
|
69
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][noise][value]') |
|
70
|
|
|
), |
|
71
|
|
|
new Makeup( |
|
72
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][makeup][eyeMakeup]'), |
|
73
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][makeup][lipMakeup]') |
|
74
|
|
|
), |
|
75
|
|
|
array_map( |
|
76
|
|
|
function (array $accessoryData) { |
|
77
|
|
|
return new Accessory($accessoryData['type']); |
|
78
|
|
|
}, |
|
79
|
|
|
$this->propertyAccessor->getValue($data, '[faceAttributes][accessories]') |
|
80
|
|
|
), |
|
81
|
|
|
!$this->propertyAccessor->getValue($data, '[faceAttributes][hair][invisible]') |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|