This is a basic but usable Example of python script that allows to convert a pdf of scanned documents (images), extract tables from each pdf page using image processing, and using OCR extract the table data into into one CSV file, while keeping correct table structure.
This code has quite a bit assumptions (the table is largest object in the pages), but it can be useful to convert printed excel tables back into digital copy
install the following Packages (versions the script was developed on)
- python 3.6
- tesseract-ocr 4.0.0
- opencv 3.4.4
- pip requirements.txt
usage:
python pdf-to-csv-cv.py -p test.pdf
this will create test.pdf.csv output file
3. find largest contour with largest area (hopefully our table), fix perspective using four point transform
The performance is mostly affected by the OCR package, both speed and accuracy, feel free to play with tesseract flags
Vitali Mogilevsky
wtfpl - see the LICENSE file for details