Coder Social home page Coder Social logo

opencv-and-tesseract-4's Introduction

Multipage-OCR

Description

This is a simple python script that executes tesseract OCR on a multi-page PDF.

Each page of the PDF is converted into an image, each image is converted to text, and all text files are concatenated to produce the final output.

The script allows you to specify ImageMagick parameters in the image conversion, along with some tesseract parameters for the OCR.

William Wu ([email protected]), 2013 March 9

Python 3

The original script has been updated on 2018 May 20 by Ian Watt to work with Python 3.6+ on Mac OSX. The new version is multipage-ocr_p3.py

If you experience errors at line 121 - convert PDF to image format - you can cure it by running "brew install imagemagick" as I did. See the most popular answer to this StackOverflow question which fixed the error.

Python 2

The original script created by William Wu is unchanged.

Demo

$ python multipage_ocr.py -i input.pdf

Number of pages: 3
/tmp/ocr_44XR0WPHN6
Convert PDF to image: convert -density 300 -depth 8 input.pdf[0] -background white /tmp/ocr_44XR0WPHN6/0.jpg
OCR on image: tesseract -psm 3 /tmp/ocr_44XR0WPHN6/0.jpg /tmp/ocr_44XR0WPHN6/0 quiet
Convert PDF to image: convert -density 300 -depth 8 input.pdf[1] -background white /tmp/ocr_44XR0WPHN6/1.jpg
OCR on image: tesseract -psm 3 /tmp/ocr_44XR0WPHN6/1.jpg /tmp/ocr_44XR0WPHN6/1 quiet
Convert PDF to image: convert -density 300 -depth 8 input.pdf[2] -background white /tmp/ocr_44XR0WPHN6/2.jpg
OCR on image: tesseract -psm 3 /tmp/ocr_44XR0WPHN6/2.jpg /tmp/ocr_44XR0WPHN6/2 quiet
Concatenate OCR outputs: cat /tmp/ocr_44XR0WPHN6/0.txt /tmp/ocr_44XR0WPHN6/1.txt /tmp/ocr_44XR0WPHN6/2.txt > input_ocr.txt
Cleanup temporary files: rm -r /tmp/ocr_44XR0WPHN6

Requirements

System requirements: tesseract, pypdf

To install tesseract on Mac OS X:

$ brew install tesseract

To install pypdf:

$ pip install pypdf

To install imagemagick

$ brew install imagemagick

opencv-and-tesseract-4's People

Contributors

willywutang avatar greatbahram avatar watty62 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.