0% found this document useful (0 votes)
203 views24 pages

Project Report: Fake Note Detection (Python and Opencv)

This document provides a project report on developing a fake currency detection application using Python and OpenCV. It includes an introduction describing the application, literature review on relevant technologies, problem definition, implementation details, modules used, code snippets, screenshots and results. The application uses feature matching and validation algorithms to compare images of currency notes to a database and detect differences that may indicate counterfeits. It provides a simple GUI for users to upload images and get real-time results on note authenticity. The project aims to deploy the application at points of high currency usage to help detect counterfeits.

Uploaded by

Malai Paratha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
203 views24 pages

Project Report: Fake Note Detection (Python and Opencv)

This document provides a project report on developing a fake currency detection application using Python and OpenCV. It includes an introduction describing the application, literature review on relevant technologies, problem definition, implementation details, modules used, code snippets, screenshots and results. The application uses feature matching and validation algorithms to compare images of currency notes to a database and detect differences that may indicate counterfeits. It provides a simple GUI for users to upload images and get real-time results on note authenticity. The project aims to deploy the application at points of high currency usage to help detect counterfeits.

Uploaded by

Malai Paratha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

FAKE NOTE DETECTION

(Python And OpenCV)

PROJECT REPORT
Submitted for the Course: Image Processing (CSE4019)

By

Name Registration Number

Atharva Bais 17BCE0931


Kausthub Kesavadas 17BCE2144

To
Prof. Nagaraja Rao A.
School of Computer Science and Engineering
INDEX
Content Page no.

• Acknowledments ………………………………… 3
• Abstract ………………………………….………..4
• Introduction ……………………………………….5
• Literature Review ………………………………...6
• Problem Definition ………………………………..7
• Implementation …………………………………....9
• Modules …………………………………………..11
• Code ………………………………….…………...14
• Screenshots ………………………………….……18
• Results And Conclusions …………………………23
• Bibliography ……………………………………...23
ACKNOWLEDGEMENTS

We would like to thank our respected Image Processing teacher Prof. Nagaraja Rao
A. for providing us the support, guidance and for pushing us to do our best for our
project and teaching us all the important concepts involved to successfully end this
task.

Also, we all are grateful to VIT UNIVERSITY Management for providing us with
such a good environment to work out on our topic and providing this one opportunity
out of many others they are yet to provide.
Abstract
In the year 2016, our government took the historical decision to undergo
demonetisation. Such a big move has been rarely implemented in the history of the
world. The primary reasons for the 2016 decision were hoarding of notes, money
laundering and chiefly counterfeit currency. Even though the differences in the
counterfeit notes and the originals were obvious, it was difficult for a lame man to
constantly keep a track of these as one is always busy and there was no fast
mechanism (there still is not) to check fake notes. Our project uses the simplest
implementation of feature matching between images to detect differences in images
of notes and uses a number validation algorithm for the note’s serial number. The
final product is easy to use and responds in fairly less time. The ultimate aim is to
deploy the application to points of currency bottlenecks (cash counters at shopping
malls,petrol pumps,shops etc).
Introduction
A simple Python GUI program has been made for the purpose, a simple camera can
be used to click a picture (a steady/mounted camera and clear background produces
best results) and the pictures storage path acts as a input the the application. Phone
camera pictures were used in the development and can also be used for the purpose
of the application. A GUI based implementation can also be made and a constant
stream of input can also be provided for paths, a fixed mounted camera (even
webcam) can be suitable input. The image is loaded and using python and opencv, a
series of tests are performed to give a comment on the notes genuinity.

The final program also uses the various inbuilt libraries of python namely, Scipy and
Numpy. The large number of trials conducted are asurance of the fact that the
application is fit for deployment.The program is rather simple and easy to
understand, it is difficult to tweak pass the program as the note features comparison
is rather general than a particular feature specific. This ensures that the newest
tweaks to the notes can also be caught.

