Build your own OCR service, step two: PaddleOCR environment installation

When installing the PaddleOCR environment, I encountered many problems. The problems vary depending on the system. Don't blindly follow other people's tutorials. Some tutorials are out of date. Make adjustments according to the actual situation.

My side is currently built using windows 10 system + CPU + python 3.7.

People who are familiar with OCR should know that it is best to use a GPU, and the performance gap is not a little bit. But what should ordinary people do if they don’t have that condition? They can only settle for the second best. Fortunately, you don’t need such good performance to learn to use it yourself.

PaddleOcr environment installation steps:

Step 1: Install the C++ development environment first

The biggest problem I encountered during the construction process was that the local computer did not have a Microsoft Visual C++ development environment. After all, if you are not engaged in C++ development, it would be easy to ignore this problem. Later, I found many technical articles to determine this big problem.

Visual Studio Download
First download the Visual Studio installer from Microsoft’s official website (https://visualstudio.microsoft.com/zh-hans/downloads/), as shown in the figure below:

Choose the community version, which is free. If you are a business user, choose another version.

 For the main installation process, just choose the C++ application. Others are not the focus of this article.

  For the main installation process, just choose C++ desktop development. Others are not the focus of this article.

 After this step is completed, the rest will be relatively easy.

Step 2: Just follow the installation steps on the PaddleOCR official website.

Enter Baidu Feijian official website installation address:

https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/windows-pip.html

1. Select the version, system, installation method and computer platform.

2. Execute the paddlepaddle command to install the CPU version

python -m pip install paddlepaddle==2.4.2 -i https://pypi.tuna.tsinghua.edu.cn/simple

Precautions:

During the pip installation process, relevant dependent libraries will be automatically downloaded. Two of them (lanms-neo and polygon3) are related to the c++ development environment in the first step above. If the c++ environment is not installed, installation errors will always be reported.

3. Verify installation

After the installation is complete, you can use python to enter the python interpreter, enter import paddle, and then enter paddle.utils.run_check()

If PaddlePaddle is installed successfully! appears, it means you have successfully installed it. Running the test can also detect how many CPUs the computer has.

You can also refer to the installation tutorial on gitee:

gitee source code address: 

https://gitee.com/paddlepaddle/PaddleOCR

https://gitee.com/paddlepaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/quickstart.md

4. python script uses OCR to identify images

Test picture: 1.png

 paddleocr_test.py :

from paddleocr import PaddleOCR
'''
测试ocr方法
'''
def test_ocr():
    # paddleocr 目前支持的多语言语种可以通过修改lang参数进行切换
    # 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
    # 使用CPU预加载,不用GPU
    ocr = PaddleOCR(use_angle_cls=True, lang="ch", use_gpu=False)
    # 打开图片文件
    result = ocr.ocr("1.png", cls=True)
    # 打印所有结果信息
    print(result)
    for index in range(len(result)):
        rst = result[index]
        for line in rst:
            points = line[0]
            text = line[1][0]
            score = line[1][1]
            print('points : ', points)
            print('text : ', text)
            print('score : ', score)


if __name__ == "__main__":
    test_ocr()

The first time you run the recognition program, 3 Chinese and English ultra-lightweight PP-OCRv3 models (detection model, direction classifier, and recognition model) will be automatically downloaded.

You can also actively download the model you want. on gitee.

You can also download various pre-trained models from Baidu Feijian official website and use them immediately.

Official website address: https://aistudio.baidu.com/aistudio/modelsoverview?lang=zh_CN

PaddleOCR can run normally through the python script test, but the recognition rate is not that high. This requires you to slowly train a new model later and continuously optimize the recognition model. 

Or choose a pre-trained model on the official website, which is simple and hassle-free.

Step 3: Download PaddleOCR source code

Github open source address: https://github.com/PaddlePaddle/PaddleOCR.git

gitee open source address: https://gitee.com/paddlepaddle/PaddleOCR

Download the PaddleOCR source code locally instead of simply installing the PaddleOCR library and directly calling its methods. If the purpose is to learn and research, it is still very useful to look at the source code.

The source code directory structure is as follows:

 Among them, pip installation paddlepaddle 过程中下载的相关依赖库就在 requirements.txt 文件里。

--------------------------At this point, the installation of PaddleOCR is basically completed------------- ------------------

Guess you like

Origin blog.csdn.net/xionghui2007/article/details/132753899