This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
沒有留言 :
張貼留言