WD Project Final
WD Project Final
CHAPTER 1
ABSTRACT
Security is always a main concern in every domain, due to a rise in crime rate in a crowded event
or suspicious lonely areas. Abnormal detection and monitoring have major applications of
computer vision to tackle various problems. Due to growing demand in the protection of safety,
security and personal properties, needs and deployment of video surveillance systems can
recognize and interpret the scene and anomaly events play a vital role in intelligence monitoring.
This paper implements automatic gun (or) weapon detection using a Faster RCNN algorithms.
Proposed implementation uses two types of datasets. One dataset, which had pre-labelled images
and the other one is a set of images, which were labelled manually. Results are tabulated, both
algorithms achieve good accuracy, but their application in real situations can be based on the
trade-off between speed and accuracy.
1
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
CHAPTER 2
INTRODUCTION
Dataset is created, trained and fed to object detection algorithm. Based on application suitable
detection algorithm (SSD or fast RCNN) chosen for gun detection. The approach addresses a
problem of detection using various machine learning models like Region Convolutional Neural
Network (RCNN), Single Shot Detection (SSD).
Security is always a main concern in every domain, due to a rise in crime rate in a crowded event
or suspicious lonely areas. Abnormal detection and monitoring have major applications of
computer vision to tackle various problems. Due to growing demand in the protection of safety,
security and personal properties, needs and deployment of video surveillance systems can
recognize and interpret the scene and anomaly events play a vital role in intelligence monitoring.
This paper implements automatic gun (or) weapon detection using a convolution neural network
(CNN) based SS D and Faster RCNN algorithms. Proposed implementation uses two types of
datasets. One dataset, which had pre-labelled images and the other one is a set of images, which
were labelled manually. Results are tabulated, both algorithms achieve good accuracy, but their
application in real situations can be based on the trade-off between speed and accuracy.
CHAPTER 3
2
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
LITERATURE SURVEY
We present a method for detecting objects in images using a single deep neural network. Our
approach, named SSD, discretizes the output space of bounding boxes into a set of default boxes
over different aspect ratios and scales per feature map location. At prediction time, the network
generates scores for the presence of each object category in each default box and produces
adjustments to the box to better match the object shape. Additionally, the network combines
predictions from multiple feature maps with different resolutions to naturally handle objects of
various sizes. SSD is simple relative to methods that require object proposals because it completely
eliminates proposal generation and subsequent pixel or feature resampling stages and encapsulates
all computation in a single network. This makes SSD easy to train and straightforward to integrate
into systems that require a detection component. Experimental results on the PASCAL VOC,
COCO, and ILSVRC datasets confirm that SSD has competitive accuracy to methods that utilize
an additional object proposal step and is much faster, while providing a unified framework for
both training and inference. For 300×300300×300 input, SSD achieves 74.3 % mAP on
VOC2007 test at 59 FPS on a Nvidia Titan X and for 512×512512×512 input, SSD achieves
76.9 % mAP, outperforming a comparable state of the art Faster R-CNN model. Compared to other
single stage methods, SSD has much better accuracy even with a smaller input image size.
the highest levels of the network. We are able to obtain competitive recognition performance on
VOC2007 and ILSVRC2012, while using only the top few predicted locations in each image and
a small number of neural network evaluations
“Anomaly Detection in Videos for Video Surveillance Applications Using Neural Networks,”
Security is always a main concern in every domain, due to a rise in crime rate in the crowded event
or suspicious lonely areas. Abnormal detection and monitoring have major applications of
computer vision to tackle various problems. Due to growing demand in the protection of safety,
security and personal properties, the needs and deployment of video surveillance systems can
recognize and interpret the scene and anomaly events play a vital role in intelligence monitoring.
Anomaly detection is a technique used to distinguish various patterns and identify unusual patterns
with a minimal period, this pattern is called outliers. Surveillance videos can capture a variety of
realistic anomalies. Anomaly detection in video surveillance involves breaking down the whole
process into three layers, which are video labelers, image processing, and activity detection.
Hence, anomaly detection in videos for video surveillance application gives assured results in
regards to real-time scenarios. In this paper, we anomaly was detected in images and videos with
an accuracy of 98.5 %.
“A Review of Artificial Intelligence Methods for Data Science and Data Analytics:
Applications and Research Challenges,”
Artificial intelligence is a field which requires multidisciplinary expertise where the final goal is
to automate all the human activities that presently require human intelligence. The major problem
is to develop a method which works exactly the way how a human brain works. The architecture
of artificial intelligence must emphasize on evaluation and redesign the nature of design process.
Data science is also trending now and analytically deals to solve complex problems. Data is divided
into smaller parts and its trends, behaviors are understood. The main problem in data science is to
handle large quantities of data. Though there is significant increase in terms of research
opportunities few challenges like lack of compute power, people power still remains a big
challenge.
4
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Object Classification is a principle task in image and video processing. It is exercised over a
multitude of applications ranging from test and number classification to traffic surveillance. The
primitive machine learning concepts had provided the pedestal for carrying out umber of image
processing tasks. Classifier such as Haar cascade which uses Haar like features was primitively
used for face detection. Nowadays it's used for tacking and detection purposes also. Moreover, due
to the ever-increasing demand and scope of improvement in the existing fields, the primitive
methods need a lot of upgradation. Neural Networks have made the tasks quite plain sailing. Right
from the vanilla neural networks to Fast R-CNN and then Faster R-CNN, all models have
contributed significantly in the domain of computer vision. This paper mainly focuses in detection
and classification ranging from single class objects to multi class objects. The Haar cascade
classifier was trained on a batch of positive and negative samples which were later stitched together
to form a vector file and finally form the xml file. On the other hand, COCO dataset used for
implementing R-CNN algorithm due to the presence of pertained model in it.
“Simulation and Performance Analysis of Feature Extraction and Matching Algorithms for
Image Processing Applications”
Feature extraction and matching has the limelight in all almost all the fields ranging from
biomedical to exploratory research. It has ubiquitous applications in present world that is moving
at a breathtaking pace towards automation. The algorithms used for feature extraction are
application specific, i.e. the one that yields better performance for face recognition does not
guarantee the same performance for lane detection. A lot of time is invested in identifying
algorithms that are best suited for an application. In the interest of time, an attempt has been made
to develop few good algorithm combinations that assist in the selection of algorithms. The features
of input image and the target image are extracted, described and matched using various algorithm
combinations like SURF, FAST, MSER, and Harris Corner Detector. The combination of all these
algorithms is simulated on MATLAB using computer vision and image processing toolboxes. A
Graphical User Interface (GUI) is developed for better user experience. Face recognition is
considered as an example to perform the simulation. The results reflect that the combination of
5
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
SURF and MSER performs better compared to other algorithm combinations when an image is
scaled and rotated, however there are no good matches when there is also a pose variation. Proper
thresholding of ‘Match Threshold’, ‘Reject Ratio’, and ‘Inlier Threshold’ must be carried out
through trial and error method to get better results.
The plan is to establish an integrated system that can manage high-quality visual information and
also detect weapons quickly and efficiently. It is obtained by integrating ARM-based computer
vision and optimization algorithms with deep neural networks able to detect the presence of a
threat. The whole system is connected to a Raspberry Pi module, which will capture live
broadcasting and evaluate it using a deep convolutional neural network. Due to the intimate
interaction between object identification and video and image analysis in real-time objects, By
generating sophisticated ensembles that incorporate various low-level picture features with high-
level information from object detection and scenario classifiers, their performance can quickly
plateau. Deep learning models, which can learn semantic, high-level, deeper features, have been
developed to overcome the issues that are present in optimization algorithms. It presents a review
of deep learning based object detection frameworks that use Convolutional Neural Network layers
for better understanding of object detection. The Mobile-Net SSD model behaves differently in
network design, training methods, and optimization functions, among other things. The crime rate
in suspicious areas has been reduced as a consequence of weapon detection. However, security is
always a major concern in human life. The Raspberry Pi module, or computer vision, has been
extensively used in the detection and monitoring of weapons. Due to the growing rate of human
safety protection, privacy and the integration of live broadcasting systems which can detect and
analyse images, suspicious areas are becoming indispensable in intelligence. This process uses a
Mobile-Net SSD algorithm to achieve automatic weapons and object detection.
“Background Modelling techniques for foreground detection and Tracking using Gaussian
Mixture model”
Background Modelling and Foreground detection in sports has been achieved by cleverly
developing a model of a background from a video by deducing knowledge from frames and
comparing this model to every subsequent frame and subtracting the background region from it,
6
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
hence leaving the foreground detected. This output from GMM background subtraction is fed into
the feature extraction algorithm, which segregates the players based on teams. By extracting
information of primary colors from each frame, the design of the algorithm based on the color of
preference is done. Tracking algorithms Kalman and extended Kalman Filters help to predict and
correct the location of players and in correctly estimating their trajectory on the field. Challenges
such as shadowing, occlusions and illumination changes are addressed. The designed algorithms
are tested against a set of performance parameters for the following datasets (Norway and FIFA)
using MATLAB (2017b) and the inferences are respectively made. Object detection, motion
detection and Kalman filter algorithms are implemented and the observed results are 100%, 84%
and 100% accuracy respectively. With the results quantification and performance analysis, it is
observed that with the decrease in contrast between player jerseys a decrease in detection accuracy
occurs and with players crowded regions on the field and occluded players a decrease in tracking
accuracy was observed.
We introduce a new distance between two distributions that we call the Earth Mover's Distance
(EMD), which reflects the minimal amount of work that must be performed to transform one
distribution into the other by moving "distribution mass" around. This is a special case of the
transportation problem from linear optimization, for which efficient algorithms are available. The
EMD also allows for partial matching. When used to compare distributions that have the same
overall mass, the EMD is a true metric, and has easy-to-compute lower bounds. In this paper we
focus on applications to image databases, especially color and texture. We use the EMD to exhibit
the structure of color-distribution and texture spaces by means of Multi-Dimensional Scaling
displays. We also propose a novel approach to the problem of navigating through a collection of
color images, which leads to a new paradigm for image database search.
The single object detection has been performed by using the concepts of convolution layers. A
neural network consists of several different layers such as the input layer, at least one hidden layer,
and an output layer. The dataset used for single object detection is the on-road vehicle dataset.
7
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
This dataset consists of three classes of images which are Heavy, Auto and Light. The dataset
consists of images of varying illuminations. The performance metrics has been calculated for the
day dataset, evening dataset and night dataset. Multiple object detection has been performed using
the You Only Look Once (YOLOv3) algorithm. This approach encompasses a single deep
convolution neural network dividing the input into a cell grid and each cell predicts a boundary
box and classifies object directly. The dataset used for multiple object detection is the KITTI
dataset. It consists of 80 classes out of which five classes has been considered for this project which
are: car, bus, truck, and motorcycle and train. Using the Multiple Object Detection concepts,
tracking of vehicles was further implemented. The first frame of the video was taken and Multiple
object detection was performed and in the further frames of the video the object was tracked using
its centroid position. This has been developed using OpenCV and Python using YOLOv3
algorithm for the object detection phase.
8
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
CHAPTER 4
SYSTEM ANALYSIS
EXISTING SYSTEM:
Abnormal detection and monitoring have major applications of computer vision to tackle various
problems. Due to growing demand in the protection of safety, security and personal properties,
needs and deployment of video surveillance systems can recognize and interpret the scene and
anomaly events play a vital role in intelligence monitoring. This paper implements automatic gun
(or) weapon detection using a convolution neural network (CNN)
DISADVANTAGES:
PROPOSED SYSTEM:
g. This paper implements automatic gun (or) weapon detection using based SS D and Faster
RCNN algorithms. Proposed implementation uses two types of datasets. One dataset, which had
pre-labelled images and the other one is a set of images, which were labelled manually. Results
are tabulated, both algorithms achieve good accuracy, but their application in real situations can
be based on the trade-off between speed and accuracy
ADVANTAGES:
More Accuracy.
FRCNN is faster than CNN
9
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Umbrella
DOCUMENT CONTROL
Activity
Umbrella
Business Requirement Activity
Documentation
• Feasibility Study
• TEAM FORMATION
• Project Specification ANALYSIS &
Requirements PREPARATION
DESIGN CODE UNIT TEST ASSESSMENT
Gathering
INTEGRATION ACCEPTANCE
& SYSTEM TEST
DELIVERY/INS
TESTING
TALLATION
Umbrella
TRAINING
Activity
SDLC is nothing but Software Development Life Cycle. It is a standard which is used by software
industry to develop good software.
Stages in SDLC:
Requirement Gathering
Analysis
Designing
Coding
Testing
Maintenance
10
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Requirements Gathering stage:The requirements gathering process takes as its input the goals
identified in the high-level requirements section of the project plan. Each goal will be refined into
a set of one or more requirements. These requirements define the major functions of the intended
application, define operational data areas and reference data areas, and define the initial data
entities. Major functions include critical processes to be managed, as well as mission critical
inputs, outputs and reports. A user class hierarchy is developed and associated with these major
functions, data areas, and data entities. Each of these definitions is termed a Requirement.
Requirements are identified by unique requirement identifiers and, at minimum, contain a
requirement title and textual description.
These requirements are fully described in the primary deliverables for this stage: the Requirements
Document and the Requirements Traceability Matrix (RTM). The requirements document contains
complete descriptions of each requirement, including diagrams and references to external
documents as necessary. Note that detailed listings of database tables and fields are not included
in the requirements document.
The title of each requirement is also placed into the first version of the RTM, along with the title
of each goal from the project plan. The purpose of the RTM is to show that the product components
11
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
developed during each stage of the software development lifecycle are formally connected to the
components developed in prior stages.
In the requirements stage, the RTM consists of a list of high-level requirements, or goals, by title,
with a listing of associated requirements for each goal, listed by requirement title. In this
hierarchical listing, the RTM shows that each requirement developed during this stage is formally
linked to a specific product goal. In this format, each requirement can be traced to a specific
product goal, hence the term requirements traceability.
The outputs of the requirements definition stage include the requirements document, the RTM,
and an updated project plan.
No. of staff required to handle a project is represented as Team Formation, in this case only
modules are individual tasks will be assigned to employees who are working for that
project.
Project Specifications are all about representing of various possible inputs submitting to
the server and corresponding outputs along with reports maintained by administrator.
Analysis Stage:
The planning stage establishes a bird's eye view of the intended software product, and uses this to
establish the basic project structure, evaluate feasibility and risks associated with the project, and
describe appropriate management and technical approaches.
12
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
The most critical section of the project plan is a listing of high-level product requirements, also
referred to as goals. All of the software product requirements to be developed during the
requirements definition stage flow from one or more of these goals. The minimum information for
each goal consists of a title and textual description, although additional information and references
to external documents may be included. The outputs of the project planning stage are the
configuration management plan, the quality assurance plan, and the project plan and schedule, with
a detailed listing of scheduled activities for the upcoming Requirements stage, and high level
estimates of effort for the out stages.
Designing Stage:
The design stage takes as its initial input the requirements identified in the approved requirements
document. For each requirement, a set of one or more design elements will be produced as a result
of interviews, workshops, and/or prototype efforts. Design elements describe the desired software
features in detail, and generally include functional hierarchy diagrams, screen layout diagrams,
tables of business rules, business process diagrams, pseudo code, and a complete entity-
relationship diagram with a full data dictionary. These design elements are intended to describe
13
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
the software in sufficient detail that skilled programmers may develop the software with minimal
additional input.
When the design document is finalized and accepted, the RTM is updated to show that each design
element is formally associated with a specific requirement. The outputs of the design stage are the
design document, an updated RTM, and an updated project plan.
The development stage takes as its primary input the design elements described in the approved
design document. For each design element, a set of one or more software artifacts will be produced.
Software artifacts include but are not limited to menus, dialogs, and data management forms, data
reporting formats, and specialized procedures and functions. Appropriate test cases will be
developed for each set of functionally related software artifacts, and an online help system will be
developed to guide users in their interactions with the software.
14
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
The RTM will be updated to show that each developed artifact is linked to a specific design
element, and that each developed artifact has one or more corresponding test case items. At this
point, the RTM is in its final configuration. The outputs of the development stage include a fully
functional set of software that satisfies the requirements and design elements previously
documented, an online help system that describes the operation of the software, an implementation
map that identifies the primary code entry points for all major system functions, a test plan that
describes the test cases to be used to validate the correctness and completeness of the software, an
updated RTM, and an updated project plan.
During the integration and test stage, the software artifacts, online help, and test data are migrated
from the development environment to a separate test environment. At this point, all test cases are
run to verify the correctness and completeness of the software. Successful execution of the test
suite confirms a robust and complete migration capability. During this stage, reference data is
finalized for production use and production users are identified and linked to their appropriate
15
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
roles. The final reference data (or links to reference data source files) and production user list are
compiled into the Production Initiation Plan.
The outputs of the integration and test stage include an integrated set of software, an online help
system, an implementation map, a production initiation plan that describes reference data and
production users, an acceptance plan which contains the final suite of test cases, and an updated
project plan.
During the installation and acceptance stage, the software artifacts, online help, and initial
production data are loa ded onto the production server. At this point, all test cases are run to
verify the correctness and completeness of the software. Successful execution of the test suite is a
prerequisite to acceptance of the software by the customer.
16
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
After customer personnel have verified that the initial production data load is correct and the test
suite has been executed with satisfactory results, the customer formally accepts the delivery of the
software.
The primary outputs of the installation and acceptance stage include a production application, a
completed acceptance test suite, and a memorandum of customer acceptance of the software.
Finally, the PDR enters the last of the actual labor data into the project schedule and locks the
project as a permanent project record. At this point the PDR "locks" the project by archiving all
software items, the implementation map, the source code, and the documentation for future
reference.
17
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Maintenance:
Outer rectangle represents maintenance of a project, Maintenance team will start with requirement
study, understanding of documentation later employees will be assigned work and they will
undergo training on that particular assigned category. For this life cycle there is no end, it will be
continued so on like an umbrella (no ending point to umbrella sticks).
CHAPTER 5
Overall Description
ECONOMIC FEASIBILITY
19
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
A system can be developed technically and that will be used if installed must still be a good
investment for the organization. In the economical feasibility, the development cost in creating the
system is evaluated against the ultimate benefit derived from the new systems. Financial benefits
must equal or exceed the costs. The system is economically feasible. It does not require any
addition hardware or software. Since the interface for this system is developed using the existing
resources and technologies available at NIC, There is nominal expenditure and economical
feasibility for certain.
OPERATIONAL FEASIBILITY
Proposed projects are beneficial only if they can be turned out into information system. That will
meet the organization’s operating requirements. Operational feasibility aspects of the project are
to be taken as an important part of the project implementation. This system is targeted to be in
accordance with the above-mentioned issues. Beforehand, the management issues and user
requirements have been taken into consideration. So there is no question of resistance from the
users that can undermine the possible application benefits. The well-planned design would ensure
the optimal utilization of the computer resources and would help in the improvement of
performance status.
TECHNICAL FEASIBILITY
Earlier no system existed to cater to the needs of ‘Secure Infrastructure Implementation System’.
The current system developed is technically feasible. It is a web based user interface for audit
workflow at NIC-CSD. Thus it provides an easy access to .the users. The database’s purpose is to
create, establish and maintain a workflow among various entities in order to facilitate all concerned
users in their various capacities or roles. Permission to the users would be granted based on the
roles specified. Therefore, it provides the technical guarantee of accuracy, reliability and security..
External Interface Requirements
User Interface
The user interface of this system is a user friendly python Graphical User Interface.
Hardware Interfaces
20
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
The interaction between the user and the console is achieved through python capabilities.
Software Interfaces
SYSTEM REQUIREMENT:
SOFTWARE REQUIREMENTS:
21
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
CHAPTER 6
SYSTEM DESIGN
The Unified Modelling Language allows the software engineer to express an analysis model using
the modelling notation that is governed by a set of syntactic semantic and pragmatic rules.
A UML system is represented using five different views that describe the system from distinctly
different perspective. Each view is defined by a set of diagram, which is as follows.
II. The analysis representation describes a usage scenario from the end-users perspective.
I. In this model the data and functionality are arrived from inside the system.
It represents the dynamic of behavioural as parts of the system, depicting the interactions of
collection between various structural elements described in the user model and structural model
view.
In this the structural and behavioural as parts of the system are represented as they are to be built.
Environmental Model View:In this the structural and behavioural aspects of the environment in
which the system is to be implemented are represented.
22
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
SYSTEM DESIGN
Class Diagram:
The class diagram is the main building block of object oriented modeling. It is used both for
general conceptual modeling of the systematic of the application, and for detailed modeling
translating the models into programming code. Class diagrams can also be used for data modeling.
The classes in a class diagram represent both the main objects, interactions in the application and
the classes to be programmed. In the diagram, classes are represented with boxes which contain
three parts:
23
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
A use case diagram at its simplest is a representation of a user's interaction with the system
and depicting the specifications of a use case. A use case diagram can portray the different types
of users of a system and the various ways that they interact with the system. This type of diagram
is typically used in conjunction with the textual use case and will often be accompanied by other
types of diagrams as well.
User Login
user
View Credited Cheques
NewUseCase5
24
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Sequence diagram:
A sequence diagram is a kind of interaction diagram that shows how processes operate with one
another and in what order. It is a construct of a Message Sequence Chart. A sequence diagram
shows object interactions arranged in time sequence. It depicts the objects and classes involved in
the scenario and the sequence of messages exchanged between the objects needed to carry out the
functionality of the scenario. Sequence diagrams are typically associated with use case realizations
in the Logical View of the system under development. Sequence diagrams are sometimes called
event diagrams, event scenarios, and timing diagrams
user upload weapon create & load weapo upload images detect weapon detect weapon FRCNN weapon detection
dataset n detection model from image from video training accuracy,Loss graph
upload weapon dataset
upload images
25
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Collaboration diagram:
detect weapon
from video
26
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Component Diagram:
In the Unified Modelling Language, a component diagram depicts how components are
wired together to form larger components and or software systems. They are used to illustrate the
structure of arbitrarily complex systems.
Components are wired together by using an assembly connector to connect the required
interface of one component with the provided interface of another component. This illustrates the
service consumer - service provider relationship between the two components.
upload weapo
n dataset
upload
images
user
detect weapo
n from image
detect weapo
n from video
27
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Deployment Diagram:
The nodes appear as boxes, and the artifacts allocated to each node appear as rectangles
within the boxes. Nodes may have sub nodes, which appear as nested boxes. A single node in a
deployment diagram may conceptually represent multiple physical nodes, such as a cluster of
database servers.
28
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
upload
weapon
create &
load
upload
images
user
detect
weapon
detect
weapon
FRCNN
weapon
Activity Diagram:
29
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Activity diagram is another important diagram in UML to describe dynamic aspects of the
system. It is basically a flow chart to represent the flow form one activity to another activity. The
activity can be described as an operation of the system. So the control flow is drawn from one
operation to another. This flow can be sequential, branched or concurrent
30
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Data flow diagrams illustrate how data is processed by a system in terms of inputs and outputs.
Data flow diagrams can be used to provide a clear representation of any business function. The
technique starts with an overall picture of the business and continues by analyzing each of the
functional areas of interest. This analysis can be carried out in precisely the level of detail
required. The technique exploits a method called top-down expansion to conduct the analysis in
a targeted way.
As the name suggests, Data Flow Diagram (DFD) is an illustration that explicates the passage of
information in a process. A DFD can be easily drawn using simple symbols. Additionally,
complicated processes can be easily automated by creating DFDs using easy-to-use, free
downloadable diagramming tools. A DFD is a model for constructing and analyzing information
processes. DFD illustrates the flow of information in a process depending upon the inputs and
outputs. A DFD can also be referred to as a Process Model. A DFD demonstrates business or
technical process with the support of the outside data saved, plus the data flowing from the process
to another and the end results
31
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
32
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
CHAPTER 7
IMPLEMETATION
Python
Python is a general-purpose language. It has wide range of applications from Web development
(like: Django and Bottle), scientific and mathematical computing (Orange, SymPy, NumPy) to
desktop graphical user Interfaces (Pygame, Panda3D). The syntax of the language is clean and
length of the code is relatively short. It's fun to work in Python because it allows you to think about
the problem rather than focusing on the syntax.
History of Python:
Python is a fairly old language created by Guido Van Rossum. The design began in the late 1980s
and was first released in February 1991.
In late 1980s, Guido Van Rossum was working on the Amoeba distributed operating system group.
He wanted to use an interpreted language like ABC (ABC has simple easy-to-understand syntax)
that could access the Amoeba system calls. So, he decided to create a language that was extensible.
This led to design of a new language which was later named Python.
No. It wasn't named after a dangerous snake. Rossum was fan of a comedy series from late
seventies. The name "Python" was adopted from the same series "Monty Python's Flying Circus".
Features of Python:
A simple language which is easier to learn : Python has a very simple and elegant syntax. It's
much easier to read and write Python programs compared to other languages like: C++, Java, C#.
Python makes programming fun and allows you to focus on the solution rather than syntax.
33
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
If you are a newbie, it's a great choice to start your journey with Python.
You can freely use and distribute Python, even for commercial use. Not only can you use and
distribute software’s written in it, you can even make changes to the Python's source code.
Portability
You can move Python programs from one platform to another, and run it without any changes.
It runs seamlessly on almost all platforms including Windows, Mac OS X and Linux.
Suppose an application requires high performance. You can easily combine pieces of C/C++ or
other languages with Python code.
This will give your application high performance as well as scripting capabilities which other
languages may not provide out of the box.
Unlike C/C++, you don't have to worry about daunting tasks like memory management, garbage
collection and so on.
Likewise, when you run Python code, it automatically converts your code to the language your
computer understands. You don't need to worry about any lower-level operations.
Python has a number of standard libraries which makes life of a programmer much easier since
you don't have to write all the code yourself. For example: Need to connect MySQL database on
a Web server? You can use MySQLdb library using import MySQLdb .
34
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Standard libraries in Python are well tested and used by hundreds of people. So you can be sure
that it won't break your application.
Object-oriented
Everything in Python is an object. Object oriented programming (OOP) helps you solve a complex
problem intuitively.
With OOP, you are able to divide these complex problems into smaller sets by creating objects.
Applications of Python:
Programming in Python is fun. It's easier to understand and write Python code. Why? The syntax
feels natural. Take this source code for an example:
a=2
b=3
sum = a + b
print(sum)
You don't need to define the type of a variable in Python. Also, it's not necessary to add semicolon
at the end of the statement.
Python enforces you to follow good practices (like proper indentation). These small things can
make learning much easier for beginners.
Python allows you to write programs having greater functionality with fewer lines of code. Here's
a link to the source code of Tic-tac-toe game with a graphical interface and a smart computer
35
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
opponent in less than 500 lines of code. This is just an example. You will be amazed how much
you can do with Python once you learn the basics.
Python has a large supporting community. There are numerous active forums online which can be
handy if you are stuck.
CHAPTER 8
36
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
SAMPLE CODE
import tkinter
import numpy as np
import cv2
import pickle
import os
import keras
37
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
import xml.etree.ElementTree as ET
main = tkinter.Tk()
main.title("Weapon Detection")
main.geometry("1300x900")
X = []
38
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
Y = []
bb = []
bb = []
x = max(xmin * conv_x, 0)
y = max(ymin * conv_y, 0)
x = x / 128
y = y / 128
width = width/128
height = height/128
def createFRCNNModel():
global X, Y, bb
39
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2)#split dataset into train and
test
#create FRCNN layers with 32, 64 and 512 neurons or data filteration size
x = MaxPooling2D((2, 2))(x)
x = MaxPooling2D((2, 2))(x)
x = Flatten()(x)
#define output layer with 4 bounding box coordinate and 1 weapan class
40
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
model_check_point = ModelCheckpoint(filepath='model/frcnn_model_weights.hdf5',
verbose = 1, save_best_only = True)
f = open('model/history.pckl', 'wb')
pickle.dump(hist.history, f)
f.close()
frcnn_model.load_weights("model/frcnn_model_weights.hdf5")
a = accuracy_score(test,predict)*100
41
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
text.update_idletasks()
def uploadDataset():
global X, Y, BB
Y = to_categorical(Y)
else:
for j in range(len(directory)):
tree = ET.parse('Dataset/annotations/xmls/'+directory[j])
root = tree.getroot()
42
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
ymin = int(item.find('bndbox/ymin').text)
xmax = int(item.find('bndbox/xmax').text)
ymax = int(item.find('bndbox/ymax').text)
X.append(img)
Y = np.asarray(Y)
bb = np.asarray(bb)
43
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
np.save('model/Y.txt',Y)
np.save('model/bb.txt',bb)
text.insert(END,"Dataset Loaded\n")
def loadModel():
text.delete('1.0', END)
classes = ['Weapon']
layer_names = model.getLayerNames()
createFRCNNModel()
def detectWeapon():
img = cv2.imread(filename)
model.setInput(blob)
outs = model.forward(output_layers)
class_ids = []
confidences = []
boxes = []
score = []
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
scr = np.amax(scores)
# Object detected
w = int(detection[2] * width)
45
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
h = int(detection[3] * height)
# Rectangle coordinates
x = int(center_x - w / 2)
y = int(center_y - h / 2)
score.append(scr)
boxes.append([x, y, w, h])
confidences.append(float(confidence))
class_ids.append(class_id)
if indexes == 0:
flag = 0
font = cv2.FONT_HERSHEY_PLAIN
for i in range(len(boxes)):
if i in indexes:
x, y, w, h = boxes[i]
print(str(class_ids[i])+" "+str(score[i]))
label = str(classes[class_ids[i]])
46
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
color = colors[class_ids[i]]
flag = 1
if flag == 0:
cv2.imshow("Image", img)
cv2.waitKey(0)
def uploadImage():
global filename
text.delete('1.0', END)
text.insert(END,filename+" loaded\n")
def detectVideoWeapon():
cap = cv2.VideoCapture(filename)
47
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
while True:
_, img = cap.read()
model.setInput(blob)
outs = model.forward(output_layers)
class_ids = []
confidences = []
boxes = []
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
# Object detected
w = int(detection[2] * width)
h = int(detection[3] * height)
48
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
# Rectangle coordinates
x = int(center_x - w / 2)
y = int(center_y - h / 2)
boxes.append([x, y, w, h])
confidences.append(float(confidence))
class_ids.append(class_id)
print(indexes)
font = cv2.FONT_HERSHEY_PLAIN
for i in range(len(boxes)):
if i in indexes:
x, y, w, h = boxes[i]
label = str(classes[class_ids[i]])
color = colors[class_ids[i]]
cv2.imshow("Image", img)
49
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
break
cap.release()
cv2.destroyAllWindows()
def graph():
f = open('model/history.pckl', 'rb')
data = pickle.load(f)
f.close()
accuracy = data['class_accuracy']
loss = data['class_loss']
axs[0].set_xlabel('Epochs')
axs[0].set_ylabel('Accuracy')
50
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
axs[1].set_xlabel('Epochs')
axs[1].set_ylabel('Loss')
plt.show()
title.config(bg='black', fg='white')
title.config(font=font)
title.config(height=3, width=120)
title.place(x=0,y=5)
uploadDatasetButton.place(x=50,y=100)
uploadDatasetButton.config(font=font1)
51
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
loadButton.place(x=300,y=100)
loadButton.config(font=font1)
uploadButton.place(x=50,y=150)
uploadButton.config(font=font1)
detectButton.place(x=50,y=200)
detectButton.config(font=font1)
videoButton.place(x=50,y=250)
videoButton.config(font=font1)
graphButton.place(x=50,y=300)
52
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
graphButton.config(font=font1)
text=Text(main,height=20,width=120)
scroll=Scrollbar(text)
text.configure(yscrollcommand=scroll.set)
text.place(x=10,y=350)
text.config(font=font1)
main.config(bg='chocolate1')
main.mainloop()
CHAPTER 9
SYSTEM TESTING
53
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
54
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
55
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
56
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
CHAPTER 10
SCREEN SHOTS
In above screen click on ‘Upload Weapon Dataset’ button to upload dataset and get below output
57
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
In above screen selecting and uploading entire XML folder with annotating bounding boxes and
images path and then click on ‘Select Folder’ button to load dataset and get below output
In above screen we can see 1057 weapon images loaded from dataset and now click on ‘Generate
& Load Weapon Detection Model’ button to train FRCNN model and get below output
58
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
In above screen FRCNN model loaded and we got it accuracy as 73% and we can see other metrics
also and now click on ‘Upload Image’ button to upload image and get below output
In above screen selecting and uploading image and then click on ‘Open’ button and ‘Detect
Weapon from Image’ button to get below output
59
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
In above screen in image weapon is detected and now similarly click on ‘Detect Weapon from
Video’ button to upload video file and get below output
In above screen selecting and uploading MP4 video file and then click on ‘Open’ button to start
video playing and if your system fast then video will play faster otherwise slow
60
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
In above screen you can see video start playing and we can see detection output also and now click
on ‘FRCNN Weapon Detection Training Accuracy-Loss Graph’ button to get below output
61
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
In above screen you can see video start playing and we can see detection output also and now click
on ‘FRCNN Weapon Detection Training Accuracy-Loss Graph’ button to get below output
In above training graphs x-axis represents training EPOCH and y-axis represents accuracy and loss
values and green line represents accuracy and red line represents LOSS and with each increasing
epoch accuracy got increase and loss got decrease. Similarly you can upload and test other images.
62
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
CHAPTER 11
CONCLUSION:
SSD and Faster RCNN algorithms are simulated for pre labeled and self-created image dataset for
weapon (gun) detection. Both the algorithms are efficient and give good results but their
application in real time is based on a tradeoff between speed and accuracy. In terms of speed, SSD
algorithm gives better speed with 0.736 s/frame. Whereas Faster RCNN gives speed 1.606s/frame,
which is poor compared to SSD. With respect to accuracy, Faster RCNN gives better accuracy of
84.6%. Whereas SSD gives an accuracy of 73.8%, which is poor compared to faster RCNN.SSD
provided real time detection due to faster speed but Faster RCNN provided superior accuracy.
Further, it can be implemented for larger datasets by training us ing GPUs and high-end DSP and
FPGA kits.
FUTURE ENHANCEMENTS:
The project demonstrated a trade-off between speed and accuracy, making each
model suitable for different applications. The system performed well on image and
video inputs, providing a robust foundation for practical surveillance applications
using Python and GUI interfaces.
Implement the models with larger and more diverse datasets to improve
generalization and robustness.
Hardware Acceleration:
Extend the model to detect multiple types of weapons (e.g., knives, rifles,
explosives) rather than focusing on guns alone.
CHAPTER 12
64
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
REFERENCES
[1] Wei Liu et al., “SSD: Single Shot MultiBox Detector”, European Conference on Conputer
Vision, Volume 169, pp 20-31 Sep. 2017.
[2] D. Erhan et al., “Scalable Object Detection Using Deep Neural Networks,” IEEE Conference
on Computer Vision and Pattern Recognition(CVPR),2014.
[3] Ruben J Franklin et.al., “Anomaly Detection in Videos for Video Surveillance Applications
Using Neural Networks,” International Conference on Inventive Systems and Control,2020.
[4] H R Rohit et.al., “A Review of Artificial Intelligence Methods for Data Science and Data
Analytics: Applications and Research Challenges,”2018 2nd International Conference on I-SMAC
(IoT in Social, Mobile, Analytics and Cloud), 2018.
[5] Abhiraj Biswas et. al., “Classification of Objects in Video Records using Neural Network
Framework,” International conference on Smart Systems and Inventive Technology,2018.
[6] Pallavi Raj et. al.,“Simulation and Performance Analysis of Feature Extraction and Matching
Algorithms for Image Processing Applications” IEEE International Conference on Intelligent
Sustainable Systems,2019. [7] Mohana et.al., “Simulation of Object Detection Algorithms for
Video Survillance Applications”, International Conference on I-SMAC (IoT in Social, Mobile,
Analytics and Cloud),2018.
[8] Yojan Chitkara et. al.,“Background Modelling techniques for foreground detection and
Tracking using Gaussian Mixture model” International Conference on Computing Methodologies
and Communication,2019.
[9] Rubner et.al, “A metric for distributions with applications to image databases”, International
Conference on Computer Vision,2016.
[10] N. Jain et.al., “Performance Analysis of Object Detection and Tracking Algorithms for Traffic
Surveillance Applications using Neural Networks,” 2019 Third International conference on I-
SMAC (IoT in Social, Mobile, Analytics and Cloud), 2019.
65
Dept. of CSE(AI&ML)
WEAPON DETECTION USING FASTER R-CNN
[11] A. Glowacz et.al., “Visual Detection of Knives in Security Applications using Active
Appearance Model”,Multimedia Tools Applications, 2015.
[13] Ayush Jain et.al.,“Survey on Edge Computing - Key Technology in Retail Industry”
International Conference on Intelligent Computing and Control Systems,2019.
[14] Mohana et.al., Performance Evaluation of Background Modeling Methods for Object
Detection and Tracking,” International Conference on Inventive Systems and Control,2020.
[15] J. Wang et.al., “Detecting static objects in busy scenes”, Technical Report TR99-1730,
Department of Computer Science, Cornell University, 2014.
[16] V. P. Korakoppa et.al., “An area efficient FPGA implementation of moving object detection
and face detection using adaptive threshold method,” International Conference on Recent Trends
in Electronics, Information & Communication Technology,2017.
[17] S. K. Mankani et.al., “Real-time implementation of object detection and tracking on DSP for
video surveillance applications,”International Conference on Recent Trends in Electronics,
Information & Communication Technology,2016.
66
Dept. of CSE(AI&ML)