Google Vision OCR returning similar character with different ascii values

52 views
Skip to first unread message

sushant khandelwal

unread,
Apr 16, 2021, 8:52:43 AM4/16/21
to cloud-vision-discuss
I have been recently working on extracting text from images using Google Cloud Vision API.

It's giving amazing results, however, I have been stuck at a particular step where I need to compare the extracted text and the same is of different ASCII values and hence doesn't get matched.

For eg: 

    for i in [77,924,1018,1052]:

        print(chr(i))

The above code will display the characters that look similar to the English character 'M', however, they are all different, and hence when I try to compare, it returns False. This issue is with multiple characters.

It would be really great if any help/suggestions could be provided on how to deal with the same.

Google Vision Code for text extraction:

    def detect_text(img_path,x,y,w,h):
        data = []
        client = vision.ImageAnnotatorClient()
        im = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), cv2.IMREAD_UNCHANGED)[y:y+h, x:x+w]
        _, im_buf_arr = cv2.imencode(".jpg", I'm)
        content = im_buf_arr.tobytes()
        image = vision.Image(content=content)
        response = client.text_detection(image=image)
        texts = response.text_annotations
        for text in texts:
            data.append('\n"{}"'.format(text.description))
        return data
        if response.error.message:
            raise Exception('{}\nFor more info on error messages, check: '
                        'https://cloud.google.com/apis/design/errors'.format(
                            response.error.message))

Olusayo Akinlaja

unread,
Aug 3, 2021, 5:57:54 PM8/3/21
to cloud-vision-discuss
Hello, 

Sorry about the late response on this thread. I see you already reported the same concern on Stackoverflow[0] and a recommendation offered on using Language Hints[1]. 

I hope that information helps. If you still require any help, be sure to reply to this thread. 

Reply all
Reply to author
Forward
0 new messages