【发布时间】:2022-12-01 02:35:24
【问题描述】:
我正在使用 pytesseract 处理下图:
当我使用 image_to_string() 函数时
config = "--oem 3 -l eng --psm 7"
pytesseract.image_to_string(potential_image, config = config)
我得到正确的“03”输出。但是,当我使用 image_to_data() 函数时
predict = pytesseract.image_to_data(potential_image, config = config, output_type="data.frame")
print(predict)
predict = predict[predict["conf"] != -1]
try:
detected = " ".join([str(int(a)) if isinstance(a, float) else str(a) for a in predict["text"].tolist()])
confidence = predict["conf"].iloc[0]
print("Converted detected:", detected)
print("with confidence:", confidence)
except:
pass
我得到:
level page_num block_num par_num line_num word_num left top width height conf text
4 5 1 1 1 1 1 4 4 25 16 95.180374 3.0
Converted detected: 3
with confidence: 95.180374
前导 0 未保留,结果是一个浮点数,我稍后必须将其转换为 int / string。有没有办法保留文本输出,使其与image_to_string() 相同?
【问题讨论】:
标签: python dataframe python-tesseract