4

I want to scan hundreds of A4 papers, but I don't have a scanner.

I have a good camera though, so I:

  1. Put the paper on the floor
  2. Focus powerful lights on it (including sunlight)
  3. With the camera, zoom in to reduce distortion
  4. Take a picture from far above

I end up with a whole folder of JPG files that have the following problems:

  • Cushion distortion
  • White is rather grey-yellow
  • Margins around the paper

I am looking for a program that can, for each image, automatically:

  • Detect and fix the cushion distortion and non-orthogonal angle
  • Detect and fix the rotation
  • Guess where the white is and make it really white, to make the result more beautiful and increase compressibility, without reducing readability
  • Detect and crop out the margin, so that the resulting file is the same shape as the paper. Paper border can always be guessed by seeing the shadows and differences in colour.

Requirements:

  • Can run automatically on the folder of images, no human manipulation needed
  • Free, ideally open source
  • Run on Ubuntu Linux

Any sensible output format is fine, for instance PNG or PDF.
It can be GIMP-based if it is runnable from command-line or can otherwise process hundreds of JPG files without human intervention.

7
  • Just being curious: how shall that work "without human intervention"? Can the camera flip pages? Maybe I miss something here ;) I guess your requested Android solution is the better (and easier) approach, at least if you have no scanner.
    – Izzy
    Feb 29, 2016 at 6:59
  • @Izzy: Is it clearer now? Thanks :-)
    – Nicolas Raoul
    Feb 29, 2016 at 7:11
  • Ah – you don't mean the scan but the processing of results. OK, keywords: unpaper. Again, never tried it (I have a scanner). Often used when scanning entire books, so batch-mode is its default. Should do all of "the above" IIRC (distortion fix, crop, color/contrast, etc.) and I remember howtos where it was part of an entire OCR process. Ah yeah, see Wikipedia (OCRFeeder, mentions the use and purpose of unpaper plus a link). unpaper is in most repos AFAIK, so easy to find.
    – Izzy
    Feb 29, 2016 at 7:17
  • @Izzy: unpaper is designed for flatbed scanners, so it does not reduce distortion, it seems.
    – Nicolas Raoul
    Feb 29, 2016 at 7:26
  • 1
    There is a very good blog post at pyimagesearch.com/2014/09/01/… which gives you the code to do all that you are asking for using python and OpenCV. Linux/Windows/Android - Gratis & Open Source Feb 29, 2016 at 17:32

1 Answer 1

0

i tried some of the solutions proposed in the comments to the OP. below are my comments:

  1. unpaper - by and large it didn't work for me. works well with pbm images (black and white) but getting a good pbm initial image was impossible for me.
  2. this solution based on cv2 and skimage worked fine. merge the python code across the article and run it. note you don't need pyimagesearch module (it is proprietary and paid), the code for the function four_point_transform is provided here. i had to play with arguments of some methods (threshold_local, cv2.Canny) to get a good result.
1
  • Great! Any chance you can publish your code somewhere? :-)
    – Nicolas Raoul
    Oct 31, 2022 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.