【问题标题】:Pytesseract is too slow. How can I make it process images faster?Pytesseract 太慢了。如何让它更快地处理图像?
【发布时间】:2018-08-29 06:08:02
【问题描述】:

我在下面的代码中使用 pytesseract:

    def fnd():
    for fname in list:
        x = None
        x = np.array([np.array(PIL.Image.open(fname))])
        print x.size
        for im in x:
                     txt = pytesseract.image_to_string(image=im).encode('utf-8').strip()
                     open("Output.txt","a+").write(txt)
                     with open("Output.txt") as openfile:                        
                         for line in openfile:
                             for part in line.split():
                                 if "cyber" in part.lower():
                                     print(line)
                                     return

该列表包含文件夹中的图像名称(2408*3506 和 300 res 灰度)。不幸的是,大约 35 张图像的总处理时间约为 1400-1500 秒。

有什么方法可以减少处理时间?

【问题讨论】:

  • 也许你可以试试多线程,here。我认为您的图像正在按顺序处理(一个接一个)。所以并行运行它们可能会节省一些时间。
  • 我可以试试......但是@VineethSai 即使我在这段代码中放了一张图片,也需要大约 30-50 秒来处理。
  • 您正在尝试从图像中查找字符对吗?,也许您可​​以使用 PIL 库在将图像传递到 tesseract 之前降低图像的分辨率。也许 2408*3506 & 300 res Gray-scaled tesseract 不需要这么大的分辨率来识别字符。
  • 因此降低分辨率并结合并行处理可能会大大减少时间。
  • @VineethSai ...这是我脑海中的第一个想法。我也尝试使用 100 和 200 的分辨率,但在这种情况下输出质量会受到影响。我只能在分辨率为 300 的情况下获得正确的输出。但是,将颜色更改为灰度减少了时间并提高了准确性。

标签: python ocr tesseract python-tesseract


【解决方案1】:

Pytesseract 会写入和读取您传递的每个图像。运行 35 个图像时,这是不必要的。相反,您应该使用python tesseract API interface。这将明显更快。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 1970-01-01
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    相关资源
    最近更新 更多