Egyptian National ID Card Detection, Alignment and Text Region Extractions.
This solution assumes the ID is scanned.
This solution assumes the detection of the front side only of the ID.
Input image as follows:
The script will first detect the SIFT features and match them between the following template and the test image:
If Matches Found:
A homography matrix between the image and the template is found. If the image moves out of frame, the matrix is compensated by another translation matrix to accomodate the translation back in to frame. The result of the translation is as follows:
After warping, Canny Edges are applied for edge detection and finding the largest contour to only select the card from the scene. The largest contour is then warped to a fixed size of (672, 448). This is a static size I configured best for the application.
The card is then converted to binary, dilated and eroded for blob detection by finding contours around blobs. The blobs will resemble the text regions and the face. We need to disregard the face Bounding Box. I used dlib's face detector to find the region of the face and delete any of the boxes that overlap with the region of the face. The final result is as follows:
The bounding boxes of the text are saved in output/
directory
Add yout images to the test-dataset directory and write the following commands
git clone https://github.com/KarimIbrahim11/ID-Card-Detection.git
cd ID-Card-Detection
conda env create -f env.yaml
conda activate env
python id_detector.py