|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2017 Google Inc. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | + |
| 19 | +namespace Google\Cloud\Samples\Vision; |
| 20 | + |
| 21 | +# [START face_detection_gcs] |
| 22 | +use Google\Cloud\ServiceBuilder; |
| 23 | + |
| 24 | +// $projectId = 'YOUR_PROJECT_ID'; |
| 25 | +// $bucketName = 'your-bucket-name' |
| 26 | +// $objectName = 'your-object-name' |
| 27 | + |
| 28 | +$builder = new ServiceBuilder([ |
| 29 | + 'projectId' => $projectId, |
| 30 | +]); |
| 31 | +$vision = $builder->vision(); |
| 32 | +$storage = $builder->storage(); |
| 33 | + |
| 34 | +// fetch the storage object and annotate the image |
| 35 | +$object = $storage->bucket($bucketName)->object($objectName); |
| 36 | +$image = $vision->image($object, ['FACE_DETECTION']); |
| 37 | +$result = $vision->annotate($image); |
| 38 | + |
| 39 | +// print the response |
| 40 | +print("Faces:\n"); |
| 41 | +foreach ((array) $result->faces() as $face) { |
| 42 | + printf("Anger: %s\n", $face->isAngry() ? 'yes' : 'no'); |
| 43 | + printf("Joy: %s\n", $face->isJoyful() ? 'yes' : 'no'); |
| 44 | + printf("Surprise: %s\n\n", $face->isSurprised() ? 'yes' : 'no'); |
| 45 | +} |
| 46 | +# [END face_detection_gcs] |
| 47 | +return $result; |
0 commit comments