pkboom/google-vision

v0.1 2020-08-13 19:03 UTC

This package is auto-updated.

Last update: 2024-09-21 01:53:20 UTC


README

Latest Stable Version Total Downloads

此包让使用Google Vision变得轻松。一旦设置好,您可以进行以下操作

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->text($imagePath);

// statically
use Pkboom\GoogleVision\Facades\GoogleVision;

GoogleVision::face($imagePath);

安装

您可以通过composer安装此包

composer require pkboom/google-vision

您必须使用以下命令发布配置

php artisan vendor:publish --provider="Pkboom\GoogleVision\GoogleVisionServiceProvider"

这将在一个名为google-vision.php的文件中发布您的配置目录,内容如下

return [
    /*
     * Path to the json file containing the credentials.
     */
    'service_account_credentials_json' => storage_path('app/service-account/credentials.json'),
];

如何获取与Google Vision通信的凭证

如何获取与Google日历通信的凭证

Google Vision设置

使用

检测文本或手写

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->text($imagePath);

检测标志

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->logo($imagePath);

// with extension
$result = $googleVision->logo($imagePath, $imageExtension);

// with file output
$result = $googleVision
    ->output($outputFilePath);
    ->logo($imagePath);

检测裁剪提示

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->cropHints($imagePath);

检测文档

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->document($imagePath);

检测人脸

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->face($imagePath, $extension, $outputPath);

// with extension
$result = $googleVision->face($imagePath, $imageExtension);

// with file output
$result = $googleVision
    ->output($outputFilePath);
    ->face($imagePath);

检测图像属性

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->imageProperty($imagePath);

检测图像标签

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->label($imagePath);

检测地标

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->landmark($imagePath);

// with extension
$result = $googleVision->landmark($imagePath, $imageExtension);

// with file output
$result = $googleVision
    ->output($outputFilePath);
    ->landmark($imagePath);

检测对象

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->object($imagePath);

检测显式内容

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->safeSearch($imagePath);

检测Web实体和页面

use Pkboom\GoogleVision\GoogleVisionFactory;

$googleVision = GoogleVisionFactory::create();

$result = $googleVision->web($imagePath);

// with geo results
$result = $googleVision
    ->includeGeoResult()
    ->web($imagePath);

检测pdf

您可以检测pdf并将其存储在Google Cloud Storage上的Json中。默认目标设置为gs://your-bucket/results

use Pkboom\GoogleVision\GoogleVisionFactory;

$path = 'gs://your-bucket/file.pdf';
$output = 'gs://your-bucket/any/';

$googleVision = GoogleVisionFactory::create();

$googleStorage->pdf($path, $output);

// with destination
$googleStorage
    ->to($output)
    ->pdf($path, $output);