Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pyteseract太慢了。如何使其更快地处理图像?_Python_Ocr_Tesseract_Python Tesseract - Fatal编程技术网

Python Pyteseract太慢了。如何使其更快地处理图像?

Python Pyteseract太慢了。如何使其更快地处理图像?,python,ocr,tesseract,python-tesseract,Python,Ocr,Tesseract,Python Tesseract,我在以下代码中使用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('ut

我在以下代码中使用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分辨率灰度)。不幸的是,对于大约35幅图像,总处理时间约为1400-1500秒


有没有办法缩短处理时间

Pytesseract写入和读取您传递的每个图像。这在运行35个映像时是不必要的。相反,您应该使用。这将大大加快速度。

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