To use the application, one needs the following

● visual input device of satisfactory quality (webcam,phone camera)


● information transfer device (if visual input is not connected to computer)
● Computer with 512 Mb RAM, windows xp and above
● LCD,LED/ any medium to high resolution screen
● Keyboard Mouse etc.
Literature review
OpenCV is vast library which can be used in many programming languages like
Python,C++, Java and most Object Oriented Programming Languages. It is used to
deal with all sorts of visual inputs to the the system, images as well as videos, it has
many features such as color recognition, shape recognition, moving objects
detection, line detection etc. Most of the image processing concepts learnt in class
can be implemented via the OpenCV library.

Python is an Object Oriented Programming Language used widely for application


development, it is easy to code in and provides a large number of inbuilt libraries
like scipy and numpy to implement nearly any program. We have chosen Python to
develop our application because the end product is very user friendly and is in a GUI
format.

The types of comparisions used for the purpose are all feature comparision and ORB
feature comparision. All feature comparision looks at all the minute features of a
image and comparision can be done using various algorithms, whereas ORB feature
detects larger features such as text and shapes and can still detect them irrespective
of their tint or orientation.
Problem definition
To perform the counterfeit note detection, the image first needs to be supplied to the
machine, then it’s path must be provide to the code, after which multiple operations
can be performed.
Counterfeit Notes usually do not contain certain important safety features, moreover
the general color , indentation etc. and other characteristics are very different in the
counterfeit notes.
About The GUI:-
• PyQt5 – The main module used for creating the GUI is PyQt5 which is the
converted module of Qt5 which is used in C++
• Buttons – Buttons are used on the GUI so that each option can selected by
clicking the button. Multiple buttons have been used for different purposes
like selecting a picture, note recognition, fine recognition of the currency, orb
recognition and to quit the application.
• Label – A label is used to display all the processes that are being performed
rather than showing it in command window or IDE it is being displayed on
the GUI so that the user has to only look at the GUI and not multiple places.
Implementation

The implementation of fake currency recognition using image processing using


OpenCV, NumPy, SciPy is to gain practical knowledge of image processing and
using GUI, where we learn to apply different algorithms on the note to detect
whether the note used is fake or real based on many features. In this project, we aim
to detect whether the given note is real or not real. As mentioned we use many
Python tools like PyQt5, OpenCV, NumPy, SciPy for feature extraction, GUI, colour
recognition and many more features. The type of note is detected first and the
database of real notes is searched and the features of the given note is compared with
the database of notes and then it is determined whether the note is fake or real.

SIFT CREATE(Scale-Invariant Feature Transform): in 2004, D.Lowe, University of


British Columbia, came up with a new algorithm, Scale Invariant Feature Transform
(SIFT) in his paper, Distinctive Image Features from Scale-Invariant Keypoints,
which extract keypoints and compute its descriptors. In this algorithm, the imported
module SIFT goes through every pixel and selects features which are bigger than a
few pixels, in the algorithm we have implemented, we compare all the recognized
features using a radius factor of 0.6(which we have found to be optimal after several
test runs) which compares features only if they are in the similar region of the image.
If the number of matches is greater than 60% the number of matches when the
original image is compared to itself we can say that the note is real else the image is
displayed as fake.

NOTE RECOGNITION: in this algorithm using scipy, firstly we calculate the


