Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'vendor/autoload.php';
- use Aws\Rekognition\RekognitionClient;
- // Configuración de AWS Rekognition
- define('AWS_REGION', 'us-east-1'); // Cambia a tu región
- define('AWS_KEY', '<tu-access-key>');
- define('AWS_SECRET', '<tu-secret-key>');
- // Crear el cliente de AWS Rekognition
- function getRekognitionClient() {
- return new RekognitionClient([
- 'region' => AWS_REGION,
- 'version' => 'latest',
- 'credentials' => [
- 'key' => AWS_KEY,
- 'secret' => AWS_SECRET,
- ],
- ]);
- }
- // Detectar el rostro y extraer el vector facial
- function extractFaceVector($imagePath) {
- $rekognition = getRekognitionClient();
- try {
- // Leer la imagen
- $imageData = file_get_contents($imagePath);
- // Enviar la imagen a AWS Rekognition
- $result = $rekognition->detectFaces([
- 'Image' => ['Bytes' => $imageData],
- 'Attributes' => ['ALL'] // Devuelve landmarks y otros atributos
- ]);
- if (!empty($result['FaceDetails'])) {
- return $result['FaceDetails'][0]; // Devuelve los detalles 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