0

I use google vision api to detect the ocr.

However, I got no ocr text.

On the other hand, I uploaded the image to https://cloud.google.com/vision/ and got DBR Weddings\n.

Is it normal?

How should I correct my code?

Thank you very much.

Here is my code:

import requests
from PIL import Image
from io import BytesIO
import cv2
import base64
import ast

url = r'https://drive.google.com/uc?id=1pjofUsy5V4v7DSVsRERw6S-Zo36hO1bZ'
feature_json_obj = [{'type': 'TEXT_DETECTION', 'maxResults': 100}]
img = Image.open(BytesIO(requests.get(url).content))
arr = cv2.cvtColor(np.asarray(img.convert('RGB'), dtype=np.uint8), cv2.COLOR_RGB2BGR)

content_json_obj = {'content': base64.b64encode(a_numpy.tostring()).decode('UTF-8')}
request_list = {'requests': [{'features': feature_json_obj, 'image': content_json_obj, 'imageContext': {'languageHints': "zh-TW"}}]}
req = requests.post(url='https://vision.googleapis.com/v1/images:annotate?key=my_key', data = str.encode(str(request_list)), headers={'Content-Type': 'application/json'}).text
receive_data = req.encode(sys.stdin.encoding, "replace").decode(sys.stdin.encoding)
data = ast.literal_eval(receive_data)['responses'][0]['fullTextAnnotation']['text']#get google-vision result
Chan
  • 3,605
  • 9
  • 29
  • 60

0 Answers0