Function similar to Document Scanner. Given images of A4 paper sheets, output paper sheets' four corners as well as four edges and their equations. Then crop the background and leave the paper sheet in proper position and standard scaling. We can do this in three steps. Firstly, detect edges with hough transform. Then store the corners in order. Lastly, apply a perspective transform to warp the image.
For more details about the theory, implementation, results and improvement, please read my post.
Any feedback is welcomed!
Handwritten Digits Recognition
I test on Visual Studio 2015, C++11. Here's the guide for Using Eigen with Microsoft Visual Studio:
EIGENDIR
(e.g. F:\eigen3.3.3
)EIGENDIR
in VS Project(Project->Properties->C/C++->General->Additional Include Directories->F:\eigen3.3.3;)Simply download this repository, compile and run. Change the parameter CASE
in main.cpp
to choose different datasets.
Here I have two datasets prepared by Kun Zeng for test. (All results also have been generated in corresponding folders)
dataset1
: 16 A4 paper sheets with diverse contents. Placed with different angles and in different background. Some of them are lack of one corners. The resolution of each image is 400px*539px
or 539px*400px
.dataset2
: 5 sticky notes or small paper sheets with digits. Placed with different angles and in different background. The resolution of each image is 922px*692px
or 692px*922px
.400px~700px
for smaller side). The default parameters should works well for proper size.bmp
format (e.g. convert by ImageMagick)main.cpp
.Error cases guide
in the end of main.cpp
and tune the parameters in Hough.cpp
.By default, the results *_marked.bmp
(marked with paper corners and edges) and *_A4.bmp
(cropped paper sheet in A4 paper size) of each images will be saved in the same folder of the test dataset. The intermediate results of blur
, gradients
and hough_space
will be displayed but not saved. You can set this in constructor Hough::Hough()
of Hough.cpp
.
Here I take two examples from two datasets. The intermediate process is shown.
NO.14 image (scale by 45%)
NO.4 image (scale by 40%)