eihli / image-table-ocr Goto Github PK
View Code? Open in Web Editor NEWTurn images of tables into CSV data. Detect tables from images and run OCR on the cells.
License: MIT License
Turn images of tables into CSV data. Detect tables from images and run OCR on the cells.
License: MIT License
When i run
python -m table_ocr.demo https://raw.githubusercontent.com/eihli/image-table-ocr/master/resources/test_data/simple.png
i get
pytesseract.pytesseract.TesseractError: (1, 'Error opening data file C:UsersGetyAppDataLocalProgramsPythonPython38libsite-packagestable_ocrtessdata/table-ocr.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'table-ocr\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')
(note file path does not have '/')
File does exist
I tried setting env variable TESSDATA_PREFIX - same error.
as well as specifying path in cli python -m table_ocr.demo https://raw.githubusercontent.com/eihli/image-table-ocr/master/resources/test_data/simple.png --tessdata-dir C:\Users\Btycoon\AppData\Local\Programs\Python\Python38\Lib\site-packages\table_ocr\tessdata
I am on Windows 10.
hey, I m not able to extract table that continues from one page to another as one table using the tools here:
Life_Cycle_Assessment_of_Cow_Tanned_Leather_Produc.pdf
can someone help?
Traceback (most recent call last):
File "/opt/anaconda3/envs/Hyper-Table-Recognition/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/opt/anaconda3/envs/Hyper-Table-Recognition/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/chouroukhelaoui/PycharmProjects/image-table-ocr/table_ocr/demo/main.py", line 51, in
csv_output = main(sys.argv[1])
File "/Users/chouroukhelaoui/PycharmProjects/image-table-ocr/table_ocr/demo/main.py", line 34, in main
for cell in cells
File "/Users/chouroukhelaoui/PycharmProjects/image-table-ocr/table_ocr/demo/main.py", line 34, in
for cell in cells
File "/Users/chouroukhelaoui/PycharmProjects/image-table-ocr/table_ocr/ocr_image/init.py", line 33, in main
txt_file.write(txt)
UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 15: ordinal not in range(128)
in some cases, we get this issue it can't be fixed by adding this line of code in "/image-table-ocr/table_ocr/ocr_image /init.py" line 32 :
txt = txt.encode('ascii', 'ignore').decode('ascii')
We use the below config to get the table ocr, but there is no way to get hocr of the image. can someone add this feature please?
d = os.path.dirname(sys.modules["table_ocr"].__file__) tessdata_dir = os.path.join(d, "tessdata") tess_args = "--psm 6 -l table-ocr --tessdata-dir {0}".format(tessdata_dir)
Hi, glad that I found this. Kudos to the developers first of all. I was just wondering if you can provide an end to end descriptive steps from input PDF to output CSV. It's not exactly clear from the shell script you gave. Thanks!
Dear Eihli, Your program will help me in the future for personal porposes. I am running it on Win 10. I foolow all the steps to simply extract datas from images but I don't find why it does not run through it.
Here is the message after I run py -m table_ocr.demo https://raw.githubusercontent.com/eihli/image-table-ocr/master/resources/test_data/simple.png
Running extract_tables.main([C:\Users\MAGICB~1\AppData\Local\Temp\demo_cp3ejb98\simple.png]).
Extracted the following tables from the image:
[('C:\Users\\AppData\Local\Temp\demo_cp3ejb98\simple.png', ['C:\Users\\AppData\Local\Temp\demo_cp3ejb98\simple\table-000.png'])]
Processing tables for C:\Users*\AppData\Local\Temp\demo_cp3ejb98\simple.png.
Processing table C:\Users*\AppData\Local\Temp\demo_cp3ejb98\simple\table-000.png.
Traceback (most recent call last):
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 255, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users*****\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users*****\AppData\Local\Programs\Python\Python39\lib\site-packages\table_ocr\demo_main.py", line 51, in
csv_output = main(sys.argv[1])
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\site-packages\table_ocr\demo_main_.py", line 32, in main
ocr = [
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\site-packages\table_ocr\demo_main_.py", line 33, in
table_ocr.ocr_image.main(cell, None)
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\site-packages\table_ocr\ocr_image_init_.py", line 31, in main
txt = ocr_image(cropped, " ".join(tess_args))
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\site-packages\table_ocr\ocr_image_init_.py", line 83, in ocr_image
return pytesseract.image_to_string(
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 409, in image_to_string
return {
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 412, in
Output.STRING: lambda: run_and_get_output(args),
File "C:\Users*\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 287, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users**\AppData\Local\Programs\Python\Python39\lib\site-packages\pytesseract\pytesseract.py", line 259, in run_tesseract
raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.
I have tesseract installed so I donnot get it:
PS C:\Users*\AppData\Local\Programs\Python\Python39> py -m pip install tesseract
Requirement already satisfied: tesseract in c:\users*\appdata\local\programs\python\python39\lib\site-packages (0.1.3)
Thanks for your help.
Eddy
Hello, I open this question because I need help. May you please help me?
I cloned the repository and following your read.me I managed to run your demo (Image 1 shows successful execution).
However, I have some issues.
So I can't run for any link.
Questions:
Thank you and I look forward to your return.
Alessandra Jandrey
Can you please share the setup instructions getting below error
"pytesseract.pytesseract.TesseractError: (1, 'Error opening data file C:\Users\Ankur.Biswal\AppData\Local\Tesseract-OCR\tessdata/tessdata/eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory. Failed loading language 'eng' Tesseract couldn't load any languages! Could not initialize tesseract.')"
Hi,
I run the following demo command
python3 -m table_ocr.demo https://raw.githubusercontent.com/eihli/image-table-ocr/master/resources/test_data/simple.png
on Windows but got the following error:
raise TesseractError(proc.returncode, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (1, 'Error opening data file C:UsersjackylamAppDataLocalPackagesPythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0LocalCachelocal-packagesPython310site-packagestable_ocrtessdata/table-ocr.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language 'table-ocr' Tesseract couldn't load any languages! Could not initialize tesseract.')
I set TESSDATA_PREFIX and point to somewhere containing the table-ocr.traindata but no use.
However, the above problem doesn't happen on Linux. As my project prefer to run on Windows, hope someone can give me some hint on this issue.
Thanks,
Sing
first, thanks for this package its look amazing.
what is the version that i should install of:
Hello. Can I ocr local images and other files?
Dear @eihli ,
Thank you very much for your project. It works great!
I have not fully understood your detection algorithms yet, but I think there is this issue, which would be great to improve the accuracy of your package. I noticed that in the case some columns are merged, the program will cut it followed by the major columns. Besides, your program works well in case of rows are merged:
Here is the example:
The extract_cell_images_from_table
method 's results:
I will take a look deeper into the code, meanwhile, I think it's better to report this to you so that the library can be enhanced in the future.
Asides from this minor issue, your library is awesome.
Thanks again and best regards
Hello, thanks for this repo!
It's a bit hard to understand how to get it working when you simply start with a PNG image and want to give it a try. So I'm trying with a sample file you're giving.
I run
python -m table_ocr.extract_tables resources/examples/example-page-table-000.png | grep table > /tmp/extracted-tables.txt
cat /tmp/extracted-tables.txt | xargs -I{} python -m table_ocr.extract_cells {} | grep cells > /tmp/extracted-cells.txt
cat /tmp/extracted-cells.txt | xargs -I{} python -m table_ocr.ocr_image {} --psm 7 -l table-ocr
and I get
pytesseract.pytesseract.TesseractError: (1, 'Error opening data file /usr/share/tessdata/table-ocr.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'table-ocr\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')
I don't understand is how to get the table-ocr.traineddata
file that tesseract seems to be looking for?
Thanks again
Hi - thank you for creating this - it really looks useful!
When I try pip3 install table_ocr
followed by python3 -m table_ocr.demo https://raw.githubusercontent.com/eihli/image-table-ocr/master/resources/test_data/simple.png
I always get the same problem - No module named 'table_ocr'
The installation runs successfully, all the dependencies are installed.
Happens both on Windows and Mac. Am I missing something?
Attempting to OCR a table and I keep getting an error.
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/table_ocr/pdf_to_images/init.py", line 69, in preprocess_img
rotate = get_rotate(filepath, tess_params)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/table_ocr/pdf_to_images/init.py", line 79, in get_rotate
subprocess.check_output(tess_command)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['tesseract', '--psm', '0', '--oem', '0', '/Users/andrewmcfadden/Documents/GitHub/one2many.github.io/image-table-ocr/dance/ga-20190131-001.png', '-']' returned non-zero exit status 1.
It's hard to use.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.