question

VedantModi-4587 avatar image
0 Votes"
VedantModi-4587 asked ramr-msft answered

Passing PIL cropped image as stream in Azure Computer Vision

I need to pass a cropped image to the Computer Vision client in Azure, either as a stream or a url. I'm using PIL to crop the image based on some bounding box values. img1 stores the cropped image

 img1 = img.crop((bbox[i][0], bbox[i][1], bbox[i][4], bbox[i][5]))
 img1.show()
 with open(img1.name, 'rb') as bg_image1:
      colour_analysis = computervision_client.analyze_image_in_stream(bg_image1, remote_image_features)

OR

 img1 = img.crop((bbox[i][0], bbox[i][1], bbox[i][4], bbox[i][5]))
 img1.show()
 open_image = open(img1.name, "rb")
 colour_analysis = computervision_client.analyze_image_in_stream(open_image, remote_image_features)

When I run the code above I get the error: raise AttributeError(name) AttributeError: name

Previously, when i uploaded the image from my files, I used this code which worked well:

 with open('filepath\filename.jpg', 'rb') as bg_image:
     colour_analysis = computervision_client.analyze_image_in_stream(bg_image, remote_image_features)

How do I pass the cropped image to the Azure Client?


azure-computer-vision
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ramr-msft avatar image
0 Votes"
ramr-msft answered

@VedantModi-4587 Thanks for the question. Can you please share the image that you are trying and SDK version that you are trying.

Please follow the below github sample to analyze a local image. See the ComputerVisionClient methods, such as AnalyzeImageInStreamAsync.

https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/dotnet/ComputerVision/ImageAnalysisQuickstart.cs#L306

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@@VedantModi-4587 Please follow this example that will generate a thumbnail image with specified width/height (pixels) and the thumbnail will be saved locally.


0 Votes 0 ·