PaddleOcr installation and usage guide

PaddleOcr installation and usage guide

1. Installation of PaddleOcr

1. Python3.7 environment preparation

Because Paddleocr has better support for Python3.7, the Python3.7 version is used.
It is best to use Anaconda to create a new virtual environment. If you don’t have Anaconda, install it (this step is not difficult, find the tutorial yourself). Even if the current Python version is 3.7, it is better to recommend a virtual environment, because deep learning The framework may conflict with other libraries.

2. Install related libraries

The required libraries are: paddlepaddle, shapely, paddleocr

Next, install it.
(In the following demo pictures, the author runs commands in the PyCharm terminal.)
①Install PaddlePaddle 2.0rc1:
on the official website
https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/ 1.8/install/pip/windows-pip.html After
selecting the various conditions, obtain the installation command paddlepaddle
and install the cpu version if you are not familiar with the gpu operation. You can
installation
enter the obtained installation command to install.

The gpu version is relatively large, about 700M and the
cpu version is very small, about 66M

②Install the shapely package
directly in the pycharm toolbar file "Settings" Project "Python interpreter" + "Search for installation
or use the command

pip install shapely -i https://mirror.baidu.com/pypi/simple

Install it.
③ Install PaddleOCR dependency (the steps are very important)
Create a requirements.txt text document in the same directory of Python.exe (in Pycharm, that is the root directory of the project).
Copy the content in the reference box below to the document and save

shapely
imgaug
pyclipper
lmdb
opencv-python==4.2.0.32
tqdm
numpy
visualdl
python-Levenshtein

Run command

pip3 install -r requirements.txt

Wait for the installation to completeThe installation is complete

④Install paddleOCR to
run the command

pip install "paddleocr>=2.0.1"

Wait for the installation to be completed So
The installation is complete
far the installation steps are completed.

☆If an error is reported during the installation process:

Such as this
The reason for the error is that the computer lacks necessary components.
Solution: Download and run this official runtime download software.
Link https://kyc592.lanzous.com/iQ9UAkm48ba Password kyc
1
select the default value and install directly.
2
3
After the installation is complete, reinstall the paddleocr related modules.

Second, the use of PaddleOcr

1. Simple test

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:/paddle/ocr/ocr.png'  # 这个是自己的图片,自行放置在代码目录下修改名称

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')  # 结果图片保存在代码同级文件夹中。

Copy the above code and modify the image path on the seventh line to the target image path to run the program.
Note: The lightweight model will be automatically downloaded when it is run for the first time, and it can be 1
run again after it is completed .
The correct operation is displayed as 1
2
Return the recognized text and generate the processed result picture

Guess you like

Origin blog.csdn.net/kyc592/article/details/112890488