kontrimas/google-vision

Google Vision Api for PHP (https://cloud.google.com/vision/)

1.7.4 2018-02-25 21:56 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:22 UTC


README

Latest Stable Version Build Status Dependency Status License

安装

安装 Google Vision 最简单的方式是通过 Composer

composer require jordikroon/google-vision

接下来,通过 Google Cloud Platform 获取 API 密钥。访问以下链接获取 API 密钥。https://cloud.google.com/vision/docs/quickstart

需求

基本用法

$vision = new \Vision\Vision(
    $apiKey, 
    [
        // See a list of all features in the table below
        // Feature, Limit
        new \Vision\Feature(\Vision\Feature::FACE_DETECTION, 100),
    ]
);

$imagePath = $_FILES['file']['tmp_name'];
$response = $vision->request(
    // See a list of all image loaders in the table below
    new \Vision\Request\Image\LocalImage($imagePath)
);

$faces = $response->getFaceAnnotations();
foreach ($faces as $face) {
    foreach ($face->getBoundingPoly()->getVertices() as $vertex) {
        echo sprintf('Person at position X %f and Y %f', $vertex->getX(), $vertex->getY());
    }
}

可用功能

可用图像加载器

要添加功能,将一个 new \Vision\Feature 实例添加到用作第二个参数的功能数组中。请参阅 基本用法 获取完整示例。

new \Vision\Feature($feature, $maxResults);

运行测试

$ composer install
$ ./vendor/bin/phpunit 

作者

Jordi Kroon | Github | Twitter | jordikroon.nl