Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'vendor/autoload.php';
- use GuzzleHttp\Client;
- // Configuración de Azure Face API
- define('AZURE_FACE_ENDPOINT', 'https://<tu-endpoint>.cognitiveservices.azure.com/face/v1.0');
- define('AZURE_FACE_KEY', '<tu-clave-de-api>');
- // Función para obtener el vector facial
- function extractFaceVector($imagePath) {
- $client = new Client();
- $url = AZURE_FACE_ENDPOINT . '/detect';
- try {
- // Leer la imagen
- $imageData = file_get_contents($imagePath);
- // Enviar la imagen a Azure Face API
- $response = $client->post($url, [
- 'headers' => [
- 'Ocp-Apim-Subscription-Key' => AZURE_FACE_KEY,
- 'Content-Type' => 'application/octet-stream'
- ],
- 'body' => $imageData,
- 'query' => [
- 'returnFaceId' => 'false',
- 'returnFaceLandmarks' => 'true',
- 'returnFaceAttributes' => 'age,gender,smile,facialHair'
- ]
- ]);
- // Decodificar la respuesta
- $result = json_decode($response->getBody(), true);
- if (!empty($result)) {
- return $result[0]; // Devuelve el vector del primer rostro detectado
- } else {
- throw new Exception('No se detectó ningún rostro en la imagen.');
- }
- } catch (Exception $e) {
- throw new Exception('Error al procesar la imagen: ' . $e->getMessage());
- }
- }
- // Ejemplo de uso
- try {
- $faceVector = extractFaceVector('ruta/a/tu/imagen.jpg');
- echo "Vector facial: " . json_encode($faceVector);
- } catch (Exception $e) {
- echo "Error: " . $e->getMessage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement