dragu / google-vision
针对 PHP 的 Google Vision Api(https://cloud.google.com/vision/),已修复文字功能
2.0.1
2024-07-11 11:28 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ~7.1
- laminas/laminas-hydrator: ~4.13
Requires (Dev)
- phpunit/phpunit: ^10.3
This package is auto-updated.
Last update: 2024-09-11 11:51:08 UTC
README
安装
通过 Composer 安装 Google Vision 是最简单的方法。
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()); } }
可用功能
可用图像加载器
要添加功能,请向用作第二个参数的功能数组中添加一个 new \Vision\Feature
实例。有关完整示例,请参阅 基本用法。
new \Vision\Feature($feature, $maxResults);
运行测试
$ composer install $ ./vendor/bin/phpunit
作者
Jordi Kroon | Github | Twitter | jordikroon.nl