Hello,
I am trying to extract text from an image. I tried doing it in Python and was able to do Label Detection and Text Detection. I am able to get the response back.
from google.cloud import vision
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="vision.json"
import base64
client = vision.ImageAnnotatorClient()
image_path ='Outlook.png'
with open(image_path, 'rb') as image:
content = image.read()
print(content)
#image_content = base64.b64encode(content)
response = client.annotate_image({'image': {'content': content}, 'features': [{'type': vision.enums.Feature.Type.TEXT_DETECTION}],})
print(response)
Unfortunately, I am passing the same requests '{"requests": [{
"features": [ {"type" : "TEXT_DETECTION", maxResults: 3}], "image":
{"content": "' + response.getBody() + '"}}]}'; in Javascript. I am
trying to call the Google Cloud Vision API from third party tool. But I
am receiving the below error. I am able to get the similar content (binary data of an image) in python as well as in Javascript, passing the same content, but I am passing the content to Google Cloud REST API. Any suggestions in resolving the issue.
"{\n \"error\": {\n \"code\": 400,\n \"message\": \"Invalid value at 'requests[0].image.content' (TYPE_BYTES), Base64 decoding failed for \\\"�PNG\\r\\n\\u001a\\n\\u0000\\u0000\\u0000\\rIHDR\\u0000\\u0000\\u00040\\u0000\\u0000\\u0001�\\b\\u0006\\u0000\\u0000\\u0000,�R�\\u0000\\u0000\\f\\u0015iCCPICC Profile\\u0000\\u0000H��W\\u0007XS�\\u0016�[R\\b\\t-\\u0010\\u0001)�7A�t�\\bH\\u0007\\u001b!\\tI(\\u0001\\u0012��\\u001d]Tp-��bEWElk\\u0001d��ba\\u0011�����ʺX��ʛ\\u0014�����;\\u007fΜs�?sϝ�\\u0000�j����F�\\u0000�\\u0011\\u0016�bC���)�L�\\u0013�\\u0001}@\\u0001f��b���bb\\\"\",\n \"status\": \"INVALID_ARGUMENT\",\n \"details\": [\n {\n \"@type\": \"
type.googleapis.com/google.rpc.BadRequest\",\n \"fieldViolations\": [\n {\n \"field\": \"requests[0].image.content\",\n \"description\": \"Invalid value at 'requests[0].image.content' (TYPE_BYTES), Base64 decoding failed for \\\"�PNG\\r\\n\\u001a\\n\\u0000\\u0000\\u0000\\rIHDR\\u0000\\u0000\\u00040\\u0000\\u0000\\u0001�\\b\\u0006\\u0000\\u0000\\u0000,�R�\\u0000\\u0000\\f\\u0015iCCPICC Profile\\u0000\\u0000H��W\\u0007XS�\\u0016�[R\\b\\t-\\u0010\\u0001)�7A�t�\\bH\\u0007\\u001b!\\tI(\\u0001\\u0012��\\u001d]Tp-��bEWElk\\u0001d��ba\\u0011�����ʺX��ʛ\\u0014�����;\\u007fΜs�?sϝ�\\u0000�j����F�\\u0000�\\u0011\\u0016�bC���)�L�\\u0013�\\u0001}@\\u0001f��b���bb\\\"\"\n }\n ]\n }\n ]\n }\n}\n"
Regards,
Jeevan