mzucker / page_dewarp Goto Github PK
View Code? Open in Web Editor NEWText page dewarping using a "cubic sheet" model
Home Page: https://mzucker.github.io/2016/08/15/page-dewarping.html
License: MIT License
Text page dewarping using a "cubic sheet" model
Home Page: https://mzucker.github.io/2016/08/15/page-dewarping.html
License: MIT License
Hello, I have ran the code as mention in comments using python page_dewarp.py Img.
Following error occurred after running the code.
python page_dewarp.py IMG_20190717_114448.jpg
loaded IMG_20190717_114448.jpg with size 2250x4000 and resized to 375x667
Traceback (most recent call last):
File "page_dewarp.py", line 915, in
main()
File "page_dewarp.py", line 867, in main
cinfo_list = get_contours(name, small, pagemask, 'text')
File "page_dewarp.py", line 450, in get_contours
cv2.CHAIN_APPROX_NONE)
ValueError: need more than 2 values to unpack
Very nice project. However, I just can't make it work because of missing cv2 requirement (and possibly others):
Traceback (most recent call last):
File "../page_dewarp.py", line 15, in <module>
import cv2
ImportError: No module named cv2
Perhaps you could add a requirements.txt file to your repo?
I'm trying to run the script but it gives me an "invalid syntax" error at line 739 print ' initial objective is', objective(params)
.
I'm using Python 3.5 (I installed WinPython with scipy, numpy and pillow) and OpenCV 3.2, which I installed following the instructions found here: https://pythonarena.wordpress.com/2016/03/07/scientific-python-on-windows/
Sorry for the silly question, but how is this used? I appear to have this and all requirements in place, but I don't follow how to actually use it on an image.
Hi Matt,
I'm working on C++ version of this code. Only optimization of reprojection error left to translate. Could you suggest C++ library that could help in this problem? I'm looking for solver to translate lines 731-748 into C++. I tried dlib, now struggling with Ceres Solver. Do you have any suggestion?
Best regards
Artur
I have been using this using the command line python page_dewarp.py image.jpg with the included images successfully but when using an image of my own I could see that the text is cropped and cut.
The image was a 2MB jpeg with the resolution of 3400x4600px
This is the original and the resulted image:
Do you know what might be the problem? Thanks
Hi,
Thanks for such an interesting implementation. I have got some doubts while I trying to implement on my image,
I couldn't get any better output. I found most of my images got rotation error, can you suggest me from which part of the code I get the angle of rotation, so I can easily rotate it.
Thanks
Sorry I cannot get this to work, and there is nothing in the readme about additional values?
Cheers for any help you can give me
loaded boston_cooking_a.jpg with size 2448x3264 and resized to 490x653
Traceback (most recent call last):
File "../page_dewarp.py", line 915, in
main()
File "../page_dewarp.py", line 867, in main
cinfo_list = get_contours(name, small, pagemask, 'text')
File "../page_dewarp.py", line 450, in get_contours
cv2.CHAIN_APPROX_NONE)
ValueError: need more than 2 values to unpack
Greate job,but how can I generate pagewarping images? Can you provide the generated code?
Thanks for great work @mzucker , I try to dewarp line in page, I think algorithm work well, but output of dewarp not in the same location. I wish to dewarp the same position output. How to config it. Thanks in advance
left is keypoint detection and optimization, right is output dewarp(but location change)
I have attached the script makes page_dewarp.py compatible with python 3 for anyone looking for this, like I was.
Just save as .py and it should work!
Debug makes the process of this algorithm so clear
I created a virtualenv and tried to install in it like below:
$ pip install -r ./requirements.txt
Collecting page_dewarp
Downloading page_dewarp-0.1.5-py3-none-any.whl (23 kB)
Collecting numpy
Using cached numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
Collecting scipy
Downloading scipy-1.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (38.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 38.6/38.6 MB 13.9 MB/s eta 0:00:00
Collecting Image
Downloading image-1.5.33.tar.gz (15 kB)
Preparing metadata (setup.py) ... done
ERROR: Could not find a version that satisfies the requirement cv2>=3.0 (from versions: none)
ERROR: No matching distribution found for cv2>=3.0
Python version:
$ python3 --version
Python 3.10.12
Could you please tell me how to set the parameters for better Chinese recognition? I have tried recognizing English, and it works quite accurately, but recognizing Chinese is more challenging
The code works fine for a some of my own images, but for a few images I get this TypeError:
Traceback (most recent call last):
File "page_dewarp.py", line 918, in
main()
File "page_dewarp.py", line 871, in main
spans = assemble_spans(name, small, pagemask, cinfo_list)
File "page_dewarp.py", line 493, in assemble_spans
candidate_edges.sort()
TypeError: '<' not supported between instances of 'ContourInfo' and 'ContourInfo'
I tried to run this, but python 2 is deprecated, cv2 is not in pip anymore, there is opencv-python, but when I installed that and other dependences, I get errors...
╰─➤ page_dewarp.py example_input/boston_cooking_a.jpg
loaded boston_cooking_a.jpg with size 2448x3264 and resized to 490x653
Traceback (most recent call last):
File "page_dewarp.py", line 1001, in <module>
main()
File "page_dewarp.py", line 954, in main
cinfo_list = get_contours(name, small, pagemask, "text")
File "page_dewarp.py", line 489, in get_contours
mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE
ValueError: need more than 2 values to unpack
I apologize for the probably stupid question: how to use the program in Windows 7? There are no installation files ...
(Google Translate).
First all print statements need to be converted from print "" to print()
floating point errors here:
561 wrap values in int() due to floating point error
795 int(width...)
796 int(height....)
general errors which need handling
some text is white washed away
Traceback (most recent call last):
File "page_dewarp.py", line 915, in
main()
File "page_dewarp.py", line 868, in main
cinfo_list = get_contours(name, small, pagemask, 'text')
File "page_dewarp.py", line 470, in get_contours
contours_out.append(ContourInfo(contour, rect, tight_mask))
File "page_dewarp.py", line 376, in init
self.center, self.tangent = blob_mean_and_tangent(contour)
File "page_dewarp.py", line 352, in blob_mean_and_tangent
mean_x = moments['m10'] / area
ZeroDivisionError: float division by zero
apparently area can be 0 so we need to protect against this
If area==0:
area=1
Resizing the image resulted in problems for me, so I nulled it out with img=src
At https://github.com/mzucker/page_dewarp/blob/master/page_dewarp.py#L16 you see import Image
.
Pillow doesn't expose a top level Image class in sys.modules -- it is only available under the PIL module.
Changing the line to from PIL import Image
from import Image
should be backwards compatible with both PIL and Pillow.
It's a very nice project you have here.
I tried to run the project on ArchLinux with opencv 4 installed and with a virtualenv just for page_dewarp and I get the following error:
(venv) $ python page_dewarp.py example_input/boston_cooking_a.jpg
loaded boston_cooking_a.jpg with size 2448x3264 and resized to 490x653
Traceback (most recent call last):
File "page_dewarp.py", line 915, in <module>
main()
File "page_dewarp.py", line 867, in main
cinfo_list = get_contours(name, small, pagemask, 'text')
File "page_dewarp.py", line 450, in get_contours
cv2.CHAIN_APPROX_NONE)
ValueError: need more than 2 values to unpack
Any idea?
Thank you for building this software but I cannot figure out how to install it. 99% of the time software comes with pip install instructions, for that 1% of the time when the software does not I have a very difficult time getting it to work.
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.