coolseven/face-platform-sdk

Face Platform Api Client For Laravel

v1.3.0 2019-09-28 15:36 UTC

This package is auto-updated.

Last update: 2024-04-29 04:20:55 UTC


README

Face Platform Api client for Laravel

Requirement

  • php >= 7.2
  • laravel >= 6.0

Installation

Install package

composer require coolseven/face-platform-sdk

Setup environments

  • add following environments to your .env file
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
  • publish config file ( optional )
php artisan vendor:publish --tag=face-platform-sdk.config

the config file will be copied to your config dir with filename "face-platform-sdk.php"

Manage Resources

  • create a new face set
$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();
  • import faces into a face set
$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();
  • search similar faces in a face set
$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();

Events

  • a Coolseven\FacePlatformSdk\Events\AccessTokenRefreshed Event will be fired after access token been refreshed.
$accessToken = $accessTokenRefreshedEvent->getRefreshedAccessToken();
  • a Coolseven\FacePlatformSdk\Events\FaceSetCreated Event will be fired after a new face set been created.
$faceSetId = $faceSetCreatedEvent->getFaceSet()->getId();
$rawResponse = $faceSetCreatedEvent->getRawResponse();
  • a Coolseven\FacePlatformSdk\Events\FacesImported Event will be fired after new faces been imported
$importedFaces = $facesImportedEvent->getImportedFaces();
$faceSetId = $facesImportedEvent->getFaceSetId();
$imageBase64 = $facesImportedEvent->getImageBase64();
$rawResponse = $facesImportedEvent->getRawResponse();
  • a Coolseven\FacePlatformSdk\Events\SimilarFacesSearched Event will be fired after similar faces been searched
$similarFaces = $similarFacesSearchedEvent->getSimilarFaces();
$faceSetId = $similarFacesSearchedEvent->getFaceSetId();
$imageBase64 = $similarFacesSearchedEvent->getImageBase64();
$rawResponse = $similarFacesSearchedEvent->getRawResponse();