subsan / microsoft-cognitive-face-php-api-client
Microsoft Cognitive Services 中 Face 模块的 PHP 客户端
v1.0.1
2018-08-31 14:05 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ~6.0
This package is auto-updated.
Last update: 2024-09-15 17:16:56 UTC
README
基于云端的 Face API 为开发者提供了访问高级人脸算法的权限。Microsoft Face 算法可以实现人脸属性检测和人脸识别
要求
安装
您可以使用 Composer 或直接 下载发行版
Composer
首选方法是使用 composer。如果您尚未安装 composer,请遵循安装说明。
安装 composer 后,在您的项目根目录下执行以下命令以安装此库
composer require subsan/microsoft-cognitive-face-php-api-client
最后,请确保包含自动加载器
require_once '/path/to/your-project/vendor/autoload.php';
下载发行版
如果您不喜欢使用 composer,您可以下载整个包。在发行版页面列出了所有稳定版本。下载任何名为 microsoft-cognitive-face-php-api-client-[RELEASE_NAME].zip
的文件,该文件包含此库及其依赖项。
解压缩您下载的 zip 文件,并在您的项目中包含自动加载器
require_once '/path/to/microsoft-cognitive-face-php-api-client/vendor/autoload.php';
示例
基本示例
// include your composer dependencies require_once 'vendor/autoload.php'; $client = new \Subsan\MicrosoftCognitiveFace\Client('YOUR_APP_KEY', 'YOUR_REGION'); $faces = $client->face()->detectFacesFromImg('URL_IMAGE_WITH_FACES'); var_dump($faces);
创建人员组并为图像中的所有面孔添加新人员
require_once 'vendor/autoload.php'; $client = new \Subsan\MicrosoftCognitiveFace\Client('YOUR_APP_KEY', 'YOUR_REGION'); // create new person group $newPersonGroupId = uniqid(); $client->personGroup($newPersonGroupId)->create( new \Subsan\MicrosoftCognitiveFace\Entity\PersonGroup( null, 'Group Name', 'Additional info' ) ); // get faces from image $url = 'URL_IMAGE_WITH_FACES'; $faces = $client->face()->detectFacesFromImg($url); $userNumber = 1; foreach ($faces as $face) { $personFaceRectangle = (new \Subsan\MicrosoftCognitiveFace\Entity\FaceRectangle())->import($face->faceRectangle); // create person $person = $client->personGroup($newPersonGroupId)->person()->create( new \Subsan\MicrosoftCognitiveFace\Entity\Person( null, 'User '.$userNumber ) ); // add image to person $client->personGroup($newPersonGroupId)->person($person->getPersonId())->addFace($url,'test',$personFaceRectangle); $userNumber++; }
训练人员组
require_once 'vendor/autoload.php'; $client = new \Subsan\MicrosoftCognitiveFace\Client('YOUR_APP_KEY', 'YOUR_REGION'); // in previous example $newPersonGroupId $personGroupId = 'ID_OF_CREATED_PERSON_GROUP'; // train group $client->personGroup()->train($personGroupId); // get train status var_dump($client->personGroup()->getTrainStatus($personGroupId));
识别图像中的所有面孔
require_once 'vendor/autoload.php'; $client = new \Subsan\MicrosoftCognitiveFace\Client('YOUR_APP_KEY', 'YOUR_REGION'); // in previous example $newPersonGroupId $personGroupId = 'ID_OF_CREATED_PERSON_GROUP'; // get faces from image $url = 'URL_IMAGE_WITH_FACES'; $faces = $client->face()->detectFacesFromImg($url); // prepare array of faces ids $faceIds = array(); foreach ($faces as $face) { $faceIds[] = $face->faceId; } // identify all faces print_r($client->face()->identify($faceIds, $personGroupId));