Python实现OCR接口

Sakura 发布于 2023-10-26 176 次阅读


wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda2-4.7.12.1-Linux-x86_64.sh --no-check-certificate
bash Miniconda2-4.7.12.1-Linux-x86_64.sh
cd miniconda2/bin/
./conda
./conda create -n ocr python=3.10
./conda activate ocr
source activate ocr

yum install -y libGL
pip install python-multipart  -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install rapidocr_onnxruntime -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install rapidocr-api -i https://pypi.tuna.tsinghua.edu.cn/simple/
rapidocr_api -ip 0.0.0.0 -p 9003

使用:

import requests

url = 'http://localhost:9003/ocr'
img_path = 'tests/test_files/ch_en_num.jpg'

with open(img_path, 'rb') as f:
    file_dict = {'image_file': (img_path, f, 'image/png')}
    response = requests.post(url, files=file_dict, timeout=60)

print(response.json())

文档:https://rapidai.github.io/RapidOCRDocs/docs/