Coder Social home page Coder Social logo

tangmissmoon / chinese-pdf-ocr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from newcomer00/chinese-pdf-ocr

0.0 0.0 0.0 29.66 MB

🔎📖对中文PDF进行OCR | OCR for Chinese PDF file using API from DayBreak-u/chineseocr_lite

License: GNU General Public License v2.0

JavaScript 41.75% Python 36.11% CSS 2.99% HTML 19.15%

chinese-pdf-ocr's Introduction

zh en

chinese-pdf-ocr

对中文PDF文件进行OCR。使用了DayBreak-u/chineseocr_lite的OCR模型。

assets/demo.png assets/demo_web.png

项目目录结构

  • chineseocr_lite/
    引用自DayBreak-u/chineseocr_lite实现的轻量级中文OCR模型。
  • pdfocr.py
    对PDF文件进行OCR的核心逻辑。先对PDF某一页进行OCR,基于识别结果使用图形学算法对PDF该页划分段落,最后把OCR结果按段落组合。
  • requirements.txt
    记录了chineseocr_lite/pdfocr.py所需要的Python包。
  • demo_gui/
    一个简单的小程序。对给定的PDF的若干页进行OCR,然后将结果输出至终端,并在新的窗口中可视化显示当前页面的OCR结果。
  • demo_web/
    在浏览器上运行的网页应用。可以在网页上打开PDF进行OCR,鼠标点击识别结果可以将OCR文字复制到剪贴板。

安装基础依赖包

项目目录下的requirements.txt 记录了chineseocr_lite/pdfocr.py所需要的Python包。执行以下命令来安装:

pip3 install -r requirements.txt

运行demo_gui

切换目录

cd demo_gui/

安装poppler

用于PDF转图片,被Python的pdf2image包使用。各平台的安装方法

安装额外的依赖包

demo_gui/requirements.txt 记录了demo_gui/所需要的额外Python包。执行以下命令来安装:

pip3 install -r requirements.txt

运行主程序

python3 main.py --file <PDF文件路径> --start <OCR开始页码> --end <OCR结束页码>

📘 示例
对当前目录下的1.pdf文件进行OCR,页码从150开始,到155结束。

python3 main.py --file ./1.pdf --start 150 --end 155

效果图

点击识别后的图片,然后按键盘上任意键即可识别下一页。 效果图

运行demo_web

切换目录

cd demo_web/

安装额外的依赖包

本示例使用了Flask包来编写Python网页后端。

pip3 install -r requirements.txt

运行主程序

python3 main.py

访问网页

要访问该服务,在浏览器中输入如下网址(无需互联网连接):

http://127.0.0.1:5000

默认情况下,该服务只能通过本机地址127.0.0.15000端口访问。如果需要让局域网内的其它设备也能访问该网页,或是需要不同的端口号,请将demo_web/main.py的最后一行修改为:

app.run(host='0.0.0.0', port=<端口号>)

⚠️注意:
本服务使用了Flask自带的网页服务器。该服务器仅供开发使用,不能在实际生产环境中使用。如需将服务发布在公网,可以参考我的另一个项目NJUST_HomeworkCollector

效果图

打开网页后,先点击左上角的Upload PDF按钮上传PDF文件到本机浏览器。然后点击PreviousNext按钮切换PDF上/下页。最后点击右上角的OCR按钮,对当前页进行OCR。识别到的文本会由红框标出,点击对应的方框即可复制其中的文字。双击Page:后的当前页码,可以编辑并跳转到指定页。 web效果图

chinese-pdf-ocr's People

Contributors

newcomer00 avatar

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.