Giter Club home page Giter Club logo

docproj's Introduction

DocProj

The source code of Document Rectification and Illumination Correction using a Patch-based CNN by Xiaoyu Li, Bo Zhang, Jing Liao, Pedro V. Sander, SIGGRAPH Asia 2019.

Prerequisites

  • Linux or Windows
  • Python 3
  • CPU or NVIDIA GPU + CUDA CuDNN

Geometric Rectification

Dataset Generation

We use Blender to automatically generate synthetic distorted document image and the corresponding flow.

You can download a small dataset with 20 samples (438MB) from here for fun and the full dataset with 2450 samples (65GB) from BitTorrent or from OneDrive.

The dataset includes three folders:

  • img (the distorted images, with the shape of [2400, 1800, 3])
  • img_mask (the mask of background, with the shape of [2400, 1800])
  • flow (the forward flow of the distorted images, with the shape of [2, 2400, 1800])

The first thing you need to do is to crop the dataset to patches for training. Change arguments to your own and run the following commands. For help message about optional arguments, run python xxx.py --h

python local_patch.py   # crop images and flows to local patches and local patch flows
python global_patch.py  # crop images to global patches

Training

Run the following command for training and change the optional arguments like dataset directory, etc.

python train.py

Use a Pre-trained Model

You can download the pre-trained model here.

Run the following command for resizing and cropping the test document image to local and global patches and estimating the patch flows:

python eval.py [--imgPath [PATH]] [--modelPath [PATH]]
               [--saveImgPath [PATH]] [--saveFlowPath [PATH]]
               
--imgPath             Path to input image
--modelPath           Path to pre-trained model
--saveImgPath         Path to saved cropped image
--saveFlowPath        Path to saved estimated flows

Stitch flow

Download the Windows executable program here to stitch the patch flows to get the image flow.

Run the following command:

Graphcut.exe [Input Path] [Output Path]

[Input Path] is the path to input patch flows with the shape of [yNum, xNum, 2, patchH, patchW], where yNum and xNum are the number of patch in y and x direction, patchH and patchW are the height and width of a local patch.

[Output Path] is the path to the output stitched flow with the shape of [2, H, W].

Notes: The path should be absolute path with "//" due to the path parse function in the program. e.g. "H://Release//test data//2_patchFlows.npy"

Resampling

Import resampling.rectification function to resample the distorted image by the stitched flow.

The distorted image should be a Numpy array with the shape of [H, W, 3] for a color image or [H, W] for a greyscale image, the stitched flow should be an array with the shape of [2, H, W].

The function will return the resulting image and a mask to indicate whether each pixel will converge within the maximum iteration.

To help you follow all these steps, we also give an example with all the intermediate results here in the test data folder.

Illumination Correction

Training

Run the following command and change the optional arguments for training.

python train_illumination.py

Use a Pre-trained Model

You can download the pre-trained illNet model here and pre-trained vgg model here.

Run the following command for testing:

python eval_illumination.py [--imgPath [PATH]] [--savPath [PATH]] [--modelPath [PATH]]
                            
--imgPath             Path to input image
--savPath             Path to saved output
--modelPath           Path to pre-trained model

docproj's People

Contributors

aishmittal avatar xiaoyu258 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docproj's Issues

pre_trained model dont work well on your paper data

Hello! I used your geometry_model to correct distorted images. I followed your doc and tried the test_data, everything is just right.
But then I used images from your paper, it cant get the similar result. It looks like just resized it and changed little.

input

8

output
8_result

GPU个数

请问那个光照矫正模型训练最少需要几个GPU??

patchFlows to stitchedFlow

I dont know how to run this graphcut,can you give me some suggestions plz
1682321061254
Click .exe directly come up a problem like this.
1682321047200

Generate dataset with Blender

Hello, I'm trying to generate dataset for my own images, but got stuck on extracting the texture coordinates when given camera view coordinates. So I wonder if you are planning to open source your scripts for dataset generating?
If not, could you please give some hints on how to transform the pixel coordinates in rendered image to the UV coordinates?
Thank you !

Source code

Hi!

Do you plan you open up the source code before conference?

Thanks!

about the train dataset

The dewarp result in your paper is excellent. However, the links of pre-trained model and dataset are all invalid, i also try to use Blender to generate synthetic distorted document image, it is hard for me to master the software. so, could you please provided the dataset and pre-trained model again, very appreciated for your kindly reply !

torchvision import _C ERROR

Hello every one i trained the illumnation model on my dataset and when i tried to run the evaluation i am getting this error:

from torchvision import _C
ImportError: DLL load failed: Le module spécifié est introuvable.

torch version 1.1.0

The dataset doesn't have the original scanned image

Hi,
when I follow your work, I find that the dataset you provide donesn't incorporate the scanned images, which are used as gorund truth to train the illumination correction network.
Could you release this datavset

