Python OpenCV Project – Pan Card Fraud Detection

FREE Online Courses: Elevate Skills, Zero Cost. Enroll Now!

In the world of identity verification and document authentication, ensuring the authenticity of the PAN card is more important. Nowadays, with digital transactions and financial activities on the rise, the need for robust fraud detection mechanism has become more crucial than ever. This is where the power of OpenCV, a versatile computer vision library comes into play. In this tutorial, we will develop a tool that can detect fraud or duplicate PAN cards.

Laplacian

Laplacian is a mathematical technique employed to enhance variations within an image. In this tool, it is used to calculate the variance of pixel intensities in the grayscale image. This is also called a blur score. This score can identify potential alterations or tampering in the PAN card. Laplacian acts as a digital magnifying glass, highlighting minute details that might indicate a fraudulent PAN card.

White pixel ratio

It is the proportion of white pixels (high-intensity values) in relation to the total number of pixels within the grayscale image. It acts as a key indicator of the image’s background and overall composition. Higher white pixel ratio suggests the presence of a significant white background, often associated with scanned or digitally altered images. By setting the threshold and comparing it with the ratio, the tool can distinguish between Fraud and Real PAN card.

Prerequisites For Python OpenCV Pan Card Fraud Detection

To make this tool, you should have python programming knowledge, be comfortable with the OpenCV library, and meet the following system requirements.

1. Python 3.7 and above
2. Any Python editor (VS code, Pycharm, etc.)

Download Python OpenCV PAN Card Fraud Detection Project.

Please download the source code of Python OpenCV Pan Card Fraud Detection Project: Python OpenCV Pan Card Fraud Detection Project Code.

Installation

Open Windows cmd as administrator

1. For the OpenCV package, run the following command.

pip install opencv-python

Let’s Implement It

To make this tool follow the below steps.

Initially, we import all the packages necessary for implementation.

import cv2
import numpy as np

1. This function is used to read images from a specified path.

def preprocessing_img(path):
    img = cv2.imread(path)
    return img

This function first analyzes the image specified by path. It calculates the image’s blur score using laplacian variance in grayscale image and then it calculates white pixel ratio. By comparing ratio with threshold, it determines whether the given PAN card is Real or Fraud.

def fraud_detect(path):
    img = preprocessing_img(path)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    blur = cv2.Laplacian(gray,cv2.CV_64F).var()
    _, binary = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY)
    white_pixel_ratio = np.sum(binary==255) / (gray.shape[0] * gray.shape[1])
    blur_thres = 100
    white_pix_thre = 0.2
    if blur < blur_thres or white_pixel_ratio> white_pix_thre:
        return True
    return False

Output

Pan card fraud detection

Here, at the beginning of main function, we provide the PAN card image. It calls fraud_detect() function to assess potential fraud based on blurriness and white pixel ratio. After obtaining the result from the function, it displays whether the given PAN card is real or fraud on image. This images is shown in “ProjectGurukul” windows.

if __name__ == "__main__":
    image_path = "pan2.jpg"
    is_fraud = fraud_detect(image_path)
    image = cv2.imread(image_path)
    print(is_fraud)
    if is_fraud:
        cv2.putText(image, "Fraud", (400, 300), cv2.FONT_HERSHEY_COMPLEX, 2, (0,0,255), 7)
    else:
        cv2.putText(image, "Real", (200, 100), cv2.FONT_HERSHEY_COMPLEX, 2, (0,255,0), 7)
    cv2.imshow("ProjectGurukul", image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

Output

Pan card fraud detection real

Pan card fraud detection real output

Pan card fraud detection real fraud

Pan card fraud detection real fraud output

Conclusion

PAN card fraud detection using OpenCV provides a practical approach to enhancing document security. By evaluating aspects like white pixel ratio and blur score using laplacian, this tool contributes to a more trustworthy document verification process. Through this, potential fraud scenarios can be identified, offering a valuable layer of protection in today’s digital world.

Leave a Reply

Your email address will not be published. Required fields are marked *