Extraction, Verification and Masking of Aadhaar UIDs from photos and scanned documents.
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:
- Extracting Aadhaar UID from photo using Tesseract.
- Verifying the extracted Aadhaar UIDs.
- Masking the first 8 digits of detected UIDs.
This task can be further divided into 2 Sub-Tasks:
- Preprocess the image and then use PyTesseract library to extract all recognizable text from the image with their corresponding bounding boxes.
- 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.
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.
In our solution pipeline we use some algorithms such as:
- 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.
- 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.
- Google Colab : Used as the development environment.
- NumPy : Used for handling high dimensional arrays.
- OpenCV and PIL : Used for image processing.
- PyTesseract : Used for OCR.
- RegEx : Used for Regular Expression searches.
- img2pdf and pdf2image : Used for handling .pdf files.
- ISR : Used for generating Super Resolution images.
Thanks for going through this Repository! Have a nice day.
Got any Queries? Feel free to contact me.
Saini Rohan Rao