Code Monkey home page Code Monkey logo

paddleocr-flask-deploy's Introduction

简介

PaddleOCR 旨在打造一套丰富、领先、且实用的OCR工具库,助力开发者训练出更好的模型,并应用落地。Flask是一个使用 Python编写的轻量级 Web 应用框架。本项目旨在将PaddleOCR部署在Flask上,方便调用。

目录说明

- caches:上传过来识别的图片
- post
	- test-post.py:服务请求代码
	- demo.jpg:测试图片
- templates:前端界面
- server.py:server端

本地使用

  1. 克隆下载本仓库代码;
  2. 安装好本地需要的环境(paddlepaddlepaddleocr、以及requirements.txt);
  3. 根据需求,修改server.py第97行IP(如果本地测试,建议127.0.0.1,如果云端部署,建议0.0.0.0);
  4. 在此文件夹下启用服务:
python server.py

'''
 * Debugger is active!
 * Debugger PIN: 109-572-001
 * Running on http://127.0.0.1:8090/ (Press CTRL+C to quit)
'''
  1. 根据输出访问:http://ip:8090/ ,如果页面可以访问,即表示服务正常启动,可以做请求;

  1. 进入post文件夹下,修改第4行url为上述输出url,修改第5行请求的图片名称,终端运行:
python test-post.py

'''
{
  "服务状态": "success",
  "识别时间": "3.2900s",
  "识别结果": [
    "***",
    "2022年06月02日",
    "19:38:23",
    "未见异常②",
    "④核酸",
    "阴性",
    "时间",
    "#疫苗",
    "查看",
    "名",
    "姓",
    "李*",
    "身份证号",
    "61***",
    "**28",
    "查询时间",
    "06-0214:30",
    "失效时间",
    "06-0224:00",
    "返回首页",
  ]
}
'''

云端部署

  1. 修改代码IP
  2. 放行服务器服务端口,如:8090;

在一台2核2G的服务器上,服务结果可在2s内返回。

参数说明

  • use_angle_cls true设置使用方向分类器识别180度旋转文字;
  • use_gpu false设置不使用GPU;
  • 单独使用检测:设置recfalse
  • 单独使用识别:设置detfalse
  • paddleocr默认使用PP-OCRv3模型(ocr_version=PP-OCRv3),如需使用其他版本可通过设置参数ocr_version,具体版本说明如下:
版本名称 版本说明
PP-OCRv3 支持中、英文检测和识别,方向分类器,支持多语种识别
PP-OCRv2 支持中英文的检测和识别,方向分类器,多语言暂未更新
PP-OCR 支持中、英文检测和识别,方向分类器,支持多语种识别
  • PaddleOCR目前支持80个语种,可以通过修改lang参数进行切换,对于英文模型,指定lang=en,常用的多语言简写包括:
语种 缩写 语种 缩写 语种 缩写
中文 ch 法文 fr 日文 japan
英文 en 德文 german 韩文 korean
繁体中文 chinese_cht 意大利文 it 俄罗斯文 ru

全部语种及其对应的缩写列表可查看多语言模型教程

服务请求

请求方法:POSTGET

请求URL: http://IP:8090/ocr

请求参数说明:

参数
file 图像数据,base64编码,支持JPGPNGJPEG格式

返回参数说明:

参数
服务状态 success:成功识别;faild:无法识别;
识别结果 列表格式,包含从图片中识别的所有文字信息
识别时间 模型识别文字消耗时间

代码请求示例:

import requests
import json

url = 'http://IP:8090/ocr'
files = {'file': open('./demo.jpg', 'rb')}
r = requests.post(url, files=files)
print(r.text)

TODO

  • 即将支持PaddleOCR多应用部署;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.