簡體   English   中英

如何更改 Vision OCR 的注釋功能?

[英]How to change annotation features for Vision OCR?

我正在嘗試使用 Python 和 Vision 從本地圖像中提取文本,基於Cloud Vision API:檢測圖像中的文本

這是要提取文本的 function:

def detect_text(path):
    """Detects text in the file."""
    from google.cloud import vision
    import io
    client = vision.ImageAnnotatorClient()

with io.open(path, 'rb') as image_file:
        content = image_file.read()

image = vision.Image(content=content)

response = client.text_detection(image=image)
    texts = response.text_annotations

它有效,但我想指定使用TEXT_DETECTION等功能而不是默認的DOCUMENT_TEXT_DETECTION功能,以及指定語言提示。 我該怎么做? text_detection function 似乎沒有采用此類參數。

或者,您可以通過添加image_context object 來請求語言提示:

response = client.text_detection(image=image,
image_context={"language_hints": ["en"]})

下面的文章對此進行了解釋,向下滾動到“創建應用程序”部分。

您需要在代碼中添加請求 object

request = {
   "image": {
      "source": {
         "image_uri": "IMAGE_URL"
      }
   },    
   "features": [
      {
         "type": "TEXT_DETECTION"
      }
   ]
   "imageContext": {
     "languageHints": ["en-t-i0-handwrit"]
   }
}

然后將其傳遞給請求。

response = client.annotate_image(request)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM