Help us understand the problem. What is going on with this article?

Google CLOUD VISION で顔認識

More than 1 year has passed since last update.

今回は cakephp3 で。

ライブラリをインストール


composer require google/cloud-vision

APIをオンに

https://cloud.google.com/vision/docs/quickstart?hl=ja

screenshot.1.png

鍵ファイルを取得

以下を参考に。
https://qiita.com/ma7ma7pipipi/items/ad33e001b6d08c3368e6

コード

<?php

namespace App\Controller;
use App\Controller\AppController;

//ライブラリを読み込み
use Google\Cloud\Vision\VisionClient;

class HogesController extends AppController
{


    public function test()
    {

        $projectId = "carbide-parser-99999";//プロジェクトID

        $vision = new VisionClient([
            'projectId' => $projectId,
            //鍵ファイルを指定
            'keyFile' => json_decode(file_get_contents(CONFIG.'warai.json'), true)

        ]);

        //解析したい画像を指定
        $image = $vision->image(file_get_contents(WWW_ROOT."img/girl.jpg"), ['FACE_DETECTION']);

        $result = $vision->annotate($image);

        print("Faces:\n");
        foreach ((array) $result->faces() as $face) {
            printf("Anger: %s\n", $face->isAngry() ? 'yes' : 'no');
            printf("Joy: %s\n", $face->isJoyful() ? 'yes' : 'no');
            printf("Surprise: %s\n\n", $face->isSurprised() ? 'yes' : 'no');
        }

        $this->autoRender = false;
    }



}


結果

Faces: Anger: no Joy: no Surprise: no

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした