【问题标题】:How to print tesseract result in chinese characters如何以汉字打印tesseract结果
【发布时间】:2019-09-10 16:21:11
【问题描述】:

我正在尝试让我的程序使用 Tesseract 识别中文,它可以工作。我遇到的唯一问题是将结果打印为汉字,结果是以拼音打印的(如何将中文输入为英文)。

# Import libraries
from PIL import Image
import pytesseract
from unidecode import unidecode

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

image_counter = 2

filelimit = image_counter - 1

outfile = "out_text.txt"

f = open(outfile, "a")

for i in range(1, filelimit + 1):
    print("ran")
    filename = "page_" + str(i) + ".png"

    # Recognize the text as string in image using pytesserct
    text = unidecode(((pytesseract.image_to_string(Image.open(filename), lang = "chi_sim"))))

    print(text)

这是我运行的图像

这是我得到的

ran Qing Ming Shi Jie Yu Fen Fen , Lu Shang Xing Ren Yu Duan Que Xin Wen Jiu Jia He Chu You , Mu Yi Tong Zhi Qiang Hua Cun .

结果应该是中文字符,如图所示。

【问题讨论】:

标签: python tesseract


【解决方案1】:

没关系,我意识到了我的问题。

text = unidecode(((pytesseract.image_to_string(Image.open(filename), lang = "chi_sim"))))

应该是

text = pytesseract.image_to_string(Image.open(filename), lang = "chi_tra")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 2017-07-21
    • 1970-01-01
    • 2018-09-26
    • 2021-07-10
    相关资源
    最近更新 更多