coolseven / face-platform-sdk
Laravel的Face Platform Api客户端
v1.3.0
2019-09-28 15:36 UTC
Requires
- php: ^7.2
- ext-json: *
- guzzlehttp/guzzle: ^6.3
- illuminate/cache: ^6.0
- illuminate/events: ^6.0
- illuminate/support: ^6.0
Requires (Dev)
- orchestra/testbench: ^4.0
- phpunit/phpunit: ^8.3
This package is auto-updated.
Last update: 2024-09-29 05:28:49 UTC
README
Face Platform Api客户端 for Laravel
要求
- php >= 7.2
- laravel >= 6.0
安装
安装包
composer require coolseven/face-platform-sdk
设置环境
- 将以下环境添加到您的 .env 文件中
FACE_PLATFORM_OAUTH_SERVER= FACE_PLATFORM_RESOURCE_SERVER= FACE_PLATFORM_CLIENT_ID= FACE_PLATFORM_CLIENT_SECRET= FACE_PLATFORM_USERNAME= FACE_PLATFORM_PASSWORD= # the cache store should be one of the stores you defined in config/cache.php # will use 'file' as cache store if not set FACE_PLATFORM_CACHE_STORE=file # the cache key to store your face platform access token, # will use 'cache:face-platform:access_token' as cache key if not set FACE_PLATFORM_CACHE_KEY=cache:face-platform:access_token
- 发布配置文件(可选)
php artisan vendor:publish --tag=face-platform-sdk.config
配置文件将被复制到您的配置目录,文件名为 "face-platform-sdk.php"
管理资源
- 创建一个新的脸集
$facePlatformClient = app(Coolseven\FacePlatformSdk\FacePlatformClient::class); // or $facePlatformClient = app('face-platform-client') $faceSetName = 'your-demo-face-set'; $response = $facePlatformClient->createFaceSet($faceSetName); $faceSetId = $response->getFaceSet()->getId(); $statusCode = $response->getRawResponse()->getStatusCode();
- 将人脸导入到脸集中
$facePlatformClient = app(Coolseven\FacePlatformSdk\FacePlatformClient::class); $faceSetId = 'your-demo-face-set-id'; $imagePath = 'your_imgae_file_path'; $response = $facePlatformClient->importFaces($faceSetId, base64_encode(file_get_contents($imagePath))); $importedFaces = $response->getImportedFaces();
- 在脸集中搜索相似的人脸
$facePlatformClient = app(Coolseven\FacePlatformSdk\FacePlatformClient::class); $faceSetId = 'your-demo-face-set-id'; $imagePath = 'your_imgae_file_path'; $similarityThreshold = 0.93; $response = $facePlatformClient->searchSimilarFaces($faceSetId, base64_encode(file_get_contents($imagePath)), $similarityThreshold); $similarFaces = $response->getSimilarFaces();
事件
- 在访问令牌刷新后,将触发一个Coolseven\FacePlatformSdk\Events\AccessTokenRefreshed 事件。
$accessToken = $accessTokenRefreshedEvent->getRefreshedAccessToken();
- 在创建一个新的脸集后,将触发一个Coolseven\FacePlatformSdk\Events\FaceSetCreated 事件。
$faceSetId = $faceSetCreatedEvent->getFaceSet()->getId(); $rawResponse = $faceSetCreatedEvent->getRawResponse();
- 在导入新的人脸后,将触发一个Coolseven\FacePlatformSdk\Events\FacesImported 事件。
$importedFaces = $facesImportedEvent->getImportedFaces(); $faceSetId = $facesImportedEvent->getFaceSetId(); $imageBase64 = $facesImportedEvent->getImageBase64(); $rawResponse = $facesImportedEvent->getRawResponse();
- 在搜索相似的人脸后,将触发一个Coolseven\FacePlatformSdk\Events\SimilarFacesSearched 事件。
$similarFaces = $similarFacesSearchedEvent->getSimilarFaces(); $faceSetId = $similarFacesSearchedEvent->getFaceSetId(); $imageBase64 = $similarFacesSearchedEvent->getImageBase64(); $rawResponse = $similarFacesSearchedEvent->getRawResponse();