'How to return image with bounding box using AWS Rekognition?

When I upload image to s3 bucket and call AWS Rekognition detect_labels I am getting dictionary of detected labels like below

{'Labels': [{'Name': 'Plant', 'Confidence': 99.70314025878906, 'Instances': [], 'Parents': []}, {'Name': 'Flower', 'Confidence': 98.37027740478516, 'Instances': [], 'Parents': [{'Name': 'Plant'}]}

but here I need to return the image with bounding box where the object is identified, how this can be achieved ?



Solution 1:[1]

From DetectLabels API documentation:

DetectLabels returns bounding boxes for instances of common object labels in an array of Instance objects. An Instance object contains a BoundingBox object, for the location of the label on the image. It also includes the confidence by which the bounding box was detected.

This is elaborated more in Detecting labels documentation

Amazon Rekognition Image and Amazon Rekognition Video can return the bounding box for common object labels such as cars, furniture, apparel or pets. Bounding box information isn't returned for less common object labels. You can use bounding boxes to find the exact locations of objects in an image, count instances of detected objects, or to measure an object's size using bounding box dimensions.

In short, bounding box information isn't returned for all labels. @Allan Chua's code will draw bounding boxes in the image only if the label is a 'common object' which has bounding box information. In the sample API response you provided, none of the labels have bounding box information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kaustubh Khavnekar