1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Meema\MediaRecognition\Recognizers; |
4
|
|
|
|
5
|
|
|
use Aws\Credentials\Credentials; |
6
|
|
|
use Aws\Rekognition\RekognitionClient; |
7
|
|
|
use Illuminate\Support\Facades\Storage; |
8
|
|
|
use Meema\MediaRecognition\Contracts\MediaRecognition; |
9
|
|
|
use Meema\MediaRecognition\Traits\InteractsWithStorage; |
10
|
|
|
|
11
|
|
|
class Rekognition implements MediaRecognition |
12
|
|
|
{ |
13
|
|
|
use InteractsWithStorage; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Client instance of MediaRecognition. |
17
|
|
|
* |
18
|
|
|
* @var \Aws\Rekognition\RekognitionClient |
19
|
|
|
*/ |
20
|
|
|
protected RekognitionClient $client; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Construct converter. |
24
|
|
|
* |
25
|
|
|
* @param \Aws\Rekognition\RekognitionClient $client |
26
|
|
|
*/ |
27
|
|
|
public function __construct(RekognitionClient $client) |
28
|
|
|
{ |
29
|
|
|
$this->client = $client; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get the MediaRecognition Client. |
34
|
|
|
* |
35
|
|
|
* @return \Aws\Rekognition\RekognitionClient |
36
|
|
|
*/ |
37
|
|
|
public function getClient(): RekognitionClient |
38
|
|
|
{ |
39
|
|
|
return $this->client; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Detects labels/objects in an image. |
44
|
|
|
*/ |
45
|
|
|
public function detectFaces() |
46
|
|
|
{ |
47
|
|
|
return $this->client->detectLabels([ |
48
|
|
|
'Image' => [ |
49
|
|
|
'S3Object' => [ |
50
|
|
|
'Bucket' => 'meema-stage', |
51
|
|
|
'Name' => 'test-media/people.jpg', |
52
|
|
|
], |
53
|
|
|
], |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Detects faces in an image. |
59
|
|
|
*/ |
60
|
|
|
public function detectFaces() |
61
|
|
|
{ |
62
|
|
|
//if ($this->path && $this->disk) { |
63
|
|
|
// Storage::disk($this->disk)->path($this->path); |
64
|
|
|
//} |
65
|
|
|
|
66
|
|
|
return $this->client->detectFaces(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Detects text in an image (OCR). |
71
|
|
|
*/ |
72
|
|
|
public function detectText($minConfidence = 50) |
73
|
|
|
{ |
74
|
|
|
$bytes = ''; |
75
|
|
|
|
76
|
|
|
$results = $this->client->detectText([ |
|
|
|
|
77
|
|
|
'Image' => ['Bytes' => $bytes], |
78
|
|
|
'MinConfidence' => $minConfidence, |
79
|
|
|
])['TextDetections']; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|