opencv - 正方体未发现错误:未安装或不在您的 PATH 中
问题描述
当我打开图像和数字化时,它会给出错误我在 jupyter notebook windows 10 上运行此代码。我也使用 pip 命令安装了 pytesseract 和 tesseract
这是我的代码
try:
from PIL import Image
except ImportError:
import Image
import pytesseract
# If you don't have tesseract executable in your PATH, include the following:
# pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'
# Example tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract'
# Simple image to string
print(pytesseract.image_to_string(Image.open('Train/TR_1.jpg')))
当我运行给定的代码时它会出错
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\anaconda3\envs\tf1\lib\site-packages\pytesseract\pytesseract.py in run_tesseract(input_filename, output_filename_base, extension, lang, config, nice, timeout)
237 try:
--> 238 proc = subprocess.Popen(cmd_args, **subprocess_args())
239 except OSError as e:
~\anaconda3\envs\tf1\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
799 errread, errwrite,
--> 800 restore_signals, start_new_session)
801 except:
~\anaconda3\envs\tf1\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1206 os.fspath(cwd) if cwd is not None else None,
-> 1207 startupinfo)
1208 finally:
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
TesseractNotFoundError Traceback (most recent call last)
<ipython-input-24-518675d4cb18> in <module>
10
11 # Simple image to string
---> 12 print(pytesseract.image_to_string(Image.open('Train/TR_1.jpg')))
13
14 # # French text image to string
~\anaconda3\envs\tf1\lib\site-packages\pytesseract\pytesseract.py in image_to_string(image, lang, config, nice, output_type, timeout)
358 Output.DICT: lambda: {'text': run_and_get_output(*args)},
359 Output.STRING: lambda: run_and_get_output(*args),
--> 360 }[output_type]()
361
362
~\anaconda3\envs\tf1\lib\site-packages\pytesseract\pytesseract.py in <lambda>()
357 Output.BYTES: lambda: run_and_get_output(*(args + [True])),
358 Output.DICT: lambda: {'text': run_and_get_output(*args)},
--> 359 Output.STRING: lambda: run_and_get_output(*args),
360 }[output_type]()
361
~\anaconda3\envs\tf1\lib\site-packages\pytesseract\pytesseract.py in run_and_get_output(image, extension, lang, config, nice, timeout, return_bytes)
268 }
269
--> 270 run_tesseract(**kwargs)
271 filename = kwargs['output_filename_base'] + extsep + extension
272 with open(filename, 'rb') as output_file:
~\anaconda3\envs\tf1\lib\site-packages\pytesseract\pytesseract.py in run_tesseract(input_filename, output_filename_base, extension, lang, config, nice, timeout)
240 if e.errno != ENOENT:
241 raise e
--> 242 raise TesseractNotFoundError()
243
244 with timeout_manager(proc, timeout) as error_string:
TesseractNotFoundError: <full_path_to_your_tesseract_executable> is not installed or it's not in your PATH
我在 jupyter notebook windows 10 上运行此代码。我也使用 pip 命令安装了 pytesseract 和 tesseract
解决方案
您必须先安装 tesseract 本身。在 Centos 中,您可以通过运行来调用
yum-config-manager --add-repo
https://download.opensuse.org/repositories/home:/Alexander_Pozdnyakov/CentOS_7/
rpm --import https://build.opensuse.org/projects/home:Alexander_Pozdnyakov/public_key
yum install -y tesseract tesseract-langpack-deu
在 Windows 操作系统中也应该有一个等价物,可以在这里找到https://github.com/tesseract-ocr/tesseract/wiki
pytesseract 只是 tesseract 包的包装器。
推荐阅读
- clojure - Clojure 矩阵乘法错误:“向量大小不匹配”(clojure.core.matrix)
- azure-spatial-anchors - Azure 空间锚点是否会针对每个用户会话优化其内部模型?
- javascript - 无法查看从 socketio 到浏览器的事件
- symfony - Symfony 4:数据表搜索过滤器问题
- progressive-web-apps - 我们如何安装渐进式网络应用程序?
- oracle - ORA: 00928 SELECT 关键字丢失
- javascript - 在滚动时,从头开始绘制三角形,但在这段代码中没有发生
- r - 光栅警告消息:在 cbind(m[i, ], vals) 中:结果的行数不是向量长度的倍数(arg 2)
- apache-spark - 火花大师中的火花提交本地模式
- java - 在封闭的 switch 表达式之外返回