Get Area of Interest of image using Azure Cognitive Service

Vedant Modi 26 Reputation points
2021-08-18T09:33:16.03+00:00

I need to extract the area of interest for images - https://learn.microsoft.com/en-in/azure/cognitive-services/computer-vision/concept-generating-thumbnails#area-of-interest.

I am using python 3.x and wish to upload an image in stream or as a URL. I don't see how to implement this among the guides given on this page - https://learn.microsoft.com/en-in/azure/cognitive-services/computer-vision/quickstarts-sdk/image-analysis-client-library?tabs=visual-studio&pivots=programming-language-python.

computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))  
remote_image_url = "https://static.hub.91mobiles.com/wp-content/uploads/2020/06/xiaomi-retail-store-et.jpg"  
  
aoi = computervision_client.get_area_of_interest(remote_image_url)  
print(aoi)  

I ran the above code and get the following output:

{'additional_properties': {}, 'area_of_interest': <azure.cognitiveservices.vision.computervision.models._models_py3.BoundingRect object at 0x000001A997A41CA0>, 'request_id': 'dd0d418a-223c-43b7-bc44-e04aafceadb1', 'metadata': <azure.cognitiveservices.vision.computervision.models._models_py3.ImageMetadata object at 0x000001A997A7EA90>, 'model_version': '2021-04-01'}  

How do I go about extracting meaningful data from this? The output mentions - BoundingRect object at 0x000001A997A41CA0 - can this give me the cordinates?

Azure Computer Vision
Azure Computer Vision
An Azure artificial intelligence service that analyzes content in images and video.
381 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,921 questions
0 comments No comments
{count} vote

Accepted answer
  1. romungi-MSFT 46,986 Reputation points Microsoft Employee
    2021-08-18T10:47:19.217+00:00

    @Vedant Modi The area_of_interest variable contains the co-ordinates the API returned in your image. You can use this co-ordinates to crop the image or create a bounding box using a package like OpenCV.

    In your code snippet if you print the details, you should see the co-ordinates for AOI and other metadata of image.

    print(aoi.area_of_interest)  
    print(aoi.request_id)  
    print(aoi.metadata)  
    

    In this case something like this is printed.

    {'additional_properties': {}, 'x': 146, 'y': 0, 'w': 450, 'h': 450}  
    49499382-63fc-465f-9d46-f21c6148c188  
    {'additional_properties': {}, 'width': 600, 'height': 450, 'format': 'Jpeg'}  
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.