pytesser - 图像中的下一行文字?

时间:2015-05-27 13:40:40

标签: python pytesser

我在使用纯文本的简单图像上使用pytesser。它很棒!但是,在python中,它会在新行上打印每行文本。但它输出的字符串没有" \ n"或者我可以提出的新行分隔符。

如何在控制台的新行上打印图像的每个新行?有没有办法可以拉出一条特定的线?或者自己拆分?

这很可能是一件非常简单的事我错过了......

from pytesser import *
image = Image.open('image.jpg') 

text =  image_to_string(image)

print len(text)
print text 

输出:

983
BACK RASHER 1.24
T CREAM 250ML 1.19
T COFFEE 200G 1.09
PEANUT BUTTER 1.12
DIET COKE * 2.39

1 个答案:

答案 0 :(得分:0)

感谢指出我的错误。 repr()在interpeter看到它时显示输出,以及新行“\ n”分隔符。使用text.split(“\ n”)然后我可以逐行拆分输出。谢谢dlask!

from pytesser import *
image = Image.open('image.jpg')  # Open image object using PIL

text =  image_to_string(image)     # Run tesseract.exe on image

print(repr(text))
result = text.split("\n")

print result
相关问题