识别时用的代码,注意更改图片地址
博文:PaddleOCR简单使用,识别文字测试
我是用PyCharm IDE
from paddleocr import PaddleOCR, draw_ocr
# 模型路径下必须含有model和params文件,如果没有,现在可以自动下载了,不过是最简单的模型
# use_gpu 如果paddle是GPU版本请设置为 True
ocr = PaddleOCR(use_angle_cls=True, use_gpu=False)
img_path = 'D:/PythonCode/paddle/ocr/11.jpg' # 这个是自己的图片,自行放置在代码目录下修改名称
result = ocr.ocr(img_path, cls=True)
for line in result:
print(line)
# 显示结果
from PIL import Image
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores)
im_show = Image.fromarray(im_show)
im_show.save('result.jpg') # 结果图片保存在代码同级文件夹中。
这个是@我是你杰哥
遇到的
这个是安装问题
他的回复
首先得保证Python是3.7版本,3.6的都不行,然后安装paddle,然后按照说明安装shapely也得对应Python版本,最后安装这个paddleocr包2.0.1或者2.0.2版本
可以参考我的安装博文重新安装
PaddleoOCR环境配置与安装
https://blog.csdn.net/qq_38463737/article/details/111890057
这个可能也是安装问题
可以参考我的安装博文重新安装
PaddleoOCR环境配置与安装
https://blog.csdn.net/qq_38463737/article/details/111890057
完整错误文本
ERROR: Command errored out with exit status 1:
command: ‘d:\code_python\paddle_2\venv\scripts\python.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\mgboy\AppData\Local\Temp\pip-inst
all-9t28wbny\python-levenshtein_13c216c123594819b0c3e6a2680b39cc\setup.py’"’"’; file=’"’"‘C:\Users\mgboy\AppData\Local\Temp\pip-install-9t28wbny\python-levensh
tein_13c216c123594819b0c3e6a2680b39cc\setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(
compile(code, file, ‘"’"‘exec’"’"’))’ install --record ‘C:\Users\mgboy\AppData\Local\Temp\pip-record-x3h79u3f\install-record.txt’ --single-version-externally-managed –
compile --install-headers ‘d:\code_python\paddle_2\venv\include\site\python3.7\python-Levenshtein’
cwd: C:\Users\mgboy\AppData\Local\Temp\pip-install-9t28wbny\python-levenshtein_13c216c123594819b0c3e6a2680b39cc
Complete output (27 lines):
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.7
creating build\lib.win-amd64-3.7\Levenshtein
copying Levenshtein\StringMatcher.py -> build\lib.win-amd64-3.7\Levenshtein
copying Levenshtein_init_.py -> build\lib.win-amd64-3.7\Levenshtein
running egg_info
writing python_Levenshtein.egg-info\PKG-INFO
writing dependency_links to python_Levenshtein.egg-info\dependency_links.txt
writing entry points to python_Levenshtein.egg-info\entry_points.txt
writing namespace_packages to python_Levenshtein.egg-info\namespace_packages.txt
writing requirements to python_Levenshtein.egg-info\requires.txt
writing top-level names to python_Levenshtein.egg-info\top_level.txt
reading manifest file ‘python_Levenshtein.egg-info\SOURCES.txt’
reading manifest template ‘MANIFEST.in’
warning: no previously-included files matching ‘*pyc’ found anywhere in distribution
warning: no previously-included files matching ‘*so’ found anywhere in distribution
warning: no previously-included files matching ‘.project’ found anywhere in distribution
warning: no previously-included files matching ‘.pydevproject’ found anywhere in distribution
writing manifest file ‘python_Levenshtein.egg-info\SOURCES.txt’
copying Levenshtein_levenshtein.c -> build\lib.win-amd64-3.7\Levenshtein
copying Levenshtein_levenshtein.h -> build\lib.win-amd64-3.7\Levenshtein
running build_ext
building ‘Levenshtein._levenshtein’ extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/
----------------------------------------
ERROR: Command errored out with exit status 1: ‘d:\code_python\paddle_2\venv\scripts\python.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\mgbo
y\AppData\Local\Temp\pip-install-9t28wbny\python-levenshtein_13c216c123594819b0c3e6a2680b39cc\setup.py’"’"’; file=’"’"‘C:\Users\mgboy\AppData\Local\Temp\pip
-install-9t28wbny\python-levenshtein_13c216c123594819b0c3e6a2680b39cc\setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’
“’, '”’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ install --record ‘C:\Users\mgboy\AppData\Local\Temp\pip-record-x3h79u3f\install-record.txt’ --sin
gle-version-externally-managed --compile --install-headers ‘d:\code_python\paddle_2\venv\include\site\python3.7\python-Levenshtein’ Check the logs for full command output.
解决方法
去 https://visualstudio.microsoft.com/visual-cpp-build-tools/
下载Microsoft C++ Build Tools
下载有点慢,请耐心
运行exe
文件
选择安装的内容(不清楚就按下面选择)
更改安装地址,(把下面红框能改的推荐改一下,改到一个容量大的盘,比如我D盘)
然后点击右下角安装按钮
安装包很大,请慢慢等吧,
这个也是安装有问题,可能是项目内的Python包有冲突
可以参考我的安装博文重新安装
PaddleoOCR环境配置与安装
https://blog.csdn.net/qq_38463737/article/details/111890057
W1229 10:51:40.596693 9548 analysis_predictor.cc:1058] Deprecated. Please use CreatePredictor instead.
[2020/12/29 10:51:41] root ERROR: error in loading image:11.jpg
Traceback (most recent call last):
File “D:/PythonCode/paddle/ocr/testocr.py”, line 8, in
for line in result:
TypeError: ‘NoneType’ object is not iterable
这个是我尝试使用CMD运行出现的错误
C:\Anaconda3\envs\paddle3.7\python.exe D:/PythonCode/paddle/ocr/testocr.py
第一个Python编译器很重要,是你安装paddleocr的编译器地址
解决
这是由于识别代码中的图片使用的地址是相对地址
把它改成绝对地址即可