a
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user