Open dturneresq opened 3 years ago
import boto3
def detect_labels(photo, bucket):
client=boto3.client('rekognition') response = client.detect_labels(Image={'S3Object':{'Bucket':bucket,'Name':photo}}, MaxLabels=10) print('Detected labels for ' + photo) print() for label in response['Labels']: print ("Label: " + label['Name']) print ("Confidence: " + str(label['Confidence'])) print ("Instances:") for instance in label['Instances']: print (" Bounding box") print (" Top: " + str(instance['BoundingBox']['Top'])) print (" Left: " + str(instance['BoundingBox']['Left'])) print (" Width: " + str(instance['BoundingBox']['Width'])) print (" Height: " + str(instance['BoundingBox']['Height'])) print (" Confidence: " + str(instance['Confidence'])) print() print ("Parents:") for parent in label['Parents']: print (" " + parent['Name']) print ("----------") print () return len(response['Labels'])
def main(): photo='' bucket='' label_count=detect_labels(photo, bucket) print("Labels detected: " + str(label_count))
if name == "main": main()
https://docs.aws.amazon.com/rekognition/latest/dg/images-s3.html
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
import boto3
def detect_labels(photo, bucket):
def main(): photo='' bucket='' label_count=detect_labels(photo, bucket) print("Labels detected: " + str(label_count))
if name == "main": main()