Tips

Cloud Vision APIをPHPから使ってみた。その③

Cloud Vision APIをPHPから使ってみた。その③

Cloud Vision APIをPHPから使ってみた。その③

前回はCloud Vision APIにPHP側からリクエストを投げるところまでを行いましたので、
今回はレスポンスの結果を確認していきたいと思います。

レスポンス内容

まずはレスポンス内容を見てみましょう。
今回はFACE_DETECTIONのみを指定していますので、FACE関連の内容しか出てきませんが、
他のDETECTIONも指定すると、もっと沢山出てきます。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
{
    "responses": [
        {
            "faceAnnotations": [
                {
                    "angerLikelihood": "UNLIKELY",
                    "blurredLikelihood": "VERY_UNLIKELY",
                    "boundingPoly": {
                        "vertices": [
                            {
                                "x": 277,
                                "y": 44
                            },
                            {
                                "x": 421,
                                "y": 44
                            },
                            {
                                "x": 421,
                                "y": 212
                            },
                            {
                                "x": 277,
                                "y": 212
                            }
                        ]
                    },
                    "detectionConfidence": 0.89532435,
                    "fdBoundingPoly": {
                        "vertices": [
                            {
                                "x": 303,
                                "y": 83
                            },
                            {
                                "x": 399,
                                "y": 83
                            },
                            {
                                "x": 399,
                                "y": 179
                            },
                            {
                                "x": 303,
                                "y": 179
                            }
                        ]
                    },
                    "headwearLikelihood": "VERY_UNLIKELY",
                    "joyLikelihood": "VERY_UNLIKELY",
                    "landmarkingConfidence": 0.71623695,
                    "landmarks": [
                        {
                            "position": {
                                "x": 332.76343,
                                "y": 113.692245,
                                "z": 0.0010525604
                            },
                            "type": "LEFT_EYE"
                        },
                        {
                            "position": {
                                "x": 369.34872,
                                "y": 113.70369,
                                "z": -0.04455744
                            },
                            "type": "RIGHT_EYE"
                        },
                        {
                            "position": {
                                "x": 315.5745,
                                "y": 103.84334,
                                "z": 4.8573413
                            },
                            "type": "LEFT_OF_LEFT_EYEBROW"
                        },
                        {
                            "position": {
                                "x": 340.6877,
                                "y": 100.55593,
                                "z": -6.7010517
                            },
                            "type": "RIGHT_OF_LEFT_EYEBROW"
                        },
                        {
                            "position": {
                                "x": 360.66492,
                                "y": 100.841,
                                "z": -6.675439
                            },
                            "type": "LEFT_OF_RIGHT_EYEBROW"
                        },
                        {
                            "position": {
                                "x": 385.28314,
                                "y": 104.174805,
                                "z": 4.846083
                            },
                            "type": "RIGHT_OF_RIGHT_EYEBROW"
                        },
                        {
                            "position": {
                                "x": 350.5497,
                                "y": 111.564865,
                                "z": -8.780574
                            },
                            "type": "MIDPOINT_BETWEEN_EYES"
                        },
                        {
                            "position": {
                                "x": 350.6659,
                                "y": 133.53343,
                                "z": -25.98531
                            },
                            "type": "NOSE_TIP"
                        },
                        {
                            "position": {
                                "x": 350.88446,
                                "y": 152.79016,
                                "z": -18.262651
                            },
                            "type": "UPPER_LIP"
                        },
                        {
                            "position": {
                                "x": 350.79382,
                                "y": 168.62276,
                                "z": -17.48801
                            },
                            "type": "LOWER_LIP"
                        },
                        {
                            "position": {
                                "x": 337.01038,
                                "y": 162.19357,
                                "z": -8.738847
                            },
                            "type": "MOUTH_LEFT"
                        },
                        {
                            "position": {
                                "x": 364.25076,
                                "y": 161.97086,
                                "z": -8.87977
                            },
                            "type": "MOUTH_RIGHT"
                        },
                        {
                            "position": {
                                "x": 350.7603,
                                "y": 160.12784,
                                "z": -16.026594
                            },
                            "type": "MOUTH_CENTER"
                        },
                        {
                            "position": {
                                "x": 361.30548,
                                "y": 139.67697,
                                "z": -9.994327
                            },
                            "type": "NOSE_BOTTOM_RIGHT"
                        },
                        {
                            "position": {
                                "x": 341.03574,
                                "y": 139.70354,
                                "z": -10.173845
                            },
                            "type": "NOSE_BOTTOM_LEFT"
                        },
                        {
                            "position": {
                                "x": 350.99435,
                                "y": 141.5242,
                                "z": -16.810558
                            },
                            "type": "NOSE_BOTTOM_CENTER"
                        },
                        {
                            "position": {
                                "x": 327.90234,
                                "y": 110.401825,
                                "z": -2.1700659
                            },
                            "type": "LEFT_EYE_TOP_BOUNDARY"
                        },
                        {
                            "position": {
                                "x": 339.141,
                                "y": 114.66393,
                                "z": 0.17736068
                            },
                            "type": "LEFT_EYE_RIGHT_CORNER"
                        },
                        {
                            "position": {
                                "x": 331.3952,
                                "y": 117.13222,
                                "z": -0.74573904
                            },
                            "type": "LEFT_EYE_BOTTOM_BOUNDARY"
                        },
                        {
                            "position": {
                                "x": 319.67868,
                                "y": 114.63684,
                                "z": 4.0833383
                            },
                            "type": "LEFT_EYE_LEFT_CORNER"
                        },
                        {
                            "position": {
                                "x": 327.14227,
                                "y": 113.88191,
                                "z": -0.55243915
                            },
                            "type": "LEFT_EYE_PUPIL"
                        },
                        {
                            "position": {
                                "x": 372.6692,
                                "y": 110.03074,
                                "z": -2.2177434
                            },
                            "type": "RIGHT_EYE_TOP_BOUNDARY"
                        },
                        {
                            "position": {
                                "x": 379.61917,
                                "y": 113.85382,
                                "z": 3.70754
                            },
                            "type": "RIGHT_EYE_RIGHT_CORNER"
                        },
                        {
                            "position": {
                                "x": 369.88336,
                                "y": 116.95369,
                                "z": -0.7889224
                            },
                            "type": "RIGHT_EYE_BOTTOM_BOUNDARY"
                        },
                        {
                            "position": {
                                "x": 361.6826,
                                "y": 114.54378,
                                "z": 0.1364616
                            },
                            "type": "RIGHT_EYE_LEFT_CORNER"
                        },
                        {
                            "position": {
                                "x": 373.2228,
                                "y": 113.504074,
                                "z": -0.6530298
                            },
                            "type": "RIGHT_EYE_PUPIL"
                        },
                        {
                            "position": {
                                "x": 325.837,
                                "y": 97.099304,
                                "z": -2.0782194
                            },
                            "type": "LEFT_EYEBROW_UPPER_MIDPOINT"
                        },
                        {
                            "position": {
                                "x": 374.49063,
                                "y": 96.73857,
                                "z": -2.1848493
                            },
                            "type": "RIGHT_EYEBROW_UPPER_MIDPOINT"
                        },
                        {
                            "position": {
                                "x": 300.00845,
                                "y": 145.06592,
                                "z": 50.649952
                            },
                            "type": "LEFT_EAR_TRAGION"
                        },
                        {
                            "position": {
                                "x": 397.4974,
                                "y": 143.11761,
                                "z": 48.0778
                            },
                            "type": "RIGHT_EAR_TRAGION"
                        },
                        {
                            "position": {
                                "x": 350.22372,
                                "y": 100.80855,
                                "z": -8.056211
                            },
                            "type": "FOREHEAD_GLABELLA"
                        },
                        {
                            "position": {
                                "x": 350.92908,
                                "y": 189.51155,
                                "z": -14.014768
                            },
                            "type": "CHIN_GNATHION"
                        },
                        {
                            "position": {
                                "x": 304.9187,
                                "y": 170.83353,
                                "z": 27.585705
                            },
                            "type": "CHIN_LEFT_GONION"
                        },
                        {
                            "position": {
                                "x": 396.78854,
                                "y": 169.80559,
                                "z": 27.643484
                            },
                            "type": "CHIN_RIGHT_GONION"
                        }
                    ],
                    "panAngle": -0.041533586,
                    "rollAngle": -0.4864438,
                    "sorrowLikelihood": "VERY_UNLIKELY",
                    "surpriseLikelihood": "VERY_LIKELY",
                    "tiltAngle": 9.323663,
                    "underExposedLikelihood": "VERY_UNLIKELY"
                }
            ]
        }
    ]
}

読み取れる感情としては以下の4つ

  • angerLikelihood(怒り)
  • sorrowLikelihood(悲しみ)
  • joyLikelihood(楽しみ)
  • surpriseLikelihood(驚き)

その他に

  • underExposedLikelihood(露光度合い)
  • blurredLikelihood(ぼやけ具合)

といった内容や

  • headwearLikelihood(帽子を被っているか)

といったものまで解析できるようです。

また、その解析の確からしさが

  • detectionConfidence

で数値化されています。
前回の戻り値のJSON($jsonArr)を使うと

1
2
echo $jsonArr["responses"][0]["faceAnnotations"][0]["angerLikelihood"];
echo $jsonArr["responses"][0]["faceAnnotations"][0]["detectionConfidence"];

といった記述で表示することができます。

次回は解析画像をアップロードする用のPHPプログラムを作成します。

初級インフラエンジニアにオススメ連載リンク

ネットワーク学習の登竜門・・
ゼロからのCCNA独学講座

Linuxの取り扱いを基礎から学ぶ
Linux資格 「LPIC-Lv1」徹底解説

Recent News

Recent Tips

Tag Search