question

TarunGupta-1679 avatar image
0 Votes"
TarunGupta-1679 asked romungi-MSFT commented

Request body format for image tagging using computer vision api

We have a requirement to get image tags from image.

I am using this API - https://docs.microsoft.com/en-us/rest/api/computervision/3.1/tag-image-in-stream/tag-image-in-stream

I am unclear about the image format that needs to be provided in Request Body of the api, as most of the times, I use to get InvalidImageFormat error.
I am using this code.

 HttpClient client = new HttpClient();
 client.BaseAddress = new Uri("https://{test}/vision/v3.1/tag?overload=stream");
 client.DefaultRequestHeaders.Add("Accept", "application/octet-stream");
 client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{apiSubscriptionKey}");
    
 var url = "https://wallpapercave.com/wp/Iw471VJ.jpg";
    
 HttpClient client2 = new HttpClient();
 var getStream = client2.GetByteArrayAsync(url);
 getStream.Wait();
 var imgByteArr = getStream.Result;
    
 string binaryString = string.Join("", imgByteArr.Select(byt => Convert.ToString(byt, 2).PadLeft(8, '0')));
 var postTask = client.PostAsJsonAsync<string>(URL, binaryString);
 postTask.Wait();
    
 var result = postTask.Result;

Please help me with this.

Thanks.

azure-computer-vision
· 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.

@TarunGupta-1679 Did you get a chance to try the below recommendation and use the URI of the image instead of local image?

0 Votes 0 ·
romungi-MSFT avatar image
0 Votes"
romungi-MSFT answered romungi-MSFT commented

@TarunGupta-1679 The sample to use the REST API with C# is available here. You just need to update the uriBase to point to /vision/3.1/tag and use a local image to get the result.

If you already have the image as a URL then you can directly call the API by passing the image URI with the TagImage API.
You can also use any supported SDK client to analyze the image.


If an answer is helpful, please click on 130616-image.png or upvote 130671-image.png which might help other community members reading this thread.


· 7
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.

Do we have specific limitations with image size(resolution in pixels) as well? If yes, what are the values?

I got this as for a particular image I got the response as "Image size too large", and by reducing the size of same image I got the tags.

Please help me with this as well.

Thanks.

0 Votes 0 ·

@TarunGupta-1679 Yes there is a limit for the image size.

The file size limit for most Computer Vision features is 4MB, but the client library SDKs can handle files up to 6MB. For Optical Character Recognition (OCR) that handles multi-page documents, the maximum file size is 50 MB.

You can refer the FAQ from the documentation for more details about the service.


1 Vote 1 ·

Hi,

How to pass region specific information to cognitive service? To reduce latency in api response time.

Please help.
Thanks.

0 Votes 0 ·

Passing the region name can be done with the header Ocp-Apim-Region but in this case it would not help with the latency. You could try using containers for computer vision?


0 Votes 0 ·

Our requirement is like, we would be deploying our service in multiple regions in azure cloud and will be querying to cognitive service from multiple deployment regions, from here "https://docs.microsoft.com/en-us/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows"

we came to know that querying to cognitive service from a different region can increase the response time and we want to reduce that, can that be done by passing region parameter in any form?

or we have to use multiple regions subscription keys?

Please suggest.

0 Votes 0 ·

Please help with the above query.

Thanks.

0 Votes 0 ·
Show more comments
TarunGupta-1679 avatar image
0 Votes"
TarunGupta-1679 answered

Hi,

How to pass region specific information to cognitive service? To reduce latency in api response time.

Please help.
Thanks.

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.