average and dominant colour of the image and then based on the ranges calculated
by multiple tests we determine the note to be of a particular denomination, after
checking the denomination number the image is finally declared to be of a particular
denomination.
ORB CREATE(Oriented FAST and Rotated BRIEF): This algorithm was brought
up by Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary R. Bradski in their
paper ORB: An efficient alternative to SIFT or SURF in 2011. As the title says, it is
a good alternative to SIFT and SURF in computation cost, matching performance
and mainly the patents. Yes, SIFT and SURF are patented and you are supposed to
pay them for its use. In this algorithm, firstly similar to sift it goes through all pixels
and recognizes unique features bigger than a few pixels, then it checks local
neighbourhood of features to recognize larger objects. In our implementation of this
module the features compared are the
triangle(Rs.100)/square(Rs.50)/Rectangle(Rs.20), xerox proof bubbles, half print
bubble, other photocopy resistant features and governor signature. in the algorithm
we have implemented, we compare all the recognized features using a radius factor
of 0.6(which we have found to be optimal after several test runs) which compares
features only if they are in the similar region of the image. If the number of matches
is greater than 60% the number of matches when the original image is compared to
itself we can say that the note is real else the image is displayed as fake.
Modules

The Modules involved are:

● PyQt5
● OpenCV
● NumPy
● SciPy
● Note Recognition
● Fine Recognition
● ORB Recognition

PyQt5

PyQt5 is a very large module which is used to create the Graphical User Interface
for the program. An alternative module that could have been used Tkinter but was
avoided as it does not feel good and is very old. Qt5 is the version that is currently
running in the C++ version and was converted for Python and hence was named
PyQt5. The main window of the GUI is called QWidget and all the things present in
the GUI are present in QWidget and are initialized in the __init__ function. initUI is
another function that is being used to initialize the buttons and the label and each of
the buttons call other functions to perform functionalities for the particular button.
QFont was used to set the font and the size of the label

OpenCV

OpenCV (Open Source Computer Vision) is a library of programming functions


mainly aimed at real-time computer vision. Originally developed by Intel, it was
later supported by Willow Garage then Itseez (which was later acquired by Intel).
The library is cross-platform and free for use under the open-source BSD license.
OpenCV supports the deep learning frameworks TensorFlow, Torch/PyTorch and
Caffe. OpenCV was an integral of the project as the module was used for various
purposes like reading image and performing various operations on the image using
OpenCV.
NumPy

NumPy is a library for the Python programming language, adding support for large,
multi-dimensional arrays and matrices, along with a large collection of high-level
mathematical functions to operate on these arrays. The ancestor of NumPy, Numeric,
was originally created by Jim Hugunin with contributions from several other
developers. In 2005, Travis Oliphant created NumPy by incorporating features of
the competing Numarray into Numeric, with extensive modifications. NumPy is
open-source software and has many contributors. NumPy was used in the project for
statistical purposes like calculating the good matches when comparing images.

SciPy

SciPy is a free and open-source Python library used for scientific computing and
technical computing.

SciPy contains modules for optimization, linear algebra, integration, interpolation,


special functions, FFT, signal and image processing, ODE solvers and other tasks
common in science and engineering.

SciPy builds on the NumPy array object and is part of the NumPy stack which
includes tools like Matplotlib, pandas and SymPy, and an expanding set of scientific
computing libraries. This NumPy stack has similar users to other applications such
as MATLAB, GNU Octave, and Scilab. The NumPy stack is also sometimes referred
to as the SciPy stack.[3]

Note Recognition

The Note Recognition module is used to recognize the type of note that has been
given as the input by the user using the PyQt5 module and checks for the type of
image by trying to recognize the note number in the image and then returns the note
number if successfully found or else return that the note was not recognized.
Fine Recognition

Fine Recognition module is used to detect whether the note recognized by the note
recognition module is real or fake using various modules like NumPy, SciPy,
OpenCV and then the result is displayed on the PyQt5 GUI. The result displayed is
of the form the type of note that was sent as an input and whether the note is real or
fake.

ORB Recognition

Fine Recognition module is used to detect whether the note recognized by the note
recognition module is real or fake using bulk features of the note by using various
modules like NumPy, SciPy, OpenCV and then the result is displayed on the PyQt5
GUI. The result displayed is of the form the type of note that was sent as an input
and whether the note is real or fake.
MODULE CODE
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QFileDialog, QPushButton, QLabel
from PyQt5.QtCore import pyqtSlot, Qt
from PyQt5.QtGui import QFont
import cv2
import numpy as np
from scipy.stats import itemfreq

