Skip to content

Commit

Permalink
Add anti_spoofing to represent function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Gabarro committed Jun 19, 2024
1 parent 38b80a6 commit 6a575a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions scripts/represent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
Expand Down
28 changes: 17 additions & 11 deletions src/DeepFace.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,24 +289,30 @@ 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);

if (! $img->isFile()) {
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(
Expand Down

0 comments on commit 6a575a4

Please sign in to comment.