簡體   English   中英

為了在谷歌雲中檢測文本,有沒有辦法只打印一次文本而不是逐行打印?

[英]For detecting text in Google cloud, is there a way to just print the texts once rather than printing them line-by-line?

例如,給定一個帶有“小心水獺穿越接下來 6 英里”標志的圖像:

response = client.text_detection(image=image)
text = response.text_annotations
for text in text:
    print(text.description)

這將打印:

CAUTION
Otters crossing
for next 6 miles
CAUTION
Otters
crossing
for
next
6
miles

但是,我只想要第一部分:

CAUTION
Otters crossing
for next 6 miles

有沒有辦法做到這一點?

text.description是一個數組,因此您可以刪除for循環並僅使用print(text[0].description)

代碼應如下所示:

response = client.text_detection(image=image)
text = response.text_annotations
    print(text[0].description)

此外,如文檔中所示,您可以使用document_text_detection而不是text_detection ,因為document_text_detection更准確。

文本檢測用於檢測圖像中的某些文本。 基本上它給出了在其中找到的文本值,因此如果圖像的文本按特定順序排列,它可能是准確的。

同時,文檔文本檢測的准確性非常好,可以檢測文檔中的每個細節。

使用document_text_detection代碼應如下所示:

response = client.document_text_detection(image=image)
text = response.text_annotations
    print(text.description)

暫無
暫無

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

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