daniel Asked:2020-01-14 00:14:14 +0000 UTC2020-01-14 00:14:14 +0000 UTC 2020-01-14 00:14:14 +0000 UTC google api vision 检测图像中的文本并翻译它[关闭] 772 我无法在文档中找到正常的示例。 python 1 个回答 Voted Best Answer yoloy 2020-01-14T00:21:12Z2020-01-14T00:21:12Z 我不知道如何立即从俄罗斯的图片中读取文本(如果需要翻译成它),但是阅读后,这是使用相同的google api完全实现的 #!/usr/bin/python # -*- coding: utf-8 -*- from google.cloud import vision from google.cloud.vision import types from google.cloud import translate translate_client = translate.Client() client = vision.ImageAnnotatorClient() file_name = os.path.join( os.path.dirname(__file__), 'some_photo.jpg') with io.open(file_name, 'rb') as image_file: content = image_file.read() image = types.Image(content=content) def translate(text,target): returns_text='' for i in text: translation = translate_client.translate(i, target_language=target) returns_text+=translation['translatedText'] return(returns_text) def detect_document(image): response = client.document_text_detection(image=image) document = response.full_text_annotation returns_text=[] for page in document.pages: for block in page.blocks: block_words = [] for paragraph in block.paragraphs: block_words.extend(paragraph.words) block_symbols = [] for word in block_words: block_symbols.extend(word.symbols) block_symbols.extend(' ') block_text = '' for symbol in block_symbols: if(type(symbol)==str): block_text = block_text + ' ' else: block_text = block_text + symbol.text returns_text.append(block_text) return(returns_text) print(translate(detect_document(image), 'ru')) https://cloud.google.com/vision/docs/reference/libraries
我不知道如何立即从俄罗斯的图片中读取文本(如果需要翻译成它),但是阅读后,这是使用相同的google api完全实现的
https://cloud.google.com/vision/docs/reference/libraries