class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'Image Processing Review 3'
self.left = 700
self.top = 100
self.width = 640
self.height = 480
self.file_path = ''
self.initUI()

def initUI(self):
newfont = QFont("Times", 15, QFont.Bold)
#
self.text_display = QLabel("Image Processing Project", self)
self.text_display.setFont(newfont)
self.text_display.resize(630, 75)
self.text_display.move(10, 90)
self.text_display.setAlignment(Qt.AlignCenter)
#
self.browse_button = QPushButton('Select A Picture', self)
self.browse_button.resize(150, 75)
self.browse_button.setToolTip('Select The Picture To Be Checked')
self.browse_button.move(240, 190)
self.browse_button.clicked.connect(self.on_click)
#
self.note_recognize = QPushButton('Note Recognition', self)
self.note_recognize.resize(150, 75)
self.note_recognize.setToolTip('Click for note recognition')
self.note_recognize.move(10, 290)
self.note_recognize.clicked.connect(self.note_recognition)

#
self.fine_recognize = QPushButton('Fine Recognition', self)
self.fine_recognize.resize(150, 75)
self.fine_recognize.setToolTip('Click for fine recognition')
self.fine_recognize.move(240, 290)
self.fine_recognize.clicked.connect(self.fine_recognition)
#
self.coarse_recognize = QPushButton('Orb Recognition', self)
self.coarse_recognize.resize(150, 75)
self.coarse_recognize.setToolTip('Click for coarse recognition')
self.coarse_recognize.move(470, 290)
self.coarse_recognize.clicked.connect(self.orb_recognition)
#
self.qbtn = QPushButton('Quit', self)
self.qbtn.resize(150, 75)
self.qbtn.clicked.connect(QApplication.instance().quit)
self.qbtn.move(240, 390)
#
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.show()
# self.openFileNamesDialog()
# self.saveFileDialog()

@pyqtSlot()
def on_click(self):
self.file_path = self.openFileNameDialog()
self.text_display.setText('Picture Selected')

@pyqtSlot()
def note_recognition(self):
self.text_display.setText('Recognizing the note')
note_20 = [193, 218, 250]
note_50 = [212, 222, 240]
note_100 = [235, 240, 239]
img = cv2.imread(self.file_path)
average_color = [img[:, :, i].mean() for i in range(img.shape[-1])]
arr = np.float32(img)
pixels = arr.reshape((-1, 3))
n_colors = 5
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
flags = cv2.KMEANS_RANDOM_CENTERS
_, labels, centroids = cv2.kmeans(pixels, n_colors, None, criteria, 10, flags)
palette = np.uint8(centroids)
dominant_color = palette[np.argmax(itemfreq(labels)[:, -1])]
dominant_color = dominant_color.tolist()
note_number = -1
for i in range(len(dominant_color)):
if note_20[i] - 5 <= dominant_color[i] <= note_20[i] + 5 and note_number
== -1 or note_number == 20:
note_number = 20
elif note_50[i] - 5 <= dominant_color[i] <= note_50[i] + 5 and note_number
== -1 or note_number == 50:
note_number = 50
elif note_100[i] - 5 <= dominant_color[i] <= note_100[i] + 5 and
note_number == -1 or note_number == 100:
note_number = 100
else:
note_number = -1
if note_number == -1:
self.text_display.setText('Note Not Recognized')
else:
self.text_display.setText('Note is ' + str(note_number))
return note_number

