Getting ImageAnalysisResultDetails in Azure AI Vision Python SDK

Getting ImageAnalysisResultDetails in Azure AI Vision Python SDK.

Sometimes when using Azure AI Python SDK you will not get the expected result, meaning that the reason property of the result of the analyze method of the ImageAnalyzer class the property will not be equal to sdk.ImageAnalysisResultReason.ANALYZED.

Phew, that’s a mouthful, easier to show it code:

...
image_analyzer = sdk.ImageAnalyzer(cv_client, image, analysis_options)

result = image_analyzer.analyze()
    
if result.reason == sdk.ImageAnalysisResultReason.ANALYZED:
...

The condition in the last line will not be true.

So you would like to actually see what was it

print(f'ResultReason = {result.reason}')

That will give us the reason

Well that’s not too useful, is it?

Let’s get the actual error behind the reason

result_details = sdk.ImageAnalysisResultDetails.from_result(result)
print(f'Result Details = {result_details.json_result}')

And voila: No free soup Analyze Operation under Computer Vision API for you.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.