├── .gitignore ├── Centos-7.repo ├── Dockerfile ├── Dockerfile-gcc-8.2.0-centos7 ├── Dockerfile-nodejs ├── Dockerfile-python-3.7-centos7 ├── LICENSE ├── README.md ├── build-docker-image.sh ├── docker-entrypoint.sh ├── epel-7.repo ├── images ├── doc-1.png ├── doc-2.png ├── fapiao-1.png ├── haibao-1.png ├── idcard-1.png ├── train-ticket-1.png ├── train-ticket-2.png ├── verifycode-1.png ├── verifycode-2.png └── webui.png ├── paddlewebocr ├── __init__.py ├── main.py ├── pkg │ ├── __init__.py │ ├── config.py │ ├── log.py │ ├── ocr.py │ └── util.py └── route │ ├── __init__.py │ ├── api.py │ └── v1 │ ├── __init__.py │ └── ocr.py ├── requirements-dev.txt ├── requirements.txt ├── tests ├── img1.png ├── test_img_b64.py └── test_img_upload.py └── webui ├── .env.example ├── .gitignore ├── babel.config.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ └── logo.png ├── components │ └── CodeHighlight.vue ├── main.js ├── router │ └── index.js └── views │ └── Index.vue └── vue.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | # LOG 2 | logs/ 3 | 4 | # Visual Code 5 | .vscode/ 6 | 7 | # Node 8 | dist/ 9 | node_modules/ 10 | 11 | # PaddlePaddle Models 12 | inference/ 13 | 14 | # Byte-compiled / optimized / DLL files 15 | __pycache__/ 16 | *.py[cod] 17 | *$py.class 18 | 19 | # C extensions 20 | *.so 21 | 22 | # Distribution / packaging 23 | .Python 24 | build/ 25 | develop-eggs/ 26 | dist/ 27 | downloads/ 28 | eggs/ 29 | .eggs/ 30 | lib/ 31 | lib64/ 32 | parts/ 33 | sdist/ 34 | var/ 35 | wheels/ 36 | pip-wheel-metadata/ 37 | share/python-wheels/ 38 | *.egg-info/ 39 | .installed.cfg 40 | *.egg 41 | MANIFEST 42 | 43 | # PyInstaller 44 | # Usually these files are written by a python script from a template 45 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 46 | *.manifest 47 | *.spec 48 | 49 | # Installer logs 50 | pip-log.txt 51 | pip-delete-this-directory.txt 52 | 53 | # Unit test / coverage reports 54 | htmlcov/ 55 | .tox/ 56 | .nox/ 57 | .coverage 58 | .coverage.* 59 | .cache 60 | nosetests.xml 61 | coverage.xml 62 | *.cover 63 | *.py,cover 64 | .hypothesis/ 65 | .pytest_cache/ 66 | 67 | # Translations 68 | *.mo 69 | *.pot 70 | 71 | # Django stuff: 72 | *.log 73 | local_settings.py 74 | db.sqlite3 75 | db.sqlite3-journal 76 | 77 | # Flask stuff: 78 | instance/ 79 | .webassets-cache 80 | 81 | # Scrapy stuff: 82 | .scrapy 83 | 84 | # Sphinx documentation 85 | docs/_build/ 86 | 87 | # PyBuilder 88 | target/ 89 | 90 | # Jupyter Notebook 91 | .ipynb_checkpoints 92 | 93 | # IPython 94 | profile_default/ 95 | ipython_config.py 96 | 97 | # pyenv 98 | .python-version 99 | 100 | # pipenv 101 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 102 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 103 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 104 | # install all needed dependencies. 105 | #Pipfile.lock 106 | 107 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 108 | __pypackages__/ 109 | 110 | # Celery stuff 111 | celerybeat-schedule 112 | celerybeat.pid 113 | 114 | # SageMath parsed files 115 | *.sage.py 116 | 117 | # Environments 118 | .env 119 | .venv 120 | env/ 121 | venv/ 122 | ENV/ 123 | env.bak/ 124 | venv.bak/ 125 | 126 | # Spyder project settings 127 | .spyderproject 128 | .spyproject 129 | 130 | # Rope project settings 131 | .ropeproject 132 | 133 | # mkdocs documentation 134 | /site 135 | 136 | # mypy 137 | .mypy_cache/ 138 | .dmypy.json 139 | dmypy.json 140 | 141 | # Pyre type checker 142 | .pyre/ 143 | -------------------------------------------------------------------------------- /Centos-7.repo: -------------------------------------------------------------------------------- 1 | # CentOS-Base.repo 2 | # 3 | # The mirror system uses the connecting IP address of the client and the 4 | # update status of each mirror to pick mirrors that are updated to and 5 | # geographically close to the client. You should use this for CentOS updates 6 | # unless you are manually picking other mirrors. 7 | # 8 | # If the mirrorlist= does not work for you, as a fall back you can try the 9 | # remarked out baseurl= line instead. 10 | # 11 | # 12 | 13 | [base] 14 | name=CentOS-$releasever - Base - mirrors.aliyun.com 15 | failovermethod=priority 16 | baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ 17 | http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ 18 | http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/ 19 | gpgcheck=1 20 | gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 21 | 22 | #released updates 23 | [updates] 24 | name=CentOS-$releasever - Updates - mirrors.aliyun.com 25 | failovermethod=priority 26 | baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ 27 | http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ 28 | http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/ 29 | gpgcheck=1 30 | gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 31 | 32 | #additional packages that may be useful 33 | [extras] 34 | name=CentOS-$releasever - Extras - mirrors.aliyun.com 35 | failovermethod=priority 36 | baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ 37 | http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ 38 | http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/ 39 | gpgcheck=1 40 | gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 41 | 42 | #additional packages that extend functionality of existing packages 43 | [centosplus] 44 | name=CentOS-$releasever - Plus - mirrors.aliyun.com 45 | failovermethod=priority 46 | baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ 47 | http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ 48 | http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/ 49 | gpgcheck=1 50 | enabled=0 51 | gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 52 | 53 | #contrib - packages by Centos Users 54 | [contrib] 55 | name=CentOS-$releasever - Contrib - mirrors.aliyun.com 56 | failovermethod=priority 57 | baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ 58 | http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ 59 | http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/ 60 | gpgcheck=1 61 | enabled=0 62 | gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 63 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nodejs as nodejsbuilder 2 | FROM gcc:8.2.0-centos7 as gccbuilder 3 | FROM python:3.7-centos7 4 | 5 | COPY --from=gccbuilder /usr/local/gcc-8.2.0 /usr/local/gcc-8.2.0 6 | 7 | ENV LD_LIBRARY_PATH=/usr/local/gcc-8.2.0/lib64:${LD_LIBRARY_PATH} 8 | 9 | RUN yum install -y \ 10 | gmp-devel \ 11 | mpfr-devel \ 12 | libmpc-devel 13 | 14 | WORKDIR /app 15 | 16 | COPY requirements.txt requirements.txt 17 | 18 | RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ \ 19 | --no-cache-dir \ 20 | -r requirements.txt 21 | 22 | COPY paddlewebocr paddlewebocr 23 | 24 | RUN python paddlewebocr/pkg/ocr.py 25 | 26 | COPY --from=nodejsbuilder /app/dist webui/dist 27 | 28 | COPY docker-entrypoint.sh /usr/local/bin/ 29 | 30 | ENTRYPOINT ["docker-entrypoint.sh"] 31 | 32 | EXPOSE 8080 33 | 34 | VOLUME /app/logs 35 | 36 | CMD ["uvicorn", "paddlewebocr.main:app", "--host", "0.0.0.0", "--port", "8080"] 37 | -------------------------------------------------------------------------------- /Dockerfile-gcc-8.2.0-centos7: -------------------------------------------------------------------------------- 1 | FROM centos:centos7 2 | 3 | MAINTAINER Le Wang 4 | 5 | RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 6 | COPY Centos-7.repo /etc/yum.repos.d/CentOS-Base.repo 7 | RUN sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo 8 | COPY epel-7.repo /etc/yum.repos.d/epel.repo 9 | 10 | WORKDIR /root 11 | 12 | RUN yum install -y \ 13 | wget \ 14 | gmp-devel \ 15 | mpfr-devel \ 16 | libmpc-devel \ 17 | gcc \ 18 | gcc-c++ \ 19 | make \ 20 | automake \ 21 | autoconf \ 22 | libtool 23 | 24 | ARG GCC_VERSION=8.2.0 25 | 26 | RUN wget --no-check-certificate https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz && \ 27 | tar zxvf gcc-${GCC_VERSION}.tar.gz && \ 28 | mkdir gcc-${GCC_VERSION}-build && \ 29 | cd gcc-${GCC_VERSION}-build && \ 30 | ../gcc-${GCC_VERSION}/configure --enable-languages=c,c++ --disable-multilib --prefix=/usr/local/gcc-${GCC_VERSION} && \ 31 | make -j$(nproc) && make install && \ 32 | cd .. && rm -rf gcc-${GCC_VERSION} gcc-${GCC_VERSION}.tar.bz2 gcc-${GCC_VERSION}-build 33 | -------------------------------------------------------------------------------- /Dockerfile-nodejs: -------------------------------------------------------------------------------- 1 | FROM node:16.13.0 2 | 3 | WORKDIR /app 4 | 5 | COPY ["webui/package.json", "webui/package-lock.json*", "./"] 6 | 7 | RUN npm install 8 | 9 | COPY webui . 10 | 11 | RUN npm run build 12 | -------------------------------------------------------------------------------- /Dockerfile-python-3.7-centos7: -------------------------------------------------------------------------------- 1 | FROM centos:centos7 2 | 3 | ARG PYTHON_VERSION=3.7.9 4 | 5 | RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 6 | COPY Centos-7.repo /etc/yum.repos.d/CentOS-Base.repo 7 | RUN sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo 8 | COPY epel-7.repo /etc/yum.repos.d/epel.repo 9 | 10 | RUN yum install -y \ 11 | ncurses-libs \ 12 | zlib-devel \ 13 | mesa-libGL \ 14 | libffi-devel \ 15 | bzip2-devel \ 16 | openssl-devel \ 17 | ncurses-devel \ 18 | sqlite-devel \ 19 | readline-devel \ 20 | tk-devel \ 21 | gdbm-devel \ 22 | db4-devel \ 23 | libpcap-devel \ 24 | xz-devel \ 25 | gcc \ 26 | gcc-c++ \ 27 | make \ 28 | curl \ 29 | vim \ 30 | git \ 31 | wget && yum clean all 32 | 33 | 34 | ENV LANG en_US.UTF-8 35 | 36 | ENV PYENV_ROOT="/.pyenv" \ 37 | PATH="/.pyenv/bin:/.pyenv/shims:$PATH" 38 | 39 | RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash && \ 40 | wget https://npm.taobao.org/mirrors/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz -P /.pyenv/cache/ && \ 41 | pyenv install ${PYTHON_VERSION} && \ 42 | pyenv global ${PYTHON_VERSION} && \ 43 | rm -rf /.pyenv/cache/Python-${PYTHON_VERSION}.tar.xz /tmp/* 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PaddleWebOCR 2 | 3 | 开源的中英文离线 OCR,使用 [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) 实现,提供了简单的 Web 页面及接口。 4 | 5 | An opensource offline multi-languages OCR system shipped with RESTful api and web page. 6 | 7 | ## 介绍 8 | 9 | **使用了开源的 PaddleOCR 并内置了多个模型,可以在离线环境下运行,并且相关资料丰富便于自行训练模型。PaddleOCR 本身支持中文简体繁体,英文,韩文等等多种语言,本项目只内置了中英文(简体中文和繁体中文)的模型,如需要识别其它语言,可以参考本项目调整模型。** 10 | 11 | 12 | ![web页面](https://github.com/lewangdev/PaddleWebOCR/blob/main/images/webui.png?raw=true) 13 | 14 | 15 | ## 特性 16 | 17 | * 中文简体/繁体,英语等多语种识别 18 | 19 | ## 安装需求 20 | 21 | ### 运行平台 22 | 23 | * ✔ Python 3.7+ 24 | * ✔ Windows 10/11 25 | * ✔ CentOS 7 26 | * ✔ MacOS Big Sur 27 | * ✔ Docker 28 | 29 | Windows、CentOS 和 MacOS 系统下在安装好依赖之后可以直接运行,目前只构建了 paddlepaddle 的 CPU 版本,不支持 GPU。也过通过构建 Docker 镜像或者直接从 DockerHub 拉去镜像来使用。 30 | 31 | ### 最低配置要求 32 | 33 | * CPU: 2 核 34 | * 内存: 4GB 35 | 36 | ## 安装说明 37 | 38 | ### 服务器部署 39 | 40 | 0. 安装好 nodejs 之后进入 webui 目录 41 | 42 | ``` 43 | cd webui 44 | npm install 45 | npm run build 46 | ``` 47 | 48 | 1. 安装 python 3.7 49 | 50 | 2. 安装依赖包 51 | 52 | ``` shell script 53 | pip install -r requirements.txt 54 | ``` 55 | 56 | 3. 运行,项目默认运行在 8080 端口: 57 | 58 | ``` shell script 59 | uvicorn paddlewebocr.main:app --host 0.0.0.0 --port 8080 60 | 61 | 62 | #或者 63 | 64 | PYTHONPATH="${PYTHONPATH}:." python paddlewebocr/main.py [--port=8080] 65 | 66 | ``` 67 | 68 | ### Docker 部署 69 | 70 | 71 | 推荐从 DockerHub pull 运行镜像 72 | 73 | ```shell script 74 | docker run -d -p 8080:8080 -v ${PWD}/logs:/app/logs --name paddlewebocr lewangdev/paddlewebocr:latest 75 | ``` 76 | 77 | 使用脚本构建本地镜像(因为要编译 GCC,整个构建过程非常漫长) 78 | 79 | ```shell script 80 | # Dockerfile 构建 81 | ./build-docker-image.sh 82 | 83 | # 运行镜像 84 | docker run -d -p 8080:8080 -v ${PWD}/logs:/app/logs --name paddlewebocr paddlewebocr:latest 85 | ``` 86 | 87 | 88 | ## 接口调用示例 89 | 90 | * Python 使用 File 上传文件 91 | 92 | ``` python 93 | import requests 94 | url = 'http://127.0.0.1:8080/api/ocr' 95 | img1_file = { 96 | 'img_upload': open('img1.png', 'rb') 97 | } 98 | res = requests.post(url=url, data={'compress': 0}, files=img1_file) 99 | ``` 100 | 101 | * Python 使用 Base64 102 | 103 | ``` python 104 | import requests 105 | import base64 106 | 107 | 108 | def img_to_base64(img_path): 109 | with open(img_path, 'rb')as read: 110 | b64 = base64.b64encode(read.read()) 111 | return b64 112 | 113 | 114 | url = 'http://127.0.0.1:8080/api/ocr' 115 | img_b64 = img_to_base64('./img1.png') 116 | res = requests.post(url=url, data={'img_b64': img_b64}) 117 | 118 | ``` 119 | 120 | ## 效果展示 121 | 122 | ![英文文档识别](https://github.com/lewangdev/PaddleWebOCR/blob/main/images/doc-1.png?raw=true) 123 | 124 | ![中文文档识别](https://github.com/lewangdev/PaddleWebOCR/blob/main/images/doc-2.png?raw=true) 125 | 126 | ![验证码识别](https://github.com/lewangdev/PaddleWebOCR/blob/main/images/verifycode-1.png?raw=true) 127 | 128 | ![验证码识别](https://github.com/lewangdev/PaddleWebOCR/blob/main/images/verifycode-2.png?raw=true) 129 | 130 | ![火车票](https://github.com/lewangdev/PaddleWebOCR/blob/main/images/train-ticket-1.png?raw=true) 131 | 132 | ![火车票](https://github.com/lewangdev/PaddleWebOCR/blob/main/images/train-ticket-2.png?raw=true) 133 | 134 | ![发票](https://github.com/lewangdev/PaddleWebOCR/blob/main/images/fapiao-1.png?raw=true) 135 | 136 | ![身份证](https://github.com/lewangdev/PaddleWebOCR/blob/main/images/idcard-1.png?raw=true) 137 | 138 | ![海报](https://github.com/lewangdev/PaddleWebOCR/blob/main/images/haibao-1.png?raw=true) 139 | 140 | ## 更新记录 141 | 142 | [查看更新记录](https://github.com/lewangdev/PaddleWebOCR/releases) 143 | 144 | 145 | ## 致谢 146 | 147 | 本项目参考了 [TrWebOCR](https://github.com/alisen39/TrWebOCR),由于 TrWebOCR 启动时需要联网并且它使用的 [Tr](https://github.com/myhub/tr) 相关的资料比较少,故而尝试使用 [paddlepaddle](https://github.com/PaddlePaddle/Paddle) 和 [paddleocr](https://github.com/PaddlePaddle/PaddleOCR) 来替换 Tr, 从而有了本项目。 148 | 149 | 150 | ## License 151 | 152 | Apache 2.0 153 | -------------------------------------------------------------------------------- /build-docker-image.sh: -------------------------------------------------------------------------------- 1 | sudo docker build . -f Dockerfile-gcc-8.2.0-centos7 -t gcc:8.2.0-centos7 2 | sudo docker build . -f Dockerfile-nodejs -t nodejs 3 | sudo docker build . -f Dockerfile-python-3.7-centos7 -t python:3.7-centos7 4 | sudo docker build . -t paddlewebocr 5 | -------------------------------------------------------------------------------- /docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -eu 3 | 4 | exec "$@" 5 | -------------------------------------------------------------------------------- /epel-7.repo: -------------------------------------------------------------------------------- 1 | [epel] 2 | name=Extra Packages for Enterprise Linux 7 - $basearch 3 | baseurl=http://mirrors.aliyun.com/epel/7/$basearch 4 | failovermethod=priority 5 | enabled=1 6 | gpgcheck=0 7 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 8 | 9 | [epel-debuginfo] 10 | name=Extra Packages for Enterprise Linux 7 - $basearch - Debug 11 | baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug 12 | failovermethod=priority 13 | enabled=0 14 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 15 | gpgcheck=0 16 | 17 | [epel-source] 18 | name=Extra Packages for Enterprise Linux 7 - $basearch - Source 19 | baseurl=http://mirrors.aliyun.com/epel/7/SRPMS 20 | failovermethod=priority 21 | enabled=0 22 | gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 23 | gpgcheck=0 24 | -------------------------------------------------------------------------------- /images/doc-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/images/doc-1.png -------------------------------------------------------------------------------- /images/doc-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/images/doc-2.png -------------------------------------------------------------------------------- /images/fapiao-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/images/fapiao-1.png -------------------------------------------------------------------------------- /images/haibao-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/images/haibao-1.png -------------------------------------------------------------------------------- /images/idcard-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/images/idcard-1.png -------------------------------------------------------------------------------- /images/train-ticket-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/images/train-ticket-1.png -------------------------------------------------------------------------------- /images/train-ticket-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/images/train-ticket-2.png -------------------------------------------------------------------------------- /images/verifycode-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/images/verifycode-1.png -------------------------------------------------------------------------------- /images/verifycode-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/images/verifycode-2.png -------------------------------------------------------------------------------- /images/webui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/images/webui.png -------------------------------------------------------------------------------- /paddlewebocr/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/paddlewebocr/__init__.py -------------------------------------------------------------------------------- /paddlewebocr/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import click 4 | import logging 5 | from loguru import logger 6 | from fastapi import FastAPI 7 | from fastapi.staticfiles import StaticFiles 8 | from starlette.middleware.cors import CORSMiddleware 9 | from paddlewebocr.pkg.config import settings 10 | from paddlewebocr.pkg.log import InterceptHandler, format_record 11 | from paddlewebocr.route.api import api_router 12 | 13 | 14 | def make_app(): 15 | app = FastAPI( 16 | title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json", 17 | debug=settings.DEBUG, 18 | ) 19 | 20 | logging.getLogger().handlers = [InterceptHandler()] 21 | 22 | logger.configure( 23 | handlers=[{"sink": sys.stdout, "level": logging.DEBUG, "format": format_record}] 24 | ) 25 | logger.add(settings.LOG_FILE, encoding='utf-8', rotation="9:46") 26 | 27 | loggers = ( 28 | logging.getLogger(name) 29 | for name in logging.root.manager.loggerDict 30 | if name.startswith("uvicorn.") or name.startswith("paddle.") 31 | ) 32 | for uvicorn_logger in loggers: 33 | uvicorn_logger.handlers = [] 34 | logging.getLogger("uvicorn").handlers = [InterceptHandler()] 35 | logging.getLogger("paddle").handlers = [InterceptHandler()] 36 | logger.info("Starting {}", settings.PROJECT_NAME) 37 | return app 38 | 39 | 40 | app = make_app() 41 | 42 | # Set all CORS enabled origins 43 | if settings.CORS_ORIGINS: 44 | app.add_middleware( 45 | CORSMiddleware, 46 | allow_origins=[str(origin) for origin in settings.CORS_ORIGINS], 47 | allow_credentials=True, 48 | allow_methods=["*"], 49 | allow_headers=["*"], 50 | ) 51 | 52 | app.include_router(api_router, prefix=settings.API_V1_STR) 53 | app.mount("/", StaticFiles(directory=os.path.join(".", "webui", "dist"), html=True), name="static") 54 | 55 | 56 | @click.command() 57 | @click.option("--bind", default='0.0.0.0', help="service bind address") 58 | @click.option("--port", default=8080, help="service port") 59 | def main(bind, port): 60 | import uvicorn 61 | uvicorn.run(app, host=bind, port=port) 62 | 63 | 64 | if __name__ == "__main__": 65 | main() 66 | -------------------------------------------------------------------------------- /paddlewebocr/pkg/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/paddlewebocr/pkg/__init__.py -------------------------------------------------------------------------------- /paddlewebocr/pkg/config.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | from pydantic import BaseSettings, AnyHttpUrl 4 | 5 | 6 | class Settings(BaseSettings): 7 | API_V1_STR: str = "/api" 8 | PROJECT_NAME: str = "PaddleWebOCR" 9 | CORS_ORIGINS: List[AnyHttpUrl] = [] 10 | DEBUG: bool = False 11 | LOG_FILE: str = "logs/info.log" 12 | 13 | class Config: 14 | case_sensitive = True 15 | env_file = ".env" 16 | 17 | 18 | settings = Settings() 19 | -------------------------------------------------------------------------------- /paddlewebocr/pkg/log.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from pprint import pformat 3 | 4 | from loguru import logger 5 | from loguru._defaults import LOGURU_FORMAT 6 | 7 | 8 | class InterceptHandler(logging.Handler): 9 | def emit(self, record): 10 | # Get corresponding Loguru level if it exists 11 | try: 12 | level = logger.level(record.levelname).name 13 | except ValueError: 14 | level = record.levelno 15 | 16 | # Find caller from where originated the logged message 17 | frame, depth = logging.currentframe(), 2 18 | while frame.f_code.co_filename == logging.__file__: 19 | frame = frame.f_back 20 | depth += 1 21 | 22 | logger.opt(depth=depth, exception=record.exc_info).log( 23 | level, record.getMessage() 24 | ) 25 | 26 | 27 | def format_record(record: dict) -> str: 28 | format_string = LOGURU_FORMAT 29 | 30 | if record["extra"].get("payload") is not None: 31 | record["extra"]["payload"] = pformat( 32 | record["extra"]["payload"], indent=4, compact=True, width=88 33 | ) 34 | format_string += "\n{extra[payload]}" 35 | 36 | format_string += "{exception}\n" 37 | return format_string 38 | -------------------------------------------------------------------------------- /paddlewebocr/pkg/ocr.py: -------------------------------------------------------------------------------- 1 | import os 2 | from paddleocr import PaddleOCR 3 | from PIL import Image 4 | import numpy as np 5 | 6 | 7 | OCR = { 8 | "chinese_cht_mobile_v2.0": PaddleOCR(lang="chinese_cht", 9 | det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer", 10 | cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer", 11 | rec_model_dir="./inference/chinese_cht_mobile_v2.0_rec_infer", 12 | use_gpu=False, total_process_num=os.cpu_count(), use_mp=True, show_log=False), 13 | "ch_ppocr_mobile_v2.0_xx": PaddleOCR(lang="ch", 14 | det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer", 15 | cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer", 16 | rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer", 17 | use_gpu=False, total_process_num=os.cpu_count(), use_mp=True, show_log=False), 18 | "ch_PP-OCRv2_xx": PaddleOCR(lang="ch", 19 | det_model_dir="./inference/ch_PP-OCRv2_det_infer", 20 | cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer", 21 | rec_model_dir="./inference/ch_PP-OCRv2_rec_infer", 22 | use_gpu=False, total_process_num=os.cpu_count(), use_mp=True, show_log=False), 23 | "ch_ppocr_server_v2.0_xx": PaddleOCR(lang="ch", 24 | det_model_dir="./inference/ch_ppocr_server_v2.0_det_infer", 25 | cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer", 26 | rec_model_dir="./inference/ch_ppocr_server_v2.0_rec_infer", 27 | use_gpu=False, total_process_num=os.cpu_count(), use_mp=True, show_log=False) 28 | } 29 | 30 | 31 | def text_ocr(img: Image, ocr_model: str) -> list: 32 | ocr = OCR.get(ocr_model, OCR["ch_ppocr_mobile_v2.0_xx"]) 33 | return ocr.ocr(np.array(img), cls=False) 34 | -------------------------------------------------------------------------------- /paddlewebocr/pkg/util.py: -------------------------------------------------------------------------------- 1 | import random 2 | import base64 3 | from io import BytesIO 4 | from PIL import Image, ImageDraw 5 | 6 | MAX_COMPRESS_SIZE = 1600 7 | 8 | 9 | def compress_image(img: Image, compress_size: int) -> Image: 10 | if compress_size is None or compress_size <= 0: 11 | return img 12 | 13 | if img.height > MAX_COMPRESS_SIZE or img.width > MAX_COMPRESS_SIZE: 14 | scale = max(img.height / MAX_COMPRESS_SIZE, img.width / MAX_COMPRESS_SIZE) 15 | 16 | new_width = int(img.width / scale + 0.5) 17 | new_height = int(img.height / scale + 0.5) 18 | img = img.resize((new_width, new_height), Image.ANTIALIAS) 19 | return img 20 | 21 | 22 | def rotate_image(img: Image) -> Image: 23 | if hasattr(img, '_getexif') and img._getexif() is not None: 24 | orientation = 274 25 | exif = dict(img._getexif().items()) 26 | if orientation in exif: 27 | if exif[orientation] == 3: 28 | img = img.rotate(180, expand=True) 29 | elif exif[orientation] == 6: 30 | img = img.rotate(270, expand=True) 31 | elif exif[orientation] == 8: 32 | img = img.rotate(90, expand=True) 33 | return img 34 | 35 | 36 | def draw_box_on_image(img: Image, texts: list) -> Image: 37 | img_draw = ImageDraw.Draw(img) 38 | colors = ['red', 'green', 'blue', "purple"] 39 | for line in texts: 40 | points = [tuple(point) for point in line[0]] 41 | points.append(points[0]) 42 | # img_draw.polygon(points, outline=colors[random.randint(0, len(colors) - 1)]) 43 | img_draw.line(points, width=4, fill=colors[random.randint(0, len(colors) - 1)]) 44 | return img 45 | 46 | 47 | def convert_image_to_bytes(img: Image) -> bytes: 48 | img_byte = BytesIO() 49 | img.save(img_byte, format='JPEG') 50 | return img_byte.getvalue() 51 | 52 | 53 | def b64encode(bytes_data: bytes) -> str: 54 | return base64.b64encode(bytes_data).decode('utf8') 55 | 56 | 57 | def convert_image_to_b64(img: Image) -> str: 58 | return b64encode(convert_image_to_bytes(img)) 59 | 60 | 61 | def convert_bytes_to_image(bytes_data: bytes) -> Image: 62 | return Image.open(BytesIO(bytes_data)) 63 | 64 | 65 | def convert_b64_to_image(b64_data: str) -> Image: 66 | return Image.open(BytesIO(base64.b64decode(b64_data.encode('utf8')))) 67 | -------------------------------------------------------------------------------- /paddlewebocr/route/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/paddlewebocr/route/__init__.py -------------------------------------------------------------------------------- /paddlewebocr/route/api.py: -------------------------------------------------------------------------------- 1 | from fastapi import APIRouter 2 | 3 | from paddlewebocr.route.v1 import ocr 4 | 5 | api_router = APIRouter() 6 | api_router.include_router(ocr.router, tags=["ocr"]) 7 | -------------------------------------------------------------------------------- /paddlewebocr/route/v1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/paddlewebocr/route/v1/__init__.py -------------------------------------------------------------------------------- /paddlewebocr/route/v1/ocr.py: -------------------------------------------------------------------------------- 1 | import time 2 | import orjson 3 | import logging 4 | from typing import Any 5 | from fastapi import APIRouter, File, UploadFile, Form, status 6 | from fastapi.responses import ORJSONResponse, JSONResponse 7 | from paddlewebocr.pkg.util import * 8 | from paddlewebocr.pkg.ocr import text_ocr 9 | 10 | 11 | class MyORJSONResponse(ORJSONResponse): 12 | media_type = "application/json" 13 | 14 | def render(self, content: Any) -> bytes: 15 | return orjson.dumps(content, option=orjson.OPT_SERIALIZE_NUMPY) 16 | 17 | 18 | router = APIRouter() 19 | 20 | 21 | @router.post('/ocr') 22 | async def ocr(img_upload: UploadFile = File(None), 23 | img_b64: str = Form(None), 24 | compress_size: int = Form(None), 25 | ocr_model: str = Form(None)): 26 | start_time = time.time() 27 | 28 | if img_upload is not None: 29 | img = convert_bytes_to_image(img_upload.file.read()) 30 | elif img_b64 is not None: 31 | img = convert_b64_to_image(img_b64) 32 | else: 33 | return JSONResponse(status_code=status.HTTP_400_BAD_REQUEST, 34 | content={'code': 4001, 'msg': '没有传入参数'}) 35 | 36 | img = rotate_image(img) 37 | img = img.convert("RGB") 38 | img = compress_image(img, compress_size) 39 | 40 | texts = text_ocr(img, ocr_model) 41 | img_drawed = draw_box_on_image(img.copy(), texts) 42 | img_drawed_b64 = convert_image_to_b64(img_drawed) 43 | 44 | data = {'code': 0, 'msg': '成功', 45 | 'data': {'img_detected': 'data:image/jpeg;base64,' + img_drawed_b64, 46 | 'raw_out': list(map(lambda x: [x[0], x[1][0], x[1][1]], texts)), 47 | 'speed_time': round(time.time() - start_time, 2)}} 48 | return MyORJSONResponse(content=data) 49 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | black 2 | mypy 3 | flake8 4 | requests 5 | pytest 6 | pytest-cov 7 | isort 8 | autoflake -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | paddlepaddle==2.2.0 2 | paddleocr==2.3.0.2 3 | fastapi 4 | python-multipart 5 | uvicorn 6 | orjson 7 | loguru 8 | -------------------------------------------------------------------------------- /tests/img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/tests/img1.png -------------------------------------------------------------------------------- /tests/test_img_b64.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import base64 3 | 4 | 5 | def img_to_base64(img_path): 6 | with open(img_path, 'rb')as read: 7 | b64 = base64.b64encode(read.read()) 8 | return b64 9 | 10 | 11 | url = 'http://127.0.0.1:8000/api/ocr' 12 | img_b64 = img_to_base64('./img1.png') 13 | res = requests.post(url=url, data={'img_b64': img_b64}) 14 | 15 | print(res.content.decode('utf-8')) 16 | -------------------------------------------------------------------------------- /tests/test_img_upload.py: -------------------------------------------------------------------------------- 1 | import requests 2 | url = 'http://127.0.0.1:8000/api/ocr' 3 | img1_file = { 4 | 'img_upload': open('img1.png', 'rb') 5 | } 6 | res = requests.post(url=url, data={'compress': 0}, files=img1_file) 7 | 8 | print(res.content.decode('utf-8')) 9 | -------------------------------------------------------------------------------- /webui/.env.example: -------------------------------------------------------------------------------- 1 | PROXY=127.0.0.1:8089 -------------------------------------------------------------------------------- /webui/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /webui/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /webui/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "stage": "vue-cli-service serve --mode stage", 8 | "build": "vue-cli-service build", 9 | "lint": "vue-cli-service lint" 10 | }, 11 | "dependencies": { 12 | "ant-design-vue": "^1.5.3", 13 | "axios": "^0.19.2", 14 | "core-js": "^3.6.4", 15 | "highlight.js": "^10.0.1", 16 | "stylus": "^0.54.7", 17 | "stylus-loader": "^3.0.2", 18 | "vue": "^2.6.11", 19 | "vue-highlightjs": "^1.3.3", 20 | "vue-router": "^3.1.6" 21 | }, 22 | "devDependencies": { 23 | "@vue/cli-plugin-babel": "~4.3.0", 24 | "@vue/cli-plugin-eslint": "~4.3.0", 25 | "@vue/cli-plugin-router": "^4.3.1", 26 | "@vue/cli-service": "~4.3.0", 27 | "babel-eslint": "^10.1.0", 28 | "eslint": "^6.7.2", 29 | "eslint-plugin-vue": "^6.2.2", 30 | "vue-template-compiler": "^2.6.11" 31 | }, 32 | "eslintConfig": { 33 | "root": true, 34 | "env": { 35 | "node": true 36 | }, 37 | "extends": [ 38 | "plugin:vue/essential", 39 | "eslint:recommended" 40 | ], 41 | "parserOptions": { 42 | "parser": "babel-eslint" 43 | }, 44 | "rules": {} 45 | }, 46 | "browserslist": [ 47 | "> 1%", 48 | "last 2 versions", 49 | "not dead" 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /webui/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/webui/public/favicon.ico -------------------------------------------------------------------------------- /webui/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | PaddleWebOCR - 开源的离线 OCR 10 | 11 | 12 | 15 |
16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /webui/src/App.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 39 | -------------------------------------------------------------------------------- /webui/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewangdev/PaddleWebOCR/f75c6322a83f8af081355b963c02ae407af0b592/webui/src/assets/logo.png -------------------------------------------------------------------------------- /webui/src/components/CodeHighlight.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /webui/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import router from './router' 4 | import { 5 | Button, 6 | Layout, 7 | Input, 8 | Row, 9 | Col, 10 | Icon, 11 | Divider, 12 | Upload, 13 | 14 | } from 'ant-design-vue' 15 | import 'ant-design-vue/dist/antd.css'; 16 | import axios from 'axios' 17 | import VueHighlightJS from 'vue-highlightjs' 18 | Vue.use(VueHighlightJS) 19 | 20 | 21 | Vue.use(Button) 22 | Vue.use(Layout) 23 | Vue.use(Input) 24 | Vue.use(Row) 25 | Vue.use(Col) 26 | Vue.use(Icon) 27 | Vue.use(Divider) 28 | Vue.use(Upload) 29 | 30 | 31 | 32 | Vue.config.productionTip = false 33 | 34 | axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; 35 | axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded'; 36 | axios.defaults.transformRequest = [function (data) { 37 | let ret = '' 38 | for (let it in data) { 39 | ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&' 40 | } 41 | return ret 42 | }] 43 | 44 | new Vue({ 45 | router, 46 | render: h => h(App) 47 | }).$mount('#app') -------------------------------------------------------------------------------- /webui/src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueRouter from 'vue-router' 3 | import Index from '../views/Index.vue' 4 | 5 | Vue.use(VueRouter) 6 | 7 | const routes = [ 8 | { 9 | path: '/', 10 | name: 'Index', 11 | component: Index 12 | } 13 | ] 14 | 15 | const router = new VueRouter({ 16 | mode: 'history', 17 | base: process.env.BASE_URL, 18 | routes 19 | }) 20 | 21 | export default router 22 | -------------------------------------------------------------------------------- /webui/src/views/Index.vue: -------------------------------------------------------------------------------- 1 | 102 | 103 | 314 | 315 | 397 | -------------------------------------------------------------------------------- /webui/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // publicPath :'/vue/' 3 | outputDir: 'dist', 4 | // productionSourceMap: true, 5 | configureWebpack: { 6 | devtool: 'source-map' 7 | }, 8 | devServer: { 9 | proxy:{ 10 | '/api':{ 11 | target: 'http://localhost:8000', 12 | changeOrigin:true, 13 | pathRewrite: { 14 | '^/api': '/api' // rewrite path 15 | } 16 | 17 | } 18 | } 19 | 20 | }, 21 | 22 | } --------------------------------------------------------------------------------