-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: detectLabels functionality is added
- Loading branch information
1 parent
4e383f4
commit a4187d3
Showing
29 changed files
with
1,552 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,37 @@ | ||
<?php | ||
|
||
return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| AWS credentials | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may specify the credentials for AWS used to sign requests. | ||
| See https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.AwsClient.html#method___construct for more information. | ||
| | ||
*/ | ||
'credentials' => [ | ||
'key' => env('AWS_ACCESS_KEY_ID'), | ||
'secret' => env('AWS_SECRET_ACCESS_KEY'), | ||
], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| AWS region | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may specify the region to connect to. | ||
| See https://docs.aws.amazon.com/general/latest/gr/rande.html for a list of available regions. | ||
*/ | ||
'region' => env('AWS_REGION', 'us-east-1'), | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| AWS version of the webservice to utilize (e.g., 2006-03-01) | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may specify the version of the webservice. | ||
| See https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.AwsClient.html#method___construct for more information. | ||
*/ | ||
'version' => env('AWS_VERSION', 'latest'), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MoeMizrak\Rekognition\Data; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
/** | ||
* DetectLabelsData is for detectLabels method related context data such as image, features, maxLabels, minConfidence and settings. | ||
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#detectlabels | ||
* | ||
* @class DetectLabelsData | ||
*/ | ||
final class DetectLabelsData extends Data | ||
{ | ||
public function __construct( | ||
/* | ||
* The input image as base64-encoded bytes, image resource or an S3 object (Images stored in an S3 Bucket do not need to be base64-encoded). | ||
* | ||
* @param ImageData | ||
*/ | ||
public ImageData $image, | ||
|
||
/* | ||
* A list of the types of analysis to perform. | ||
* Specifying GENERAL_LABELS uses the label detection feature, while specifying IMAGE_PROPERTIES returns information regarding image color and quality. | ||
* default: GENERAL_LABELS | ||
* | ||
* @param array|null | ||
*/ | ||
public ?array $features = null, | ||
|
||
/* | ||
* Maximum number of labels you want the service to return in the response. The service returns the specified number of highest confidence labels. | ||
* Only valid when GENERAL_LABELS is specified as a feature type in the Feature input parameter. | ||
* | ||
* @param int|null | ||
*/ | ||
public ?int $maxLabels = null, | ||
|
||
/* | ||
* Specifies the minimum confidence level for the labels to return. | ||
* Amazon Rekognition doesn't return any labels with confidence lower than this specified value. | ||
* If MinConfidence is not specified, the operation returns labels with a confidence values greater than or equal to 55 percent. | ||
* Only valid when GENERAL_LABELS is specified as a feature type in the Feature input parameter. | ||
* | ||
* @param float|null | ||
*/ | ||
public ?float $minConfidence = null, | ||
|
||
/* | ||
* A list of the filters to be applied to returned detected labels and image properties. | ||
* | ||
* @param SettingsData|null | ||
*/ | ||
public ?SettingsData $settings = null | ||
) {} | ||
|
||
/** | ||
* Convert the data to an AWS Rekognition array format, excluding null values. | ||
* | ||
* @return array | ||
*/ | ||
public function toRekognitionDataFormat(): array | ||
{ | ||
return array_filter( | ||
[ | ||
'Image' => $this->image->toRekognitionDataFormat(), | ||
'Features' => $this->features, | ||
'MaxLabels' => $this->maxLabels, | ||
'MinConfidence' => $this->minConfidence, | ||
'Settings' => $this->settings?->toRekognitionDataFormat(), | ||
], | ||
fn ($value) => $value !== null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MoeMizrak\Rekognition\Data; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
/** | ||
* DetectLabelsImagePropertiesSettingsData is settings for the IMAGE_PROPERTIES feature type. | ||
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#shape-detectlabelsimagepropertiessettings | ||
* | ||
* @class DetectLabelsImagePropertiesSettingsData | ||
*/ | ||
final class DetectLabelsImagePropertiesSettingsData extends Data | ||
{ | ||
public function __construct( | ||
/* | ||
* The maximum number of dominant colors to return when detecting labels in an image. | ||
* The default value is 10. | ||
* | ||
* @param int|null | ||
*/ | ||
public ?int $maxDominantColors = null, | ||
) {} | ||
|
||
/** | ||
* Convert the data to an AWS Rekognition array format. | ||
* | ||
* @return array | ||
*/ | ||
public function toRekognitionDataFormat(): array | ||
{ | ||
return array_filter( | ||
[ | ||
'MaxDominantColors' => $this->maxDominantColors, | ||
], | ||
fn ($value) => $value !== null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MoeMizrak\Rekognition\Data; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
/** | ||
* Contains filters for the object labels returned by DetectLabels. Filters can be inclusive, exclusive, or a combination of both and can be applied to individual labels or entire label categories. | ||
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#shape-generallabelssettings | ||
* To see a list of label categories: https://docs.aws.amazon.com/rekognition/latest/dg/labels.html | ||
* | ||
* @class GeneralLabelsSettingsData | ||
*/ | ||
final class GeneralLabelsSettingsData extends Data | ||
{ | ||
public function __construct( | ||
/* | ||
* The label categories that should be excluded from the return from DetectLabels. | ||
* | ||
* @param array|null | ||
*/ | ||
public ?array $labelCategoryExclusionFilters = null, | ||
|
||
/* | ||
* The label categories that should be included in the return from DetectLabels. | ||
* | ||
* @param array|null | ||
*/ | ||
public ?array $labelCategoryInclusionFilters = null, | ||
|
||
/* | ||
* The labels that should be excluded from the return from DetectLabels. | ||
* | ||
* @param array|null | ||
*/ | ||
public ?array $labelExclusionFilters = null, | ||
|
||
/* | ||
* The labels that should be included in the return from DetectLabels. | ||
* | ||
* @param array|null | ||
*/ | ||
public ?array $labelInclusionFilters = null, | ||
) {} | ||
|
||
/** | ||
* Convert the data to an AWS Rekognition array format. | ||
* | ||
* @return array | ||
*/ | ||
public function toRekognitionDataFormat(): array | ||
{ | ||
return array_filter( | ||
[ | ||
'LabelCategoryExclusionFilters' => $this->labelCategoryExclusionFilters, | ||
'LabelCategoryInclusionFilters' => $this->labelCategoryInclusionFilters, | ||
'LabelExclusionFilters' => $this->labelExclusionFilters, | ||
'LabelInclusionFilters' => $this->labelInclusionFilters, | ||
], | ||
fn ($value) => $value !== null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MoeMizrak\Rekognition\Data; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
/** | ||
* Provides the input image either as bytes or an S3 object. | ||
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#shape-image | ||
* Also check: https://docs.aws.amazon.com/rekognition/latest/dg/images-information.html | ||
* | ||
* @class ImageData | ||
*/ | ||
final class ImageData extends Data | ||
{ | ||
public function __construct( | ||
/* | ||
* Blob of image bytes up to 5 MBs. | ||
* | ||
* @param string|resource|StreamInterface|null | ||
*/ | ||
public mixed $bytes = null, | ||
|
||
/* | ||
* Identifies an S3 object as the image source. | ||
* | ||
* @param S3ObjectData|null | ||
*/ | ||
public ?S3ObjectData $s3Object = null | ||
) {} | ||
|
||
/** | ||
* Convert the data to an AWS Rekognition array format. | ||
* | ||
* @return array | ||
*/ | ||
public function toRekognitionDataFormat(): array | ||
{ | ||
return array_filter( | ||
[ | ||
'Bytes' => $this->bytes, | ||
'S3Object' => $this->s3Object?->toRekognitionDataFormat(), | ||
], | ||
fn ($value) => $value !== null | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MoeMizrak\Rekognition\Data\ResultData; | ||
|
||
use Spatie\LaravelData\Data; | ||
|
||
/** | ||
* A potential alias of for a given label. | ||
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#shape-labelalias | ||
* | ||
* @class LabelData | ||
*/ | ||
final class AliasData extends Data | ||
{ | ||
public function __construct( | ||
/* | ||
* The name of an alias for a given label. | ||
* | ||
* @param string|null | ||
*/ | ||
public ?string $name = null, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MoeMizrak\Rekognition\Data\ResultData; | ||
|
||
use Spatie\LaravelData\Attributes\DataCollectionOf; | ||
use Spatie\LaravelData\Data; | ||
use Spatie\LaravelData\DataCollection; | ||
|
||
/** | ||
* Information about the properties of an image’s background, including the background’s quality and dominant colors, including the quality and dominant colors of the image. | ||
* For more info: https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-rekognition-2016-06-27.html#shape-detectlabelsimagebackground | ||
* | ||
* @class BackgroundData | ||
*/ | ||
final class BackgroundData extends Data | ||
{ | ||
public function __construct( | ||
/* | ||
* A description of the dominant colors in an image. | ||
* | ||
* @param DataCollection|null | ||
*/ | ||
#[DataCollectionOf(DominantColorsData::class)] | ||
public ?DataCollection $dominantColors = null, | ||
|
||
/* | ||
* The quality of the image background as defined by brightness and sharpness. | ||
* | ||
* @param QualityData|null | ||
*/ | ||
public ?QualityData $quality = null, | ||
) {} | ||
} |
Oops, something went wrong.