Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Dec 19, 2024
1 parent b9c6914 commit 392208f
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/Feature/DeepfaceTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
<?php

use Astrotomic\DeepFace\Data\AnalyzeResult;
use Astrotomic\DeepFace\Data\ExtractFaceResult;
use Astrotomic\DeepFace\Data\RepresentResult;
use Astrotomic\DeepFace\Enums\Emotion;
use Astrotomic\DeepFace\Enums\Gender;
use Astrotomic\DeepFace\Enums\Race;
use PHPUnit\Framework\Assert;

describe('verify', function (): void {
it('verify: img1', function (): void {
$img1 = $this->image('img1.jpg');
$img2 = $this->image('img2.jpg');
$result = $this->deepface()->verify($img1, $img2);

Assert::assertTrue($result->verified);
Assert::assertSame($img1, $result->img1_path);
Assert::assertSame(339, $result->img1_facial_area->x);
Assert::assertSame(218, $result->img1_facial_area->y);
Assert::assertSame(768, $result->img1_facial_area->w);
Assert::assertSame(768, $result->img1_facial_area->h);
Assert::assertSame($img2, $result->img2_path);
Assert::assertSame(524, $result->img2_facial_area->x);
Assert::assertSame(201, $result->img2_facial_area->y);
Assert::assertSame(491, $result->img2_facial_area->w);
Assert::assertSame(491, $result->img2_facial_area->h);
});
});

describe('analyze', function (): void {
it('analyzes: img1', function (): void {
$img = $this->image('img1.jpg');
Expand All @@ -26,3 +48,40 @@
Assert::assertSame(Race::LATINO_HISPANIC, $result->dominant_race);
});
});

describe('extractFaces', function (): void {
it('extractFaces: img1', function (): void {
$img = $this->image('img1.jpg');
$results = $this->deepface()->extractFaces($img);

Assert::assertCount(1, $results);
Assert::assertContainsOnlyInstancesOf(ExtractFaceResult::class, $results);

$result = $results[0];

Assert::assertSame($img, $result->img_path);
Assert::assertSame(339, $result->facial_area->x);
Assert::assertSame(218, $result->facial_area->y);
Assert::assertSame(768, $result->facial_area->w);
Assert::assertSame(768, $result->facial_area->h);
});
});

describe('represent', function (): void {
it('represent: img1', function (): void {
$img = $this->image('img1.jpg');
$results = $this->deepface()->represent($img);

Assert::assertCount(1, $results);
Assert::assertContainsOnlyInstancesOf(RepresentResult::class, $results);

$result = $results[0];

Assert::assertSame($img, $result->img_path);
Assert::assertSame(339, $result->facial_area->x);
Assert::assertSame(218, $result->facial_area->y);
Assert::assertSame(768, $result->facial_area->w);
Assert::assertSame(768, $result->facial_area->h);
Assert::assertCount(4096, $result->embedding);
});
});

0 comments on commit 392208f

Please sign in to comment.