@pyqtSlot()
def fine_recognition(self, flag=True):
note_number = self.note_recognition()
original = cv2.imread(r'E:\Digital Assignments\Image
Processing\original\%d.jpg' % note_number)
image_to_compare = cv2.imread(self.file_path)
# part 1 feature compare
sift = cv2.xfeatures2d.SIFT_create()
kp_1, desc_1 = sift.detectAndCompute(original, None)
kp_2, desc_2 = sift.detectAndCompute(image_to_compare, None)
index_params = dict(algorithm=0, trees=5)
search_params = dict()
flann = cv2.FlannBasedMatcher(index_params, search_params)
matches = flann.knnMatch(desc_1, desc_2, k=2)
# print(len(matches))
result = cv2.drawMatchesKnn(original, kp_1, image_to_compare, kp_2, matches,
None)
# cv2.imshow("result", result)
# cv2.imshow("result", cv2.resize(result, None, fx=0.4, fy=0.4))
good_points = []
ratio = 0.6
for m, n in matches:
if m.distance < ratio * n.distance:
good_points.append(m)
# print(len(good_points))
result2 = cv2.drawMatches(original, kp_1, image_to_compare, kp_2, good_points,
None)
if flag:
cv2.imshow("result2", cv2.resize(result2, None, fx=0.4, fy=0.4))
# part3
# print("Keypoints in 1st Image : " + str(len(kp_1)))
# print("Keypoints in 2nd Image : " + str(len(kp_2)))
percentage_match = 100 * len(good_points) / len(kp_1)
if percentage_match > 1:
self.text_display.setText('Note is ' + str(note_number) + ' and is Real')
else:
self.text_display.setText('Note is ' + str(note_number) + " but is Fake")
# print("Percentage of good matches : ", 100 * len(good_points) /
len(kp_1))

@pyqtSlot()
def orb_recognition(self):
note_number = self.note_recognition()
original = cv2.imread(r'E:\Digital Assignments\Image
Processing\original\%d.jpg' % note_number)
image_to_compare = cv2.imread(self.file_path)
# ORB detector
orb = cv2.ORB_create()
kp1, des1 = orb.detectAndCompute(original, None)
kp2, des2 = orb.detectAndCompute(image_to_compare, None)
# for d in des1:
# print(d)
# Brute Force orb matching
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) # true for best match
# matis == matches
matis = list(bf.match(des1, des2))
matis = sorted(matis, key=lambda x: x.distance)
matching_result = cv2.drawMatches(original, kp1, image_to_compare, kp2,
matis[:50], None, flags=2)
cv2.imshow("Matching Result", cv2.resize(matching_result, None, fx=0.4,
fy=0.4))
self.fine_recognition(False)
cv2.waitKey(0)
cv2.destroyAllWindows()

def openFileNameDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName, _ = QFileDialog.getOpenFileName(self, "Select A Picture", "",
"All Files (*);;Pictures (*.jpg)", options=options)

return fileName
def cryptotext(self, text_string):
crypto_text = ''
for i in range(0, len(text_string)):
crypto_text += chr(ord(text_string[i]) * (i + 1))
return crypto_text

if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
Results and Discussion
THE INTERFACE
SELECTING AN IMAGE

AFTER SELECTING THE IMAGE


AFTER RECOGNIZING THE TYPE OF NOTE
DISPLAYING THE FINE MATCHES
AFTER DETERMINING WHETHER THE NOTE IS REAL OR FAKE
DISPLAYING THE MATCHES ORB RECOGNITION
Results and Conclusions
Counterfeit Currency is a serious problem which is making the country hollow from
inside, it is a very serious issue and this our genuine effort to tackle it. The GUI is
fully functional and can tell apart counterfeit notes with satisfactory accuracy.

Conclusions about the code, OpenCV is a very effective tool and can be used to
implement various feature detection algorithms, the fine features algorithm often
matches those pixels which are not at the relatively same position, hence the radius
concept helps to remove this anomaly.

In conclusion I would like to thank Nagaraja sir for the wonderful teaching and
learning experience, we have gained a lot about image processing from this project
and will definitely use these concepts in the future.

Bibliography

• Opencv.org for opencv features


• Wikipidia for knowledge of modules
• RBI and other government websites for features

You might also like