jordikroon/google-vision

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

1.8.2 2019-11-29 11:50 UTC

README

Latest Stable Version Build Status Dependency Status License

安装

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

composer require jordikroon/google-vision

接下来,通过Google Cloud Platform获取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());
    }
}

可用功能

可用图像加载器

要添加功能,请将新的\Vision\Feature实例添加到作为第二个参数使用的features数组中。有关完整示例,请参阅基本用法

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

运行测试

$ composer install
$ ./vendor/bin/phpunit 

作者

Jordi Kroon | Github | Twitter | jordikroon.nl