question

VedantModi-1825 avatar image
0 Votes"
VedantModi-1825 asked romungi-MSFT commented

Azure Computer Vision - detect_objects_in_stream (InvalidRequest) Input data is not a valid image.

I need to run Azure Computer Vision on an image via a URL. The URL can only be accessed via a VPN. I'm connected to the VPN when I run this.

 im = Image.open(requests.get(path, stream=True).raw)

 buffer = io.BytesIO()
 im.save(buffer, 'jpeg')
 buffer.seek(0)
 image = buffer

 results = computervision_client.read_in_stream(image, raw=True)
 object_results = computervision_client.detect_objects_in_stream(image, raw=True)
 operation_location_local = results.headers["Operation-Location"]
 operation_id_local = operation_location_local.split("/")[-1]

I get the following error:

 Traceback (most recent call last):                                   
   File "path of above code", line 505, in url_detector
     object_results = computervision_client.detect_objects_in_stream(image, raw=True)
   File "c:\snip\azure\cognitiveservices\vision\computervision\operations\_computer_vision_cl
 ient_operations.py", line 1263, in detect_objects_in_stream
     raise models.ComputerVisionErrorResponseException(self._deserialize, response)
 azure.cognitiveservices.vision.computervision.models._models_py3.ComputerVisionErrorResponseException: (InvalidRequest) Input data is not a valid image.


The problem arises only with detect_objects_in_stream, read_in_stream works perfectly. Where am I going wrong?
I've tried using the im object too. I cannot pass the URL path directly in my case.




azure-cognitive-servicesazure-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.

@VedantModi-1825 Couple of things that I could recommend to debug the issue are:

  • Try the format of file in the save to 'jpg' instead of 'jpeg', I have seen one scenario where .jpg file name extensions work with some sources. Although 'jpeg' and 'jpg' are same.

  • Try to call the detect operation first and read later. You can even perform either of the call to check if they are successful. Although you are saving the image data in 'image' I am not sure if there is any other action that is causing the image data to become invalid.

0 Votes 0 ·

0 Answers