Skip to content

Conversation

@mikejoseph
Copy link

This PR adds support for detection via S3 buckets and the ability to change the detection mode.

detectFromUrl automatically looks for s3.amazonaws.com in URLs and switches from binary to S3 mode.

Also adds the following constants:

  • Service/DetectService::DETECT_BOTH
  • Service/DetectService::DETECT_LABEL
  • Service/DetectService::DETECT_TEXT

and the following method

  • setDetectMode

That allows you to limit it to text, labels or both (default).

support for reading directly from S3 buckets
@aloupfor
Copy link
Contributor

Hello,

Thank you for your contribution.

I tried to run :

<?php

use ClickAndMortar\Rekognition\Service\DetectService;

require 'vendor/autoload.php';

$detectService = new DetectService();

$url = 'https://marketing-image-production.s3.amazonaws.com/uploads/3629f54390ead663d4eb7c53702e492de63299d7c5f7239efdc693b09b9b28c82c924225dcd8dcb65732d5ca7b7b753c5f17e056405bbd4596e4e63a96ae5018.png';
$rekognitionImage = $detectService->detectFromUrl($url);
$minimumConfidence = 80;

print 'Labels:' . PHP_EOL;
foreach ($rekognitionImage->getLabels($minimumConfidence) as $label) {
    print $label;
}

print 'Texts:' . PHP_EOL;
foreach ($rekognitionImage->getTexts($minimumConfidence) as $text) {
    print $text;
}

So I am using a random URL found on internet from an S3 bucket:
https://marketing-image-production.s3.amazonaws.com/uploads/3629f54390ead663d4eb7c53702e492de63299d7c5f7239efdc693b09b9b28c82c924225dcd8dcb65732d5ca7b7b753c5f17e056405bbd4596e4e63a96ae5018.png

With master, I have :

php main.php
Labels:
Name: Clothing
Confidence: 99.954521179199

Name: Apparel
Confidence: 99.954521179199

Name: Shoe
Confidence: 97.765533447266
Parent Name: Footwear
Parent Name: Clothing

Name: Footwear
Confidence: 97.765533447266
Parent Name: Clothing

Name: Sneaker
Confidence: 92.196495056152
Parent Name: Shoe
Parent Name: Footwear
Parent Name: Clothing

Name: Human
Confidence: 85.206130981445

Name: Person
Confidence: 85.206130981445

Texts:

With thesnews:use-s3-urls, I have :

php main.php

Fatal error: Uncaught exception 'Aws\Rekognition\Exception\RekognitionException' with message 'Error executing "DetectLabels" on "https://rekognition.us-west-2.amazonaws.com"; AWS HTTP error: Client error: `POST https://rekognition.us-west-2.amazonaws.com` resulted in a `400 Bad Request` response:
{"__type":"InvalidS3ObjectException","Code":"InvalidS3ObjectException","Message":"Unable to get object metadata from S3. (truncated...)
 InvalidS3ObjectException (client): Unable to get object metadata from S3. Check object key, region and/or access permissions. - {"__type":"InvalidS3ObjectException","Code":"InvalidS3ObjectException","Message":"Unable to get object metadata from S3. Check object key, region and/or access permissions."}'

GuzzleHttp\Exception\ClientException: Client error: `POST https://rekognition.us-west-2.amazonaws.com` resulted in a `400 Bad Request` response:
{"__type":"InvalidS3ObjectException","Code":"InvalidS3ObjectException","Message":"Unable to get object metadata from S3. (truncated...)
 in /app/vendor in /app/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 191

Do you know why this is happening and what can be done to avoid this exception ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants