几个月前我写了这段代码,并希望通过它来清理它并添加一些新功能。它是一个简单的工具,我用来拍摄我的屏幕,并从中获取可写的字。我在最初编写代码的新计算机上;但是,我通过pycharm模块管理器安装了每个模块。但是,即使我已经在我的路径中找到了包,我在运行代码时仍然会收到此错误。任何帮助将不胜感激。
我查看了我的问题的几个不同的变化,但它们似乎都有不同的原因和修复,当然,这些都不适合我。
if c ==2:
img = ImageGrab.grab(bbox=(x1-5, y1-5, x2+5,y2+5)) # bbox specifies region (bbox= x,y,width,height)
img_np = np.array(img)
frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
c = 0
x = 0
string = str(pytesseract.image_to_string(frame)).lower()
print(string)
这是引用pytesseract的代码中唯一的部分,当然不是“import pytesseract”。希望我能再次使用这个代码并运行pytesseract模块,因为它是我的许多脚本不可或缺的部分。在此先感谢您的帮助。
File "C:\Users\dante\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 184, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "C:\Users\dante\Anaconda3\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\dante\Anaconda3\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/dante/Desktop/DPC/processes/screen_to_text.py", line 29, in <module>
string = str(pytesseract.image_to_string(frame)).lower()
File "C:\Users\dante\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 309, in image_to_string
}[output_type]()
File "C:\Users\dante\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 308, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "C:\Users\dante\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 218, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\dante\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 186, in run_tesseract
raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path```
问题在于我对模块缺乏了解。 pytesseract不是OCR,它只是一个允许用户使用谷歌OCR的翻译器。这意味着,为了使用此软件包,用户必须安装谷歌的OCR(我从这里下载我的https://sourceforge.net/projects/tesseract-ocr-alt/files/)。
这不;但是,解决了完整的问题。 pytesseract包需要知道实际OCR程序的位置。在pytesseract.py脚本的第35行,有一行告诉pytesseract在哪里可以找到实际的谷歌OCR tesseract程序
tesseract_cmd = 'tesseract'
如果你在Windows上并且没有手动添加tesseract到你的路径(如果你不知道这意味着什么只是按照下面的步骤),那么你需要用计算机上的谷歌OCR的实际位置替换该行。用。替换该行
tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'
应该允许你运行pytesseract假设你已经正确安装了所有东西。花了我相当长的时间,我想承认找到这个问题的明显解决方案,但希望将来有这个问题的人解决它比我做得更快!谢谢,祝你有个美好的一天。