1 | <?php |
||
14 | class FaceDetection |
||
15 | { |
||
16 | private $url; |
||
17 | private $subscriptionKey; |
||
18 | private $image; |
||
19 | private $returnFaceId = false; |
||
20 | private $returnFaceLandmarks = false; |
||
21 | private $returnFaceAttributes = ''; |
||
22 | |||
23 | /** |
||
24 | * Constructor |
||
25 | */ |
||
26 | public function __construct($image) { |
||
32 | |||
33 | /** |
||
34 | * Get all the face/s detected in an image. |
||
35 | * |
||
36 | */ |
||
37 | public function getFaces() |
||
38 | { |
||
39 | $params = array( |
||
40 | 'returnFaceId' => $this->returnFaceId, |
||
41 | 'returnFaceLandmarks' => $this->returnFaceLandmarks, |
||
42 | 'returnFaceAttributes' => $this->returnFaceAttributes |
||
43 | ); |
||
44 | |||
45 | $query = http_build_query($params); |
||
46 | $image = json_encode($this->image); |
||
47 | |||
48 | $ch = curl_init(); |
||
49 | curl_setopt($ch, CURLOPT_URL, $this->url . '?' . $query); |
||
50 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
||
51 | curl_setopt($ch, CURLOPT_POSTFIELDS, $image); |
||
52 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
53 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
||
54 | 'Ocp-Apim-Subscription-Key: ' . $this->subscriptionKey, |
||
55 | 'Content-Type: application/json', |
||
56 | 'Content-Length: ' . strlen($image) |
||
57 | ) |
||
58 | ); |
||
59 | $response = curl_exec($ch); |
||
60 | |||
61 | return $response; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Optional parameter to get face landmarks. |
||
66 | * |
||
67 | */ |
||
68 | public function analyzeFaceLandmarks() { |
||
73 | |||
74 | /** |
||
75 | * Optional parameter to get face attributes. |
||
76 | * |
||
77 | */ |
||
78 | public function analyzeFaceAttributes() { |
||
83 | |||
84 | /** |
||
85 | * Alternatively, you can enable all options. |
||
86 | * |
||
87 | */ |
||
88 | public function analyzeAll() { |
||
94 | } |
||
95 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.