DrawBoxAroundFaces::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AhmadMayahi\Vision\Detectors\Face;
6
7
use AhmadMayahi\Vision\Contracts\Drawable;
8
use AhmadMayahi\Vision\Detectors\Face;
9
use AhmadMayahi\Vision\Enums\Color;
10
use AhmadMayahi\Vision\Support\Image;
11
12
class DrawBoxAroundFaces implements Drawable
13
{
14
    private int $borderColor = Color::GREEN;
15
16
    public function __construct(private Face $face, private Image $image)
17
    {
18
    }
19
20
    public function borderColor(int $color): static
21
    {
22
        $this->borderColor = $color;
23
24
        return $this;
25
    }
26
27
    public function draw(): Image
28
    {
29
        /** @var \AhmadMayahi\Vision\Data\Face $face */
30
        foreach ($this->face->detect() as $face) {
31
            $vertices = $face->bounds;
32
33
            if (0 !== count($vertices)) {
34
                $x1 = $vertices[0]->x;
35
                $y1 = $vertices[0]->y;
36
37
                $x2 = $vertices[2]->x;
38
                $y2 = $vertices[2]->y;
39
40
                $this->image->drawRectangle($x1, $y1, $x2, $y2, $this->borderColor);
41
            }
42
        }
43
44
        return $this->image;
45
    }
46
}
47