Tax Payers Fake ID Card Detection | A Machine Learning Project Part 1

Josiah Adesola
4 min readMar 19, 2022

--

You probably have been thinking how can we recognise a fake ID from a real one, even if they almost have the same similarity and your eye can’t catch them? Well here is a solution. Follow along. Feel free to copy this project and add it to your GitHub.

Introduction

Machine Learning is a subset of AI is giving computers or systems the ability to perform human operations without being explicitly programmed.

If a human can recognise the difference between a fake and a real ID card across several institutions, then we could create a machine learning model that could help solve this problem with the most accurate form.

AI is growing in its application in our everyday lives from face recognition on our phones to google map suggestions, helping our everyday lives. How can we apply this super sweet tech to detect a fake ID Card from a real one? Well, you will get to know me here.

Problem Statement

According to hindustantimes in 2019, one of the biggest news websites in India. A 21-year man used a fake ID of a pay and account officer to defraud ₹3.8 crores (over 208 million Naira 😫😪💀).

There is an increasing number of people camouflaging as taxpayers in India. They create a fake Card with their pictures on it. This has really caused breaches in the security system of the country.

It has affected the revenue entering the country negatively. There hadn’t been a good allocation of resources presently due to this problem.

Well, how can we solve this problem, Here comes the solution 😁😁

Solution

As machine learning engineer, we discovered that you can easily detect the difference between two images by making a computer understands the image first, then test the structural similarity.

If the structural similarity between the new image and the original logged up in the system is not 99% — 100% then it’s fake (could be disputable though 😏😏).

This problem can be solved using Computer vision, a part of AI. I used popular packages in the python language such as skimage, imutils, PIL, request, cv2 (Open-CV).

Let’s Code

#Jupyter Notebook or Google Colab

  1. Create a Jupyter notebook folder

Click the “+” icon when you run Jupyter notebook to create a new folder and file (download anaconda if you don’t have one). Create an image folder to contain both the fake and real ID card, you could use codes too (Manual or code😜😜).

2. Download these packages on your terminal

from skimage.metrics import structural_similarity — helps to compare the two IDs and check their structural_similarity

Import imutils — helps to grab the control of the image

import cv2 — for image processing

from PIL import Image — for downloading the image

import request — for getting the request from the URL

In case you couldn’t install it with your terminal you could also run the code in this way in your notebook.

3. Create a folder to store the images

You can create a folder and subfolder with code using the !mkdir taxpayers_caard_tampering code or do it manually

Then, download the two images from the internet to these folder, using the request(python package) we called earlier.

stream = True: It helps us open the connection to the internet, where we are getting our request form, and allows us to fetch easily anytime we need it.

.raw: It enables full control of the request

4. Check for the size and format of the image

It is clearly stated in the comment session.

However, the size and format methods used here are gotten from the (from PIL import Image), if you are wondering how.

Check the previous code, you’ll find out the Image.open() function.

5. Change the Shape and Size to the Real Image

Then you resize both images, so it will be easy to perform computer vision on both of them and save them with the Original.save()

taxpayers_card_tampering/images/- This directory is created in your jupyter notebook from the code, you can always create manually by clicking new in the folder on Jupyter notebook or Google Colab yourself

taxpayers_card_tampering/images/fake.png: This code means you just saved the fake.png to the folder “images”, you created.

Note that the original.resize(()) function has double brackets to avoid errors.

6. Convert the image to grayscale

a. Check the real/original image first

#Display the origianl imageoriginal

b. Check the fake image

#Display the fake ID the user gavefake

c. Convert to gray scale (Computer vision)

Converting to gray scale (what we call black and white 🙄🙄)is necessary because the computer easily reads gray colour, which makes the image less complex for the computer to easily identify the fake from the original.

cv2.cvtColor(original, cv2.COLOR_BGR2RAY) — This method in the cv2 package which seems obvious in the code, helps to convert any image to gray colour or what you term black and white.

Coloured images have 3 channels — RGB(Red, green and Blue) same as what is written in the code

Gray images have just 1 channel.

To be continued in…

Check out Part 2, don’t forget to like and comment.

--

--

Josiah Adesola
Josiah Adesola

Written by Josiah Adesola

Writes about machine learning, Data Science, Python. Creative. Thinker. Engineering. Twitter: @_JosiahAdesola

No responses yet