From 6a575a4d89c380a161bab69ca5a0141e7b64db53 Mon Sep 17 00:00:00 2001 From: Pablo Gabarro Date: Wed, 19 Jun 2024 11:51:38 -0300 Subject: [PATCH] Add anti_spoofing to represent function --- scripts/represent.py | 1 + src/DeepFace.php | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/scripts/represent.py b/scripts/represent.py index 06fa8a7..a7c675f 100644 --- a/scripts/represent.py +++ b/scripts/represent.py @@ -5,6 +5,7 @@ img_path = "{{img_path}}", model_name = "{{model_name}}", enforce_detection = {{enforce_detection}}, + anti_spoofing = "{{anti_spoofing}}", detector_backend = "{{detector_backend}}", align = {{align}}, normalization = "{{normalization}}" diff --git a/src/DeepFace.php b/src/DeepFace.php index 886527b..5bb2b4e 100644 --- a/src/DeepFace.php +++ b/src/DeepFace.php @@ -289,6 +289,7 @@ public function represent( Detector $detector_backend = Detector::OPENCV, bool $align = true, Normalization $normalization = Normalization::BASE, + bool $anti_spoofing = false, ): array { $img = new SplFileInfo($img_path); @@ -296,17 +297,22 @@ public function represent( throw new InvalidArgumentException("The path [{$img_path}] for image is not a file."); } - $output = $this->run( - filepath: __DIR__.'/../scripts/represent.py', - data: [ - '{{img_path}}' => str_replace('\\', '/', $img->getRealPath()), - '{{model_name}}' => $model_name->value, - '{{enforce_detection}}' => $enforce_detection ? 'True' : 'False', - '{{detector_backend}}' => $detector_backend->value, - '{{align}}' => $align ? 'True' : 'False', - '{{normalization}}' => $normalization->value, - ], - ); + try{ + $output = $this->run( + filepath: __DIR__.'/../scripts/represent.py', + data: [ + '{{img_path}}' => str_replace('\\', '/', $img->getRealPath()), + '{{model_name}}' => $model_name->value, + '{{enforce_detection}}' => $enforce_detection ? 'True' : 'False', + '{{anti_spoofing}}' => $anti_spoofing ? 'True' : 'False', + '{{detector_backend}}' => $detector_backend->value, + '{{align}}' => $align ? 'True' : 'False', + '{{normalization}}' => $normalization->value, + ], + ); + } catch(DeepFaceException $e){ + return array("error" => $e->getMessage()); + } return array_map( fn (array $result) => new RepresentResult(