kwn/recognizeim

Recognize.im PHP 客户端。支持图像识别,包括 REST 和 SOAP API

1.0.2 2015-01-12 01:28 UTC

This package is auto-updated.

Last update: 2024-09-14 18:04:05 UTC


README

Code Climate

Recognize.im 提供图像识别 API。使用前,您需要访问 http://www.recognize.im/ 并创建一个账户。登录后,进入用户资料部分,获取:您的客户端 ID您的 API 密钥您的 CLAPI 密钥

安装

将包添加到您的 composer.json 文件中

"kwn/recognizeim": "~1.0"

运行更新命令

php composer.phar update kwn/recognizeim

完成。现在您可以使用 RecognizeIm 类。

用法

use RecognizeIm\Client\RestApi;
use RecognizeIm\Client\SoapApi;
use RecognizeIm\Configuration;
use RecognizeIm\Model\Image;
use RecognizeIm\RecognizeImApi;

// [...]

// create a configuration object first
$configuration = new Configuration('CLIENT_ID', 'API_KEY', 'CLAPI_KEY');

// depending on your needs you can use soap or rest api 
$soapApi = new SoapApi($configuration);
$restApi = new RestApi($configuration, new ImageVerificator());

// or you can create an object that includes both apis (useful for dependency injection containers)
$recognizeim = new RecognizeImApi($soapApi, $restApi);

// now you can use soap api functions or rest api recognize method

// create an image and call recognize method 
$image = new Image('/home/kwn/Pictures/red.jpg');
$result = $recognizeim->getRestApiClient()->recognize($image, 'multi');

授权

您不需要自己调用 auth 方法。当需要时,模块对象会为您授权,您只需提供有效的凭证。您可以从您的 账户选项卡 获取它们。