【发布时间】:2018-09-20 17:48:23
【问题描述】:
我正在尝试从 tif 或 tiff 图像文件中读取文本。这些文件有多个页面。
当我打印数组时,我只得到 true,然后没有文本。但是,当我使用 .png 文件时,我可以打印文本。
下面是我的代码。
from PIL import Image, ImageSequence
import pytesseract
from pytesseract import image_to_string
import numpy as np
import cv2
test = Image.open(r'C:\Python\BG36820V1.tiff')
#test1 = Image.open(r'C:\Users\Documents\declaration.png')
testarray = np.array(test)
print(testarray)
print(pytesseract.image_to_string(Image.fromarray(testarray))
这是测试文件的输出:
[[ True True True ... True True True]
[ True True True ... True True True]
[ True True True ... True True True]
...
[ True True True ... True True True]
[ True True True ... True True True]
[ True True True ... True True True]]
不过,这对 test1 来说效果很好。
[[[242 242 242 255]
[242 242 242 255]
[242 242 242 255]
...
[242 242 242 255]
[242 242 242 255]
[242 242 242 255]]
[[182 180 182 255]
[182 180 182 255]
[182 180 182 255]
...
[182 180 182 255]
[182 180 182 255]
[182 180 182 255]]
g Request 4042337300021 submitted sucessfully
x
TYPE
我尝试使用 opencv 读取 tiff 文件,但格式不支持。
如何打印 tiff 或 tif 文件中的文本。
有什么建议吗?
问候, 任。
【问题讨论】:
标签: python-3.x python-tesseract