'Is there a way to automatically dewarp/uncurl/flatten warped/distorted scanned document images in C#?

I'm trying to automatically dewarp scanned document images using C#.

The Situation:

I have images of a 6 page empty form (every page is different). I also have scanned images of the same form but with real data filled in the form fields.

The Problem:

The scanned images of the filled form are warped/curled in a weird way. Please see image.

What I'm trying to achieve:

I'm trying to flatten/dewarp the scanned images so that the text lines become straight. Please see image.

Things I've tried:

  • Using the EmguCv library to do feature matching between the scanned image and the original image I have then using CvInvoke.WarpPerspective. That didn't give me very accurate results due to the nature of the image which doesn't allow me to get a lot of matches in some areas. Link I've used
  • Use the EmguCv library to find the border of the document inside the image then do CvInvoke.WarpPerspective. That didn't work because when I convert the border to a rectangle and warp the perspective, the result since the border is NOT a rectangle, it's like a cylinder almost.

This is a sample of what the distorted image looks like

This is a sample of what the final result image should look like



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source