2023年11月19日 星期日

OCR using Google vision API

OCR
OCR by google vision API 





def ocr_by_goole_vision(input_file='captcha.png',draw_text=False):
with io.open(input_file, 'rb') as image_file:
content = image_file.read()
response = client.text_detection(image=vision.Image(content=content))
if response.error.message:
raise Exception(
'{}\nFor more info on error messages, check: '
'https://cloud.google.com/apis/design/errors'.format(
response.error.message))
print('chptcha decode:')
texts=response.text_annotations
#print(texts[0].description.split())
for text in response.text_annotations[1::]:
ocr_text = text.description
print(ocr_text)
if draw_text:
bound=text.bounding_poly
draw_text_on_image(input_file,ocr_text,bound)
return ocr_text

沒有留言 :

張貼留言