python图像学习1 ANACONDA配置cv2和pytesseract,Tesseract-OCR

ANACONDA中配置cv2和pytesseract可直接使用ANNACONDA Navigator 在想要配置的路径中直接pip install opencv-python和pytesseract,下面是可能出现的问题解决方法。https://blog.youkuaiyun.com/bichengba/article/details/135467222

在配置好cv2和pytesseract后

 pytesseract.image_to_string依旧会报错,这时需要额外安装Tesseract-OCR

具体参考此篇https://blog.youkuaiyun.com/weixin_42149550/article/details/131512759

建议不要安装最新的5.4版本,额外语言包可能会报错。

下面是可供练习的代码和图片。来源:https://blog.youkuaiyun.com/m0_57323988/article/details/140287349?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_utm_term~default-1-140287349-blog-136217706.235^v43^control&spm=1001.2101.3001.4242.2&utm_relevant_index=2


import cv2
import pytesseract

# 设置 pytesseract 的路径,这个路径需要根据你的系统环境来设置
# 例如,在 Windows 上可能是 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'


# 读取图像
image = cv2.imread("C:\\Users\ASUS\Desktop\929fa6810bf817e5eff6ec9c17dc24c0.png")

# 转换为灰度图
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 进行二值化处理
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

# 使用 pytesseract 进行文字识别
text = pytesseract.image_to_string(thresh,lang='chi_sim')

# 打印识别结果
print(text)

/home/kitty/miniconda3/envs/rknn/bin/python /home/kitty/software/pycharm-community-2023.1/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 33875 --file /home/kitty/rknn/zuoye/plate_detection_recongnition_yolov5/1.py Connected to pydev debugger (build 231.8109.197) Traceback (most recent call last): File "/home/kitty/miniconda3/envs/rknn/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 275, in run_tesseract proc = subprocess.Popen(cmd_args, **subprocess_args()) File "/home/kitty/miniconda3/envs/rknn/lib/python3.8/subprocess.py", line 858, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/kitty/miniconda3/envs/rknn/lib/python3.8/subprocess.py", line 1720, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] 没有那个文件或目录: 'tesseract' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/kitty/miniconda3/envs/rknn/lib/python3.8/contextlib.py", line 131, in __exit__ self.gen.throw(type, value, traceback) File "/home/kitty/miniconda3/envs/rknn/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 217, in save yield f.name, input_file_name File "/home/kitty/miniconda3/envs/rknn/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 352, in run_and_get_output run_tesseract(**kwargs) File "/home/kitty/miniconda3/envs/rknn/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 280, in run_tesseract raise TesseractNotFoundError() pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information. Process finished with exit code 1
07-07
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值