Coder Social home page Coder Social logo

rohanrao619 / aadhaar_ocr Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 2.0 24.8 MB

Extraction, Verification and Masking of Aadhaar UIDs from photos and scanned documents.

License: MIT License

Jupyter Notebook 100.00%
computer-vision ocr pytesseract esrgan aadhaar

aadhaar_ocr's Introduction

Aadhaar OCR

Extraction, Verification and Masking of Aadhaar UIDs from photos and scanned documents.

Solution

The solution to the problem involves use of PyTesseract Optical Character Recognition engine and OpenCV for image processing. It can be divided into 3 Sub-Tasks:

  1. Extracting Aadhaar UID from photo using Tesseract.
  2. Verifying the extracted Aadhaar UIDs.
  3. Masking the first 8 digits of detected UIDs.

Extracting Aadhaar UIDs

This task can be further divided into 2 Sub-Tasks:

  1. Preprocess the image and then use PyTesseract library to extract all recognizable text from the image with their corresponding bounding boxes.
  2. Use RegEx Search to find possible UID candidates. Aadhaar contains 12 numeric digits, so any 12-digit no. in the text returned by the OCR engine can be a possible UID.

The problem now is that image may need some pre-processing before it is possible to extract text from it. There are may factors affecting the performance of Tesseract engine, such as Orientation, Noise, Resolution, Illumination etc. For tackling these problems, we use the following pipeline:

a) Try without any processing.
b) If (a) doesn’t work, try using OpenCV’s Gaussian Blur to remove random noise, then try again.
c) If (b) doesn’t work, rotate the image by 90 degrees and try (a) and (b) again.

In this way steps (a), (b) and (c) are repeated 4 times (for 0, 90, 180 and 270 degrees rotation) and if at any point UID candidates are found, we stop (as all UIDs in the image can be found in that particular setting). In case these steps fail to produce desired results, we produce the super resolution version of the image using ESRGAN and retry with the pipeline described above.

Verifying and Masking Aadhaar UIDs

In this step we try to filter the invalid UIDs using the Verhoeff Algorithm as there can be many unintended RegEx matches that are not of use. It is basically a checksum validation method. We use OpenCV’s functions to black out the first 8 digits of every UID with the help of character wise bounding boxes found in the previous step.

Algorithms Used

In our solution pipeline we use some algorithms such as:

  1. Verhoeff Algorithm: Aadhaar UID is a 12-digit number in which the last digit is a checksum digit calculated using this algorithm. It utilizes some tables (multiplication, inverse and permutation) for calculating the checksum bit. For validating, same tables are used.
  2. ESRGANs: Enhanced Super-Resolution Generative Adversarial Networks are capable of generating realistic textures during single image super-resolution. It achieves better visual quality with more realistic and natural textures than the original picture.

Tools Used

  1. Google Colab : Used as the development environment.
  2. NumPy : Used for handling high dimensional arrays.
  3. OpenCV and PIL : Used for image processing.
  4. PyTesseract : Used for OCR.
  5. RegEx : Used for Regular Expression searches.
  6. img2pdf and pdf2image : Used for handling .pdf files.
  7. ISR : Used for generating Super Resolution images.

Final Notes

Thanks for going through this Repository! Have a nice day.

Got any Queries? Feel free to contact me.

Saini Rohan Rao

mailto:rohanrao619@gmail.com https://github.com/rohanrao619 https://www.linkedin.com/in/rohanrao619 https://rohanrao619.github.io/

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.