【发布时间】:2019-09-11 06:16:11
【问题描述】:
我正在尝试使用 python 从图像中准确提取文本。
这是我在这个场景中使用的图像:
这是我的 python 文件:
from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\Users\test\AppData\Roaming\Python\Python37\site-packages\tesseract.exe'
img=Image.open('C:/Users/test/Desktop/Everything else/work/Almonds.jpg')
text = pytesseract.image_to_string(img, lang = 'eng')
print(text)
这是我在命令提示符下运行 python 文件时的输出:
INGREDIENTS: Almonds: [Nuts] Allergy Advice:
For allergens, see ingredients in Bold
Nutritional Information
TYPICALVALUES Per 100g
Energy kJ 2597.0}
Energy kcal 626.0)
Fat 50.6g|
of which Saturates 3.9g
Carbohy drate 19.7g
of which Sugars 4.89|
Fibre 3.59
Protein 21.3g|
May contain traces of
other nuts, peanut,
sesame or gluten
This product may contain
pieces of shell
Store in a cool dry place
jout of direct sunlight
Net weight:
Salt 0.ig
For Best Before & Batch see pack 1 k
如您所见,并非所有文本都拼写正确。有什么建议可以提高文本输出的准确性吗?
额外
这是我想要实现的目标的一个想法,与问题无关,但让您了解我在这里想要实现的目标。
我有多个产品图像文件,我将在其中与 Excel 表进行比较。
Excel 工作表格式如下(1 个示例数据):
Product Code: 0001
Product Desc: Californian Whole Almonds
Ingredients: Almonds: [Nuts]
Allergy Advice: True
etc...
然后我将编写一个脚本,该脚本将检测图像文件中的文本,将其与 Excel 表进行比较,并分析每个部分是否匹配,给出“真”或“假”的输出
【问题讨论】:
-
有什么想法吗?
标签: python ocr tesseract python-tesseract