Thank you!

Stitching The Flows

Hi,
I tried the stitching the tool in windows. It worked. However, I went thoroughly through the paper for how the stitching works. Can you suggest some good direction on how that can be implemented efficiently like you had the binaries in windows? This project is really intriguing. Thanks.

resampling of sample data

I just used the sample data with ground truth npy, and use the resampling.py to unwarp the imgs. The results are not good. The background cannot be cropped.
image

Graphcut.exe can not work.

Excellent work for document rectification!

But I got some problem when using the Graphcut.exe to get the stitchedFlow.npy
terminal as this:
PS D:\abpycharm\DocProj\Stitching> .\Graphcut.exe "\test data\2_patchFlows.npy" "\test data\5.npy"
\test data\2_patchFlows.npy
\test data\5.npy
flow dir: \test data\2_patchFlows.npy

But there is no 5.npy generated. I confirmed that 2_patchFlows is regulatory size as[11,8,2,256,256]
Please help me !

numba cann't run

Thanks for your work.
Can you share the version of numba, numpy and skimage?
my local version:
numpy:1.14.0
skimage:0.13.1
numba:0.38.0

Using @cuda.jit, a error occurred.
`numba.cuda.cudadrv.error.NvvmError: Failed to compile

libnvvm : error: -arch=compute_61 is an unsupported option
NVVM_ERROR_INVALID_OPTION`
I try to update numba to the lasest, but it requires the version of numpy laster than 1.15.0, so skimage is not compitable

The model does not work well

   I use your pre_trained model to inference the my data and the small dataset,the results are not so good.And I use the small dataset to train a new model,I use the new model to infenrence one of the imgs in the dataset,it is not effective ether.Can you tell me the reason,What do i need to pay attention to?
  Looking forward to your reply,thanks a lot!

000_2_result
000_3_result

Blender instruction

Hi @xiaoyu258

Thanks for sharing the code. Could you share more details of how to use blender to render the surface flow? so that we can introduce our own dataset for training, thanks

which version used for numba

we face issue in executing: resampling.py
my numba lib version is 0.51.2
OS: Windows 10
Python 3.7

Error :
Traceback (most recent call last):
File "resampling.py", line 203, in
resImg, resMsk = rectification(distortedImg, flow)
File "resampling.py", line 194, in rectification
iterSearch[blockspergrid, threadsperblock](padu, padv, paddistorted, resultImg, maxIter, precision, resultMsk)
File "C:\Users\testing\AppData\Local\Programs\Python\Python37\lib\site-packages\numba\cuda\compiler.py", line 770, in call
self.stream, self.sharedmem)
File "C:\Users\testing\AppData\Local\Programs\Python\Python37\lib\site-packages\numba\cuda\compiler.py", line 861, in call
kernel = self.compile(argtypes)
File "C:\Users\testing\AppData\Local\Programs\Python\Python37\lib\site-packages\numba\cuda\compiler.py", line 935, in compile
kernel.bind()
File "C:\Users\testing\AppData\Local\Programs\Python\Python37\lib\site-packages\numba\cuda\compiler.py", line 576, in bind
self.func.get()
File "C:\Users\testing\AppData\Local\Programs\Python\Python37\lib\site-packages\numba\cuda\compiler.py", line 446, in get
ptx = self.ptx.get()
File "C:\Users\testing\AppData\Local\Programs\Python\Python37\lib\site-packages\numba\cuda\compiler.py", line 414, in get
arch = nvvm.get_arch_option(*cc)
File "C:\Users\testing\AppData\Local\Programs\Python\Python37\lib\site-packages\numba\cuda\cudadrv\nvvm.py", line 345, in get_arch_option
return 'compute
%d%d' % arch
TypeError: not enough arguments for format string

Looks to me this might be a version mismatch issue
can someone help with which version we need to use in the window and Linux?
Batter if provided all prerequisite lib name and version that needed that might help.

Split dataset with smaller size

I have trouble to download the dataset files due to big size and always timeout during download. @xiaoyu258 could you please split dataset to smaller size pieces, say 5GB?

performance of the illumination network

Hi, thanks for your solid work.

I test the illumination network using some geometric rectified images. The results are not very well as in paper.
Like the following examples:

63_1 copy_rec
63_1 copy_rec_rec_ill

47_2 copy_rec
47_2 copy_rec_rec_ill

3_1 copy_rec
3_1 copy_rec_rec_ill

We check the code is right:
0_input
0_input_rec_rec_ill

I don‘t know what is the problem.
Thank you!

DocProj blender file

@xiaoyu258
it's better that you upload the blender file, so that we can generate using our own images.
So that you wont need to upload the entire 65GB dataset. The blender file will be enough.

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.