在使用pytesseract模块的image_to_string()功能时,识别出的结果总是带有这个向上的箭头 
和很多的换行符,在0.3.5/0.3.6版本均有多余箭头问题.
只要使用.strip()移除字符串头尾指定的字符(默认为空格或换行符)或字符序列代码如下:
import os
import sys
import pytesseract
from PIL import Image
def ocrx(image_name,lang_name):
# open image
image = Image.open(image_name)
code = pytesseract.image_to_string(image, lang=lang_name)#选择语言库
code = code.strip()
#print(code)
return code
Result = ocrx("G0.jpg",'eng')
print(Result)
待识别的图片G0.jpg

执行结果如下:

在使用pytesseract进行OCR识别时,遇到识别结果包含多余的向上箭头符号和换行。通过调用.strip()方法移除了这些不必要的字符。问题出现在0.3.5和0.3.6版本,解决方案是利用代码处理识别后的字符串。
1838

被折叠的 条评论
为什么被折叠?



