A python-based algorithm for id-card rectification, specially optimized for China 2nd-generation id-card rectification. Given an input image which contains a card, the algorithm detects the card contour and performs perspective transformation in order to obatin the rectified card as output.
- An novel edge detection network is implemented to detect the card contour under complex background. The network is based on the RDC project and a new loss called edge-consist-loss is implemented to better impove the detection result.
- The algorithm works well for various input shapes, the output will be finetuned as the standard format of China 2nd-generation id-card.
- pytorch
- torchvision
- opencv-python
- scikit-image
- imutils
- numpy
$ pip install -r requirements.txt
if you want to run the algorithm with GPU, make sure that your computer support Nivida GPU and then install cuda. The algorithm will run with GPU if cuda is available, otherwise it will run with CPU, which takes more time complexity for image processing.
-
Go to
Card-Rectification/
-
Single-image processing:
$ python rectify.py [input_path] [output_path]
input_path
: the path of input imageoutput_path
: the path of output result- e.g.
$ python rectify.py example/card1.jpg result/card1_res.png
-
Mutiple-image processing:
$ python rectify.py [input_dir] [output_dir]
input_dir
: the directory of inputsoutput_dir
: the directory of ouputs- e.g.
$ python rectify.py example/ result/
the default save format is '.png'.
- The card is incomplete or is occuluded by other objects.
- If the card is upside down, the output will not adjust the rotation.
For any problems, please contact [email protected]