a
This commit is contained in:
parent
4a238b4973
commit
8d48a1d12d
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
use Aws\Rekognition\RekognitionClient;
|
||||
$arrgs = [
|
||||
'credentials' => [
|
||||
/*
|
||||
'key' => 'AKIARKWWQN5L3CY26JXS',
|
||||
'secret' => 'Mo613SKHaBKSH+IMPoMObafFiavN7kRqgp56gePX',
|
||||
*/
|
||||
/*
|
||||
'key' => 'AKIARKWWQN5LZYQYF5HJ',
|
||||
'secret' => '8dI1CAe+/vMsOJXs11Gv+nSQGMZiRCr0nIeEFS1H',
|
||||
*/
|
||||
// en attente de réactivation => 24/09/2025
|
||||
'key' => 'AKIARKWWQN5LVQZROBMS',
|
||||
'secret' => 'zsyhfvWMlckAFSbDOjB8P51+sxx5HGmpSWnv9mS8',
|
||||
// Compte de radiant en attendant => 24/09/2025
|
||||
'key' => 'AKIA2O2PTXQ7XN5OATO3',
|
||||
'secret' => 'Rzq5mKG80tqfePQYF6iFZ5AMCM/bY2l6i5IxxLzL',
|
||||
],
|
||||
'version' => 'latest',
|
||||
'region' => 'us-west-2'
|
||||
];
|
||||
|
||||
$client = new RekognitionClient($arrgs);
|
||||
|
||||
/*
|
||||
regions
|
||||
us-east-2
|
||||
us-east-1
|
||||
us-west-1
|
||||
us-west-2
|
||||
af-south-1
|
||||
ap-east-1
|
||||
ap-south-2
|
||||
ap-southeast-3
|
||||
ap-southeast-4
|
||||
ap-south-1
|
||||
ap-northeast-3
|
||||
ap-northeast-2
|
||||
ap-southeast-1
|
||||
ap-southeast-2
|
||||
ap-northeast-1
|
||||
ca-central-1
|
||||
eu-central-1
|
||||
eu-west-1
|
||||
eu-west-2
|
||||
eu-south-1
|
||||
eu-west-3
|
||||
eu-south-2
|
||||
eu-north-1
|
||||
eu-central-2
|
||||
me-south-1
|
||||
me-central-1
|
||||
sa-east-1
|
||||
us-gov-east-1
|
||||
us-gov-west-1
|
||||
*/
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
ob_start();
|
||||
require_once "Assure.php";
|
||||
require_once 'Faceebene.php';
|
||||
session_start();
|
||||
header('Content-Type: application/json');
|
||||
|
||||
|
|
@ -72,121 +71,8 @@ class FacialVerificationAPI {
|
|||
);
|
||||
exit;
|
||||
|
||||
// Option 1: Azure Face API (Recommandé)
|
||||
// return $this->compareWithAzureFaceAPI($referenceImagePath, $capturedImageBase64);
|
||||
|
||||
// Option 2: AWS Rekognition
|
||||
return $this->compareWithAWSRekognition($referenceImagePath, $capturedImageBase64);
|
||||
|
||||
// Option 3: Solution locale avec OpenCV/dlib (avancé)
|
||||
// return $this->compareWithLocalFaceRecognition($referenceImagePath, $capturedImageBase64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparaison avec Azure Face API
|
||||
*/
|
||||
private function compareWithAzureFaceAPI($referenceImagePath, $capturedImageBase64) {
|
||||
$endpoint = AZURE_FACE_ENDPOINT;
|
||||
$apiKey = AZURE_FACE_API_KEY;
|
||||
|
||||
try {
|
||||
// 1. Détecter le visage dans l'image de référence
|
||||
$referenceImageData = base64_encode(file_get_contents($referenceImagePath));
|
||||
$referenceFaceId = $this->detectFaceAzure($referenceImageData, $endpoint, $apiKey);
|
||||
|
||||
if (!$referenceFaceId) {
|
||||
return [
|
||||
'match' => false,
|
||||
'confidence' => 0,
|
||||
'error' => 'Aucun visage détecté dans la photo de référence'
|
||||
];
|
||||
}
|
||||
|
||||
// 2. Détecter le visage dans l'image capturée
|
||||
$capturedImageData = explode(',', $capturedImageBase64)[1];
|
||||
$capturedFaceId = $this->detectFaceAzure($capturedImageData, $endpoint, $apiKey);
|
||||
|
||||
if (!$capturedFaceId) {
|
||||
return [
|
||||
'match' => false,
|
||||
'confidence' => 0,
|
||||
'error' => 'Aucun visage détecté dans votre photo'
|
||||
];
|
||||
}
|
||||
|
||||
// 3. Comparer les deux visages
|
||||
$verifyUrl = $endpoint . '/face/v1.0/verify';
|
||||
|
||||
$data = [
|
||||
'faceId1' => $referenceFaceId,
|
||||
'faceId2' => $capturedFaceId
|
||||
];
|
||||
|
||||
$ch = curl_init($verifyUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json',
|
||||
'Ocp-Apim-Subscription-Key: ' . $apiKey
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode !== 200) {
|
||||
throw new Exception("Azure API error: " . $response);
|
||||
}
|
||||
|
||||
$result = json_decode($response, true);
|
||||
|
||||
return [
|
||||
'match' => $result['isIdentical'],
|
||||
'confidence' => round($result['confidence'] * 100, 2),
|
||||
'error' => null
|
||||
];
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Erreur Azure Face API: " . $e->getMessage());
|
||||
return [
|
||||
'match' => false,
|
||||
'confidence' => 0,
|
||||
'error' => 'Erreur lors de la vérification faciale'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Détecte un visage avec Azure Face API et retourne le faceId
|
||||
*/
|
||||
private function detectFaceAzure($imageBase64, $endpoint, $apiKey) {
|
||||
$detectUrl = $endpoint . '/face/v1.0/detect?returnFaceId=true';
|
||||
|
||||
$ch = curl_init($detectUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, base64_decode($imageBase64));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/octet-stream',
|
||||
'Ocp-Apim-Subscription-Key: ' . $apiKey
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode !== 200) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$faces = json_decode($response, true);
|
||||
|
||||
if (empty($faces)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $faces[0]['faceId'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -213,7 +99,22 @@ class FacialVerificationAPI {
|
|||
'TargetImage' => ['Bytes' => $capturedImageData],
|
||||
'SimilarityThreshold' => 80
|
||||
]);
|
||||
|
||||
|
||||
/*
|
||||
$result = $client->compareFaces
|
||||
(
|
||||
[
|
||||
'SimilarityThreshold' => 80,
|
||||
'SourceImage' => [
|
||||
'Bytes' => file_get_contents($sourceImage)
|
||||
],
|
||||
'TargetImage' => [
|
||||
//'Bytes' => file_get_contents($targetImage)
|
||||
'Bytes' => base64_decode($targetImage)
|
||||
],
|
||||
]
|
||||
);
|
||||
*/
|
||||
if (empty($result['FaceMatches'])) {
|
||||
return [
|
||||
'match' => false,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user