Mca - Doc Full - 28
Mca - Doc Full - 28
PROJECT REPORT
Submitted by
of
ENGINEERING
(AUTONOMOUS)
PROJECT REPORT
Submitted by
of
ENGINEERING
(AUTONOMOUS)
i
DHANALAKSHMI SRINIVASAN ENGINEERING
COLLEGE (AUTONOMOUS)
BONAFIDE CERTIFICATE
SIGNATURE SIGNATURE
I express my gratitude and thanks to my Parents first for giving health and a
sound mind for completing this project. I give all the glory and thanks to almighty
GOD for showering upon, the necessary wisdom and grace for accomplishing this
project.
iii
ABSTRACT
The existing system for weapon detection in home surveillance cameras aims to
enhance security by employing AI algorithms to analyze video feeds for the presence
of firearms or other threatening objects. In home surveillance camera-based weapon
detection systems, a real-time challenge arises from the difficulty in accurately
distinguishing between actual weapons and harmless objects, often leading to false
alarms and compromising security effectiveness. In this weapon detection system using
convolutional neural network flask web application in Difficulty integrating real-time
video feed with the YOLO model for accurate weapon detection. Deployment
challenges with Flask web app scalability and performance optimization. A lack of
regular updates in the weapon detection system's deep learning algorithms can result in
increased false positives, potentially leading to mistrust in the system's reliability and
compromising security measures. The weapon detection system using flask web
application employs cutting-edge technology to enhance public safety, detecting
weapons in real-time images or video streams. through models training on weapon and
non-weapon datasets, it accurately identifies firearms, knives, or other threats. The flask
web app enables users to upload images or stream video for instant detection, ensuring
a swift response to potential dangers. leveraging deep learning and web technology, it
proactively prevents violence and safeguards individuals in diverse settings like
airports, schools, or public events.
iv
TABLE OF CONTENT
ABSTRACT
LIST OF FIGURES
LIST OF ABBREVIATION
1 INTRODUCTION 1
2 LITERATURE SURVEY 9
v
2.5. DEEP LEARNING ALGORITHMS-BASED
OBJECT DETECTION AND LOCALIZATION 13
REVISITED
2.6. A SURVEY ON POLICE PREVENTIVE ACTION
14
TRACKING SYSTEM USING AI
2.7. AUTOMATIC WEAPON DETECTION FOR
15
SURVEILLANCE APPLICATIONS
2.8. WEAPON DETECTION USING ARTIFICIAL
INTELLIGENCE AND DEEP LEARNING FOR 16
SECURITY APPLICATIONS
2.9. WEAPON DETECTION USING YOLO V3 FOR
17
SMART SURVEILLANCE SYSTEM
2.10. REAL-TIME CONCEALED OBJECT
DETECTION FROM PASSIVE MILLIMETER WAVE 18
IMAGES BASED ON THE YOLOV3 ALGORITHM
3 SYSTEM ANALYSIS 19
3.1.1. DISADVANTAGES 19
3.2.1. ADVANTAGES 20
4 SYSTEM SPECIFICATION 21
5 SYSTEM IMPLEMENTATION 22
6 SYSTEM DESIGN 24
vi
6.1 SYSTEM ARCHITECTURE 24
7 SOFTWARE DESCRIPTION 33
7.1 PYTHON 33
7.2 MY SQL 39
8 SYSTEM TESTING 46
9.1 CONCLUSION 49
10 APPENDICES 51
REFERENCES 74
vii
LIST OF FIGURES
PAGE
FIGURE NO FIGURE NAME
NO
viii
LIST OF ABBREVIATION
DL - DEEP LEARNING
ix
CHAPTER 1
INTRODUCTION
Object detection is a fundamental task in computer vision, essential for a wide range of
applications such as autonomous vehicles, surveillance systems, and image
understanding. In recent years, deep learning has revolutionized the field of computer
vision, particularly with the advent of Convolutional Neural Networks (CNNs). These
neural networks have demonstrated remarkable performance in various vision tasks,
including object detection.
CNNs are a class of deep neural networks specifically designed to process and analyze
visual data. They are inspired by the organization of the animal visual cortex and consist
of multiple layers of interconnected neurons, each performing convolution operations
to extract hierarchical features from input images. This hierarchical feature extraction
enables CNNs to effectively capture spatial patterns and relationships within images,
making them well-suited for tasks like object detection.
One of the most prominent architectures in the realm of object detection is the You Only
Look Once (YOLO) framework. YOLO represents a paradigm shift in object detection
by reframing it as a single regression problem, rather than treating it as a series of
classification and localization tasks. The latest iteration, YOLOv5, builds upon this
foundation with significant improvements in speed, accuracy, and versatility.
YOLOv5 is a deep learning model that employs a CNN backbone to detect objects in
images with remarkable efficiency and precision. It combines state-of-the-art
architectural innovations with advanced training techniques to achieve real-time
performance on a variety of hardware platforms. YOLOv5 introduces a streamlined
architecture that leverages the power of modern GPUs and accelerators, making it
highly scalable and adaptable to different computational environments. At the core of
YOLOv5 lies a novel CNN architecture optimized for object detection. This
architecture consists of multiple convolutional layers organized in a hierarchical
fashion, with each layer progressively refining the features extracted from the input
1
image. The network learns to localize and classify objects by directly regressing
bounding boxes and class probabilities from the raw image pixels, eliminating the need
for complex post-processing steps.
One of the key advantages of YOLOv5 is its versatility and ease of use. It supports a
wide range of object classes and can be trained on custom datasets with minimal effort.
The model comes with pre-trained weights on large-scale datasets such as COCO and
ImageNet, allowing users to quickly fine-tune it for specific applications. Additionally,
YOLOv5 provides comprehensive tools for data augmentation, model evaluation, and
deployment, making it accessible to both researchers and practitioners.
YOLO, an acronym for "You Only Live Once," has transcended its origin as a simple
phrase and morphed into a cultural phenomenon that has captured the attention of
millions worldwide. Its popularity can be attributed to a myriad of factors, ranging from
its resonance with youth culture to its philosophical undertones and its widespread
adoption in social media. At its core, YOLO embodies a sentiment of seizing the
moment, living life to the fullest, and embracing experiences with gusto and abandon.
First and foremost, YOLO has struck a chord with younger generations, particularly
millennials and Generation Z, who are often characterized by their desire for
authenticity, adventure, and self-expression. In a world inundated with societal
expectations and pressures, YOLO serves as a rallying cry for individualism and
freedom. It encourages people to break free from the constraints of conformity and
societal norms, empowering them to pursue their passions and dreams without
reservation.
2
Moreover, YOLO encapsulates a philosophical outlook on life that emphasizes the
fleeting nature of existence and the importance of making the most out of every
moment. This existential perspective resonates deeply with individuals seeking
meaning and purpose in an increasingly chaotic and uncertain world. By embracing the
philosophy of YOLO, people are inspired to prioritize experiences over material
possessions, relationships over status, and personal growth over societal validation.
Furthermore, the rise of social media platforms, such as Instagram, Snapchat, and
TikTok, has played a pivotal role in popularizing YOLO culture. These platforms
provide a stage for individuals to showcase their adventurous exploits, spontaneous
adventures, and carefree lifestyle, thereby fueling the allure of YOLO. The constant
stream of curated content featuring exhilarating experiences and daring escapades
serves as a catalyst for others to embrace the YOLO mentality and embark on their own
adventures. Additionally, the entertainment industry has also contributed to the
proliferation of YOLO culture through various mediums, including music, film, and
television. Countless songs, movies, and TV shows have incorporated YOLO into their
lyrics, dialogue, and themes, further embedding the concept into mainstream
consciousness. Whether it's Drake's chart-topping anthem "The Motto" or the countless
memes and references found across social media, YOLO has become synonymous with
living life boldly and without regret.
Furthermore, the rise of travel culture has intersected seamlessly with the ethos of
YOLO, as more and more people seek to explore the world and immerse themselves in
new cultures and experiences. The advent of budget airlines, shared accommodation
services, and travel blogs has democratized travel and made it more accessible to a
wider audience, encouraging individuals to embrace the YOLO mentality and embark
on spontaneous adventures around the globe.
Implementing real-time object detection using YOLO (You Only Look Once) involves
several steps, including understanding the YOLO architecture, preparing the dataset,
training the model, and deploying it for real-time inference. YOLO is a popular deep
learning-based algorithm for object detection that achieves high accuracy and
efficiency by dividing the input image into a grid and predicting bounding boxes and
3
class probabilities directly from the grid cells. Here's a detailed walkthrough of how to
implement real-time object detection using YOLO.
Understanding YOLO Architecture: YOLO divides the input image into an 𝑆×S grid.
Each grid cell predicts multiple bounding boxes along with their confidence scores and
class probabilities. Unlike traditional methods that slide a window over the image,
YOLO performs detection in a single pass through the network, making it extremely
fast. The network architecture typically consists of convolutional layers followed by
fully connected layers to make predictions.
Preparing the Dataset: A crucial step in implementing object detection using YOLO
is preparing a labeled dataset. The dataset should contain images along with their
corresponding bounding box annotations and class labels. Popular datasets for object
detection include COCO (Common Objects in Context) and PASCAL VOC (Visual
Object Classes). Each annotation should include the coordinates of the bounding box
and the class label for each object in the image.
Training the Model: Once the dataset is prepared, the next step is to train the YOLO
model. This involves initializing the YOLO network with pre-trained weights (usually
trained on ImageNet), and fine-tuning it on the custom dataset using techniques like
stochastic gradient descent (SGD) or Adam optimization. During training, the model
learns to predict bounding boxes and class probabilities that minimize a predefined loss
function, such as the combination of localization loss and confidence loss.
Deploying for Real-Time Inference: After training, the YOLO model can be deployed
for real-time inference on live video streams or recorded videos. Real-time inference
requires efficient hardware and software optimizations to achieve high frame rates.
Optimizations such as model quantization, pruning, and using specialized hardware like
GPUs or TPUs can significantly improve inference speed. Additionally, techniques like
batch processing and asynchronous inference can further enhance real-time
performance. To implement real-time object detection, the trained YOLO model is
loaded into memory, and input frames from the video stream are passed through the
model to generate predictions. The bounding boxes and class labels predicted by the
model are then overlaid onto the input frames to visualize the detected objects in real-
time. This process is repeated for each frame in the video stream, allowing for
4
continuous object detection in real-time. Furthermore, deploying YOLO for real-time
inference may involve integrating the model with a software application or system, such
as a surveillance system, autonomous vehicle, or smart camera. This integration
requires developing custom software to handle video input/output, model loading,
inference, and result visualization. Additionally, considerations such as latency,
throughput, and resource constraints need to be taken into account to ensure smooth
and efficient operation in real-world scenarios.
Deep learning has evolved hand-in-hand with the digital era, which has brought
about an explosion of data in all forms and from every region of the world. This data,
known simply as big data, is drawn from sources like social media, internet search
engines, e-commerce platforms, and online cinemas, among others. This enormous
amount of data is readily accessible and can be shared through fintech applications like
cloud computing. However, the data, which normally is unstructured, is so vast that it
could take decades for humans to comprehend it and extract relevant information.
Companies realize the incredible potential that can result from unraveling this
wealth of information and are increasingly adapting to AI systems for automated
support. One of the most common AI techniques used for processing big data is machine
learning, a self-adaptive algorithm that gets increasingly better analysis and patterns
with experience or with newly added data.
5
• Fundamental concepts of Deep Learning, including various Neural Networks
for supervised and unsupervised learning.
• Use of popular Deep Learning libraries such as Keras, PyTorch, and Tensor
flow applied to industry problems.
Feedforward Neural Networks (FNN): These are the simplest form of neural
networks, where information flows in one direction, from input nodes through hidden
layers to output nodes. They're commonly used for tasks like classification and
regression.
6
between real and fake data. GANs are used for generating realistic synthetic data,
image-to-image translation, and more.
Deep Belief Networks (DBN): DBNs are probabilistic generative models composed of
multiple layers of stochastic, latent variables. They are typically trained greedily, layer
by layer, using unsupervised learning techniques such as Restricted Boltzmann
Machines (RBMs).
Capsule Networks: Capsule networks are a recent advancement in deep learning that
aim to overcome some of the limitations of CNNs, particularly in handling hierarchical
relationships and spatial hierarchies within images.
7
The architecture of a CNN typically consists of several layers, each serving a specific
purpose in the feature extraction process. The first layer, known as the input layer,
receives the raw pixel values of an image. Subsequent layers, called convolutional
layers, apply convolution operations to extract various features such as edges, textures,
and shapes. These layers are followed by activation functions, such as the Rectified
Linear Unit (ReLU), which introduce non-linearities to the network, allowing it to learn
more complex relationships within the data. Pooling layers are another crucial
component of CNNs, often inserted after convolutional layers. Pooling operations, such
as max pooling or average pooling, reduce the spatial dimensions of the feature maps,
thereby decreasing the computational complexity of the network while retaining
important information. This down sampling process also helps in making the network
more robust to variations in the input data, such as changes in scale or orientation.
Beyond the convolutional and pooling layers, CNN architectures may also include fully
connected layers, which serve as the final stages of the network for classification or
regression tasks. These layers take the high-level features extracted by the preceding
layers and map them to the desired output, whether it be class labels in the case of image
classification or numerical values for regression tasks. One of the key strengths of
CNNs lies in their ability to automatically learn features from raw data, alleviating the
need for manual feature engineering. Through the process of backpropagation and
gradient descent, CNNs adjust their internal parameters, known as weights and biases,
to minimize the discrepancy between predicted outputs and ground truth labels. This
iterative learning process allows CNNs to adapt to various datasets and tasks, making
them highly versatile across a wide range of applications.
8
CHAPTER 2
LITERATURE SURVEY
DISADVANTAGES:
9
2.2. TITLE: HAWK-EYE: AN AI-POWERED THREAT DETECTOR FOR
INTELLIGENT SURVEILLANCE CAMERAS
Presenting Hawk-Eye, an advanced AI-driven threat detection system tailored for real-
time video surveillance. This pioneering prototype operates directly on the camera at
the edge, delivering exceptional prediction accuracy and swift response times. Powered
by Intel NCS 2 and Raspberry Pi 3, it efficiently processes data without relying on cloud
infrastructure. Employing cutting-edge models such as Mask R-CNN for precise
instance segmentation, Hawk-Eye swiftly identifies weapons in surveillance footage,
enabling prompt security interventions. With its intuitive interface accessible locally
and on the cloud, users can seamlessly interact with the system. Additionally, a motion
detection module enhances its real-time monitoring capabilities, ensuring
comprehensive surveillance coverage. Through meticulous experimentation, the
system demonstrates outstanding processing speeds, surpassing industry standards for
frames per second metrics. The team's dedication to open-source principles is evident
as they openly share their code and dataset, fostering collaboration and driving
innovation in the field of video surveillance. This transparent approach encourages
knowledge exchange and facilitates advancements, benefiting both researchers and
practitioners alike. Hawk-Eye represents a significant leap forward in AI-powered
threat detection, offering reliable and efficient surveillance solutions for various
security applications.
DISADVANTAGES:
10
2.3. TITLE: GESTURE DETECTION AND RECOGNITION BASED ON
OBJECT DETECTION IN COMPLEX BACKGROUND
In the study, an advanced gesture detection and recognition algorithm has been
developed, notable for its speed, precision, and resilience in identifying gestures against
complex backgrounds. The approach integrates two main components: the efficient
layer aggregation network module and the CBAM attention mechanism module.
Through the utilization of these modules, the model's parameters are streamlined, while
its capability to extract features effectively is enhanced, thereby improving its ability to
detect gestures amidst intricate backgrounds. This method surpasses existing
techniques in gesture detection and recognition, a conclusion supported by extensive
experimentation. Moving forward, the research aims to enhance recognition accuracy
with fewer samples and enhance the network's adaptability by removing anchor boxes
without compromising recognition accuracy. Additionally, there is a keen interest in
exploring the application of the model in detection and recognition across various
contexts.
DISADVANTAGES:
11
2.4. TITLE: A NOVEL APPROACH FOR OBJECT IDENTIFICATION WITH
DEEP REINFORCEMENT MACHINE LEARNING
The paper introduces an innovative method for object identification in images, utilizing
a reinforcement learning framework. The model proposes the utilization of a
reinforcement learning agent to determine the optimal policy for placing a mask in the
correct position to identify objects within the image. Building upon the foundational
principles of the faster RCNN model, the primary aim is to achieve precise and efficient
object identification within minimal computational time. Through the integration of
reinforcement learning, wherein the agent computes rewards and adapts its policy using
Q-learning, the model presents a streamlined approach to dynamically learn the optimal
identification strategy. Unlike traditional methodologies, this approach recognizes that
each object may not conform to a standardized search trajectory, enabling the agent to
learn iteratively from its errors and experiences, thereby refining the identification
process iteratively. The implementation of the model is executed using Python
Anaconda, facilitating efficient computational execution. Experimental findings
validate the efficacy of the proposed method, showcasing its ability to accurately
identify object instances by analyzing 10 to 15 regions within the image.
DISADVANTAGES:
12
2.5. TITLE: DEEP LEARNING ALGORITHMS-BASED OBJECT
DETECTION AND LOCALIZATION REVISITED
This paper provides a thorough overview of the advancements in computer vision (CV)
fields, particularly focusing on object detection (OD) and localizations using deep
learning (DL) algorithms. DL-based ODs have demonstrated significant potential due
to their robust learning capabilities, effectively addressing challenges such as
occlusions, scale transformations, and background variations. As demands for OD
technologies continue to grow, there is a push towards developing comprehensive
networks capable of localizing and classifying objects simultaneously, facilitated by
back-propagation training methods. Recent models have prioritized high-performance
prediction capacity, indicating ongoing progress in the field. Despite advancements, the
CV domain remains in its early stages, with numerous avenues for further exploration
and intensive study to gain deeper insights into OD landscapes. In essence, this article
serves as a detailed roadmap, delineating the progression of neural networks and
associated learning systems within the CV field, thereby facilitating navigation and
understanding of this rapidly evolving area of research.
DISADVANTAGES:
13
2.6. TITLE: A SURVEY ON POLICE PREVENTIVE ACTION TRACKING
SYSTEM USING AI
DISADVANTAGES:
14
2.7. TITLE: AUTOMATIC WEAPON DETECTION FOR SURVEILLANCE
APPLICATIONS
A machine learning model has been developed specifically to identify weapons like
knives, small guns, and long guns by analyzing images and videos obtained from
closed-circuit television (CCTV) systems. Upon detection of a weapon, the system
activates an alarm. The model currently demonstrates an accuracy level of around 85%.
To further enhance the model's capabilities, the acquisition of additional data pertaining
to various weapons, both with and without labels, is essential. This data would facilitate
more robust training, potentially leading to improved accuracy and performance.
Additionally, integrating graphical processing units (GPUs), digital signal processors
(DSPs), and other specialized hardware kits could significantly enhance the model's
efficiency. Expanding the model's scope beyond weapon detection is a promising
avenue for development. By incorporating data related to other criminal activities such
as robbery, the system could contribute significantly to crime reduction efforts. Its real-
time application has the potential to play a pivotal role in proactive crime prevention
strategies. Furthermore, the model's adaptability makes it a valuable asset in various
security contexts. For instance, it could be deployed in public spaces, transportation
hubs, or high-security facilities to preemptively identify and address potential threats.
Moreover, the scalability of the model allows for its implementation across diverse
environments, catering to the unique security needs of different settings.
DISADVANTAGES:
15
2.8. TITLE: WEAPON DETECTION USING ARTIFICIAL INTELLIGENCE
AND DEEP LEARNING FOR SECURITY APPLICATIONS
Weapon detection utilizing the YOLO (You Only Look Once) algorithm presents a
robust solution for reinforcing security and public safety measures. The algorithm's
capacity for real-time processing, alongside its accuracy and adaptability, renders it a
valuable tool for automatically identifying weapons within images and video streams.
YOLO's efficiency stems from its rapid analysis of images and video frames, enabling
its application across various scenarios where timely weapon detection is crucial.
Furthermore, its precise object detection capabilities help minimize false alarms,
ensuring reliable weapon identification. By automating the detection process, YOLO
streamlines security operations, reducing the need for manual inspection and thereby
improving overall efficiency. The versatility of YOLO extends its utility to diverse
domains, including surveillance, public safety, and access control. It is worth noting
that the effectiveness of weapon detection using YOLO relies on meticulous dataset
collection, annotation, and model training to achieve optimal detection accuracy. The
YOLO algorithm's prowess lies in its ability to swiftly process images and videos,
enabling it to detect weapons in real-time. This capability is instrumental in various
scenarios where prompt action is required, such as in airports, public events, or high-
security facilities. By accurately identifying weapons, YOLO helps security personnel
intervene swiftly, potentially preventing dangerous situations from escalating.
Moreover, YOLO's precision in object detection is crucial for minimizing false alarms.
This ensures that security personnel can trust the system's alerts, allowing them to focus
their attention where it is needed most.
DISADVANTAGES:
• Despite its accuracy, YOLO may still miss detecting certain weapons in
complex.
• The use of YOLO for surveillance and public safety may raise privacy issues.
• Developing and deploying YOLO-based systems for weapon detection could
entail significant financial investments in hardware and software resources.
16
2.9. TITLE: WEAPON DETECTION USING YOLO V3 FOR SMART
SURVEILLANCE SYSTEM
This study, the cutting-edge YOLO V3 object detection model has been implemented,
meticulously trained using a curated dataset tailored specifically for weapon detection
purposes. The model's primary objective is to equip machines or robots with the
capability to discern potentially hazardous weaponry and promptly alert human
administrators upon detecting guns or firearms within the designated perimeter.
Experimental results showcased the superior efficacy of the trained YOLO V3 model
when compared to its predecessor, YOLO V2, additionally offering the advantage of
reduced computational costs. The urgency to enhance current surveillance capabilities
is underscored by the imperative to leverage advanced resources in monitoring the
effectiveness of human operators. The emergence of smart surveillance systems marks
a significant transformative juncture, facilitated by the increasingly accessible low-cost
storage solutions, robust video infrastructure, and enhanced video processing
technologies. The implementation of the YOLO V3 model signifies a significant stride
forward in the domain of object detection, particularly in the context of weapon
recognition and threat assessment. By harnessing meticulously curated datasets, this
model has been fine-tuned to detect firearms with a high degree of accuracy,
minimizing false positives and false negatives.
DISADVANTAGES:
17
2.10. TITLE: REAL-TIME CONCEALED OBJECT DETECTION FROM
PASSIVE MILLIMETER WAVE IMAGES BASED ON THE YOLOV3
ALGORITHM
In the realm of security screening for expansive public venues, there has been a notable
shift away from conventional metal security gates and X-ray detectors towards the
adoption of non-contact and non-cooperative Passive Millimeter Wave (PMMW)
imagers. These imagers have emerged as the favored choice for such purposes.
Concurrently, the YOLO (You Only Look Once) algorithm has risen to prominence
due to its exceptional efficiency in real-time detection tasks, showing considerable
potential for further advancements. This study focuses specifically on the real-time
detection of metal contraband concealed on the human body utilizing PMMW images.
The approach involves employing a modest dataset in conjunction with YOLOv3
algorithms. Training procedures were conducted utilizing YOLOv3-13 and YOLOv3-
53 target detection models, each with varying convolutional layers. Subsequent analysis
aimed to delineate their individual strengths and weaknesses. Additionally,
comparative assessments were undertaken, juxtaposing these YOLO models with SSD
(Single Shot Multibox Detector) algorithms based on empirical results. The outcomes
of this study underscore the efficacy of YOLOv3-based methods for detecting
contraband within PMMW images in real-time scenarios, effectively meeting the
demands of high passenger volumes. This efficacy persists despite the utilization of a
limited sample dataset. Notably, the YOLOv3-53 model demonstrates a comparative
advantage and efficacy over its YOLOv3-13 counterpart, particularly when considering
trade-offs between detection accuracy, processing speed, and computational resource
utilization.
DISADVANTAGES:
18
CHAPTER 3
SYSTEM ANALYSIS
Existing weapon detection systems for home surveillance cameras utilize a variety of
technological approaches to enhance security and ensure the safety of residents. These
systems typically employ advanced algorithms and machine learning techniques to
analyze video feeds in real-time, identifying and flagging any instances of weapons
within the camera's field of view. One common method involves object recognition
algorithms trained to recognize the distinct shapes and characteristics of firearms,
knives, and other weapons. These algorithms are capable of distinguishing between
ordinary objects and potential threats, such as handguns or rifles, based on their shape,
size, and appearance. Additionally, some weapon detection systems leverage deep
learning models that have been trained on vast datasets of weapon images to improve
accuracy and reliability. These models continuously learn and adapt to new threats,
ensuring they can effectively detect a wide range of weapons under various lighting and
environmental conditions. Furthermore, many weapon detection systems incorporate
motion detection and behavior analysis algorithms to enhance their capabilities. By
monitoring patterns of movement and activity, these systems can detect suspicious
behaviours indicative of potential threats, such as someone carrying a concealed
weapon or acting in a threatening manner.
3.1.1. DISADVANTAGES
• Current systems may trigger false alerts, mistaking harmless objects for
weapons.
• Detection algorithms might struggle to differentiate between actual weapons
and similar-looking items.
• Integrating advanced weapon detection technology can be expensive for
homeowners.
• Constant monitoring for weapons may raise privacy issues, causing discomfort
among residents.
19
3.2 PROPOSED SYSTEM
The proposed weapon detection system utilizing a You Only Look Once (YOLO)
within a Flask web application addresses several key challenges while offering robust
security measures and real-time threat detection capabilities. Difficulty integrating real-
time video feed with the YOLO model for accurate weapon detection is tackled through
meticulous model training on weapon and non-weapon datasets. By leveraging deep
learning techniques, the system learns to distinguish between various weapons and
harmless objects, ensuring precise identification. Deployment challenges with Flask
web app scalability and performance optimization are addressed through efficient code
design and utilization of cloud-based resources. The Flask framework allows for
seamless integration of the YOLO model with the web application, enabling users to
upload images or stream video for instant weapon detection. To combat the issue of a
lack of regular updates in the YOLO algorithms, the system employs a proactive
approach by continuously updating and refining the model through ongoing training on
new data. This ensures that the system remains adaptive and capable of minimizing
false positives, thereby enhancing user trust and confidence in its reliability. The
weapon detection system using Flask web application represents a significant
advancement in public safety technology. By harnessing cutting-edge deep learning and
web technologies, it provides real-time detection of firearms, knives, or other threats in
diverse settings such as airports, schools, or public events. This proactive approach to
violence prevention enhances security measures and safeguards individuals from
potential harm.
3.2.1. ADVANTAGES
20
CHAPTER 4
SYSTEM SPECIFICATION
21
CHAPTER 5
SYSTEM IMPLEMENTATION
• Dataset Acquisition
• Image Preprocessing
• Features Extraction
• Object Detection
• Weapon Detection
22
during the image capture, which can make it challenging to precisely identify features
in the image. Normalization includes adjusting the image's pixel values to a normal
limit, which can assist to lessen the effects of changes in illumination.
The bounding boxes as well as class labels for each cell are predicted by YOLO
after it divides the input image into a grid of cells. YOLO can swiftly identify items
since the technique requires a single convolutional neural network (CNN) to process
the entire image. Then, to find firearms in the image, the bounding boxes as well as
class labels predicted by YOLO are applied. The output from YOLO is then placed
through post-processing procedures to get rid of high false detections and boost the
detection's precision. In order to accurately identify firearms in surveillance camera
images, object identification modules using YOLO are used. This information is then
provided for further research and decision-making.
23
CHAPTER 6
SYSTEM DESIGN
24
6.2 DATA FLOW DIAGRAM
A data flow diagram shows the way information flows through a process or system. It
includes data inputs and outputs, data stores, and the various sub processes the data
moves through. DFDs are built using standardized symbols and notation to describe
various entities and their relationships. Data flow diagrams visually represent systems
and processes that would be hard to describe in a chunk of text. You can use these
diagrams to map out an existing system and make it better or to plan out a new system
for implementation. Visualizing each element makes it easy to identify inefficiencies
and produce the best possible system.
It is also known as a context diagram. It’s designed to be an abstraction view, showing
the system as a single process with its relationship to external entities. It represents the
entire system as a single bubble with input and output data indicated by
incoming/outgoing arrows.
In 1-level DFD, the context diagram is decomposed into multiple bubbles/processes. In
this level, we highlight the main functions of the system and breakdown the high-level
process of 0-level DFD into sub processes.
2-level DFD goes one step deeper into parts of 1-level DFD. It can be used to plan or
record the specific/necessary detail about the system’s functioning.
25
6.2.1 LEVEL 0
Stored on
Database
26
6.2.2 LEVEL 1
Object Detecting
Using YOLO
Algorithm
Performance
Evaluation
27
6.3 UML DIAGRAMS
28
6.3.2 CLASS DIAGRAM
29
6.3.3 SEQUENCE DIAGRAM
30
6.3.4 COLLABORATION DIAGRAM
31
6.3.5 ACTIVITY DIAGRAM
32
CHAPTER 7
SOFTWARE DESCRIPTION
7.1 PYTHON
Python interpreters are available for many operating systems. Python, the
reference implementation of Python, is open-source software and has a community-
based development model, as do nearly all of Python's other implementations. Python
are managed by the non-profit Python Software Foundation. Rather than having all of
its functionality built into its core, Python was designed to be highly extensible. This
compact modularity has made it particularly popular as a means of adding
programmable interfaces to existing applications.
Van Rossum's vision of a small core language with a large standard library and
easily extensible interpreter stemmed from his frustrations with ABC, which espoused
the opposite approach. While offering choice in coding methodology, the Python
philosophy rejects exuberant syntax (such as that of Perl) in favor of a simpler, less-
cluttered grammar. As Alex Martelli put it: "To describe something as 'clever' is not
considered a compliment in the Python culture. Python philosophy rejects the Perl
"there is more than one way to do it" approach to language design in favor of "there
should be one—and preferably only one—obvious way to do it".
33
functions to extension modules written in languages such as C, or use Py, a just-in-time
compiler. Python is also available, which translates a Python script into C and makes
direct C-level API calls into the Python interpreter. An important goal of Python's
developers is keeping it fun to use. This is reflected in the language's name a tribute to
the British comedy group Monty Python and in occasionally playful approaches to
tutorials and reference materials, such as examples that refer to spam and eggs (from a
famous Monty Python sketch) instead of the standard for and bar.
34
the other hand, often the quickest way to debug a program is to add a few print
statements to the source: the fast edit-test-debug cycle makes this simple approach very
effective.
Python’s initial development was spearheaded by Guido van Rossum in the late
1980s. Today, it is developed by the Python Software Foundation. Because Python is a
multiparadigm language, Python programmers can accomplish their tasks using
different styles of programming: object oriented, imperative, functional or reflective.
Python can be used in Web development, numeric programming, game development,
serial port access and more.
There are two attributes that make development time in Python faster than in other
programming languages:
2. Python code tends to be shorter than comparable codes. Although Python offers
fast development times, it lags slightly in terms of execution time. Compared to
fully compiling languages like C and C++, Python programs execute slower. Of
course, with the processing speeds of computers these days, the speed
differences are usually only observed in benchmarking tests, not in real-world
operations. In most cases, Python is already included in Linux distributions and
Mac OS X machines.
35
• Processing big data
• Fast prototyping
• Developing production-ready software
Professionally, Python is great for backend web development, data analysis, artificial
intelligence, and scientific computing. Developers also use Python to build productivity
tools, games, and desktop apps.
Python, a dynamically typed language, is especially flexible, eliminating hard rules for
building features and offering more problem-solving flexibility with a variety of
methods. It also allows uses to compile and run programs right up to a problematic area
because it uses run-time type checking rather than compile-time checking.
On the down side, Python isn’t easy to maintain. One command can have multiple
meanings depending on context because Python is a dynamically typed language. And,
maintaining a Python app as it grows in size and complexity can be increasingly
36
difficult, especially finding and fixing errors. Users will need experience to design code
or write unit tests that make maintenance easier. Speed is another weakness in Python.
Its flexibility, because it is dynamically typed, requires a significant amount of
referencing to land on a correct definition, slowing performance. This can be mitigated
by using alternative implementation of Python.
Python and AI
AI researchers are fans of Python. Google TensorFlow, as well as other libraries (scikit-
learn, Keras), establish a foundation for AI development because of the usability and
flexibility it offers Python users. These libraries, and their availability, are critical
because they enable developers to focus on growth and building.
Good to Know
The Python Package Index (PyPI) is a repository of software for the Python
programming language. PyPI helps users find and install software developed and shared
by the Python community.
Is Python easy to learn? Yes and no. When compared to other programming languages,
such as Java or C, Python is easy to learn. One aspect of the language that makes Python
easy to learn is that its syntax mimics human-readable language. The fact that its syntax
is designed to be clear, concise and easy to read eliminates many errors and softens the
learning curve.
Python also has a large standard library with prewritten code, which reduces the need
to write every line of code. Python’s supportive community and abundance of learning
resources also help make the language more friendly to newcomers.
But while many coders consider Python easy to learn, becoming proficient in any
programming language is challenging. Software development takes time, patience and
problem-solving skills.
37
Python Is a Scripting Language
Usage of Python
Python is a popular language choice for web and software development. Frameworks
like Django and Flask make it easier to create robust and scalable web applications. But
in many cases, other tools can work as a replacement for Python.
Where Python really stands out is in the big data ecosystem. Python is often used for
data science and analytics, scientific computing, machine learning (ML) and artificial
intelligence (AI). Because of this, Python’s ecosystem is rich with libraries such as
Pandas, NumPy and Matplotlib that enable data manipulation and analysis. Tools such
as TensorFlow, PyTorch, scikit-learn and Keras dominate the ML/AI space.
The Python language is dynamically typed, meaning the variable types don’t have to be
explicitly specified. However, variables do have types and their types matter. The
Python interpreter checks variable types at runtime: this makes the language also
strongly typed. The Python interpreter is a program that reads and executes Python
code. The interpreter interprets the developer-written source code into computer
hardware readable form. There are several implementations of the Python interpreter,
the standard-bearer and most popular being Python.
38
Introduction to Python Coding Fundamentals
Python programming fundamentals include several different data types and data
structures. Python’s primitive data types are basic data types that represent single values
with no methods or attributes.
Python’s data structures organize complex information and store varied types of data.
Lists are ordered collections of data and can include data of any type. The list’s “order”
refers to the list’s indices, not the arrangement of elements inside the list.
Tuples are immutable lists. Tuples can’t be changed after they’re created.
Sets are collections of unique elements. Sets automatically remove repeated terms if
they were previously included in the set. Try copying and pasting the following code
into an IDE to see how duplicate items are removed.
7.2 MY SQL
39
Joomla, word press, phpBB, MyBB, Drupal and other software built on the software
stack. MySQL is also used in many high-profile, large-scale World wide web products,
including Wikipedia, Google (though not for searches), image book Twitter, Flickr,
Nokia.com, and YouTube.
Inter images
Graphical
phpMyAdmin is a web-based software that allows you the ability to interact with your
MySQL databases. phpMyAdmin is an easy way to run MySQL commands as well as
database operations, like browsing and changing data tables, or importing, exporting,
or deleting data. It especially is useful when you want to perform maintenance on data
and backup or edit information in the case of WordPress itself not functioning properly.
40
However, keep in mind that phpMyAdmin won’t work properly if the database is
misconfigured or broken.
MySQL Features
Easy to use: MySQL is easy to use. We have to get only the basic knowledge of SQL.
We can build and interact with MySQL by using only a few simple SQL statements.
It is secure: MySQL consists of a solid data security layer that protects sensitive data
from intruders. Also, passwords are encrypted in MySQL.
Free to download: MySQL is free to use so that we can download it from MySQL
official website without any cost.
Speed: MySQL is considered one of the very fast database languages, backed by a large
number of the benchmark test.
41
High Flexibility: MySQL supports a large number of embedded applications, which
makes MySQL very flexible.
Allows roll-back: MySQL allows transactions to be rolled back, commit, and crash
recovery.
Memory efficiency: Its efficiency is high because it has a very low memory leakage
problem.
High Performance: MySQL is faster, more reliable, and cheaper because of its unique
storage engine architecture. It provides very high-performance results in comparison to
other databases without losing an essential functionality of the software. It has fast
loading utilities because of the different cache memory.
High Productivity: MySQL uses Triggers, Stored procedures, and views that allow
the developer to give higher productivity.
Platform Independent: It can download, install, and execute on most of the available
operating systems.
Partitioning: This feature improves the performance and provides fast management of
the large database.
Disadvantages/Drawback of MySQL
• MySQL version less than 5.0 doesn't support ROLE, COMMIT, and stored
procedure.
• MySQL does not support a very large database size as efficiently.
• MySQL doesn't handle transactions very efficiently, and it is prone to data
corruption.
42
• MySQL is accused that it doesn't have a good developing and debugging tool
compared to paid databases.
• MySQL doesn't support SQL check constraints.
Architecture of MySQL
MySQL is developed and supported by MySQL AB, which is a Swedish Company and
written in C and C++ programming language. It was developed by Michael Widenius
and David Hughes. It is often used to say that MySQL is named after the name of the
daughter of the co-founder Michael Widenius whose name is ‘My’.
Architecture of MySQL:
Client Layer:
This layer is the topmost layer in the above diagram. The Client gives request
instructions to the Serve with the help of Client Layer. The Client make request through
Command Prompt or through GUI screen by using valid MySQL commands and
expressions. If the Expressions and commands are valid then the output is obtained on
the screen. Some important services of client layer are:
Connection Handling:
When a client send request to the server and server will accept the request and the client
is connected. When Client is connected to the server at that time, a client gets its own
43
thread for its connection. With the help of this thread all the queries from client side are
executed.
Authentication:
Security:
After authentication when the client gets connected successfully to MySQL server, the
server will check that a particular client has the privileges to issue in certain queries
against MySQL server.
Server Layer:
The second layer of MySQL architecture is responsible for all logical functionalities of
relational database management system of MySQL. This Layer of MySQL System is
also known as “Brain of MySQL Architecture”. When the Client give request
instructions to the Server and the server gives the output as soon as the instruction is
matched. The various subcomponents of MySQL server are:
Thread Handling:
When a client send request to the server and server will accept the request and the client
is connected. When Client is connected to the server at that time, a client gets its own
thread for its connection. This thread is provided by thread handling of Server Layer.
Also, the queries of client side which is executed by the thread is also handled by Thread
Handling module.
Parser:
A Parser is a type of Software Component that built a data structure (parse tree) of given
input. Before parsing lexical analysis is done i.e. input is broken into number of tokens.
After the data is available in the smaller element’s parser perform Syntax Analysis,
Semantics Analysis after that parse tree is generated as output.
44
Optimizer –
As soon as the parsing is done, various types of optimization techniques are applied at
Optimizer Block. These techniques may include rewriting the query, order of scanning
of tables and choosing the right indexes to use etc.
Query Cache:
Query Cache stores the complete result set for inputted query statement. Even before
Parsing, MySQL Server consult query cache. When client write a query if the query
written by client is identical in the cache, then the server simply skips the parsing,
optimization and even execution, it just simply displays the output from the cache.
Cache and will buffer store the previous query or problem asked by user. When User
write a query then it firstly goes to Query Cache then query cache will check that the
same query or problem is available in the cache. If the same query is available then it
will provide output without interfering Parser, Optimizer.
The metadata cache is a reserved area of memory used for tracking information on
databases, indexes, or objects. The greater the number of open databases, indexes, or
objects, the larger the metadata cache size.
Key Cache:
A key cache is an index entry that uniquely identifies an object in a cache. By default,
edge servers cache content based on the entire resource path and a query string.
Storage Layer:
This Storage Engine Layer of MySQL Architecture make it’s unique and most
preferable for developers. Due to this Layer, MySQL layer is counted as the mostly
used RDBMS and is widely used. In MySQL server, for different situations and
requirement’s different types of storage engines are used which are InnoDB, MyISAM,
NDB, Memory etc.
45
CHAPTER 8
SYSTEM TESTING
Testing Objectives:
There are several rules that can serve as testing objectives, they are
2. A good test case is one that has high probability of finding an undiscovered error.
The development process involves various types of testing. Each test type
addresses a specific testing requirement. The most common types of testing involved
in the development process are:
• Unit Test
• Functional Test
• Integration Test
• White box Test
• Black box Test
• System Test
46
• Validation Test
• Acceptance Test
The first test in the development process is the unit test. The source code is
normally divided into modules, which in turn are divided into smaller units called units.
These units have specific behavior. The test done on these units of code is called unit
test. Unit test depends upon the language on which the project is developed. Unit tests
ensure that each unique path of the project performs accurately to the documented
specifications and contains clearly defined inputs and expected results.
Functional test can be defined as testing two or more modules together with
the intent of finding defects, demonstrating that defects are not present, verifying that
the module performs its intended functions as stated in the specification and
establishing confidence that a program does what it is supposed to do.
In integration testing modules are combined and tested as a group. Modules are
typically code modules, individual applications, source and destination applications on
a network, etc. Integration Testing follows unit testing and precedes system testing.
Testing after the product is code complete. Betas are often widely distributed or even
distributed to the public at large in hopes that they will buy the final product when it is
released.
47
In block box testing without knowledge of the internal workings of the item
being tested. Tests are usually functional. This testing can be done by the user who has
no knowledge of how the shortest path is found.
System testing is defined as testing of a complete and fully integrated software product.
This testing falls in black-box testing wherein knowledge of the inner design of the
code is not a pre-requisite and is done by the testing team. It is the final test to verify
that the product to be delivered meets the specifications mentioned in the requirement
document. It should investigate both functional and non-functional requirements.
The process of evaluating software during the development process or at the end of
the development process to determine whether it satisfies specified business
requirements. Validation Testing ensures that the product actually meets the client's
needs. It can also be defined as to demonstrate that the product fulfils its intended use
when deployed on appropriate environment.
48
CHAPTER 9
9.1 CONCLUSION
In conclusion, the weapon detection system utilizing a Flask web application and
convolutional neural network represents a significant advancement in enhancing public
safety by proactively identifying potential threats in real-time images or video streams.
However, the integration of real-time video feed with the YOLO model presents
challenges that need to be addressed for accurate detection. Additionally, ensuring the
scalability and performance optimization of the Flask web app is crucial for its effective
deployment in various settings. Regular updates in the deep learning algorithms are
essential to minimize false positives and maintain the system's reliability, thereby
bolstering trust in its capabilities and ensuring the effectiveness of security measures.
By leveraging cutting-edge technology, this system empowers users to swiftly respond
to potential dangers, thereby preventing violence and safeguarding individuals in
diverse environments such as airports, schools, or public events. Overall, the weapon
detection system serves as a proactive tool in enhancing security measures, utilizing the
synergy between deep learning and web technology to mitigate threats and protect the
public effectively. Continued research, development, and refinement of this system are
vital to further improving its accuracy, reliability, and scalability in ensuring public
safety.
49
9.2 FUTURE ENHANCEMENT
To address the challenges and enhance the weapon detection system, future
enhancements could focus on several aspects. Firstly, continuous updates to the deep
learning algorithms should be prioritized to minimize false positives and ensure the
system's reliability. This can involve integrating advanced techniques like transfer
learning or ensemble methods to improve model performance over time. Secondly,
efforts should be made to enhance the scalability and performance optimization of the
Flask web application, possibly by leveraging cloud services for flexible resource
allocation and load balancing. Additionally, real-time video feed integration with the
YOLO model can be refined by exploring faster inference techniques or optimizing
hardware acceleration. Lastly, incorporating user feedback mechanisms and
collaborative data sharing initiatives can further refine the system's accuracy and
adaptability, ensuring its effectiveness in diverse environments. These enhancements
will bolster the system's ability to proactively prevent violence and safeguard
individuals across various settings, thereby advancing public safety measures
significantly.
50
APPENDIX 1
(SAMPLE CODE)
# Part 1 - Building the CNN
train_datagen = ImageDataGenerator(rescale=1/255)
import tensorflow as tf
model = tf.keras.models.Sequential([
# Note the input shape is the desired size of the image 200x 200 with 3 bytes color
# The first convolution
tf.keras.layers.Conv2D(16, (3,3), activation='relu', input_shape=(100, 100, 3)),
tf.keras.layers.MaxPooling2D(2, 2),
# The second convolution
tf.keras.layers.Conv2D(32, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
51
# The third convolution
tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
# The fourth convolution
tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
# The fifth convolution
tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
# Flatten the results to feed into a dense layer
tf.keras.layers.Flatten(),
# 128 neuron in the fully-connected layer
tf.keras.layers.Dense(128, activation='relu'),
# 5 output neurons for 3 classes with the softmax activation
tf.keras.layers.Dense(2, activation='softmax')
])
model.summary()
total_sample=train_generator.n
n_epochs = 15
from sklearn.metrics import classification_report
history = model.fit_generator(
train_generator,
steps_per_epoch=int(total_sample/batch_size),
epochs=n_epochs,
verbose=1)
52
model.save('model.h5')
acc = history.history['accuracy']
loss = history.history['loss']
import tensorflow as tf
import numpy as np
def endprogram():
print("\nProgram terminated!")
53
sys.exit()
def file_sucess():
global file_success_screen
file_success_screen = Toplevel(training_screen)
file_success_screen.title("File Upload Success")
file_success_screen.geometry("150x100")
Label(file_success_screen, text="File Upload Success").pack()
Button(file_success_screen, text='''ok''', font=(
'Verdana', 15), height="2", width="30", ).pack()
global ttype
def training():
global training_screen
global clicked
training_screen = Toplevel(main_screen)
training_screen.title("Training")
# login_screen.geometry("400x300")
training_screen.geometry("600x450+650+150")
training_screen.minsize(120, 1)
training_screen.maxsize(1604, 881)
training_screen.resizable(1, 1)
# login_screen.title("New Toplevel")
options = [
"knife",
"pistol"
drop.pack()
ttype = clicked.get()
def imgtraining():
name1 = clicked.get()
print(name1)
import_file_path = filedialog.askopenfilename()
import os
55
s = import_file_path
os.path.split(s)
os.path.split(s)[1]
splname = os.path.split(s)[1]
image = cv2.imread(import_file_path)
# filename = 'Test.jpg'
filename = 'Data/' + name1 + '/' + splname
cv2.imwrite(filename, image)
print("After saving image:")
im = Image.open(import_file_path)
im_invert = ImageOps.invert(im)
im_invert.save('lena_invert.jpg', quality=95)
im = Image.open(import_file_path).convert('RGB')
im_invert = ImageOps.invert(im)
im_invert.save('tt.png')
image2 = cv2.imread('tt.png')
cv2.imshow("Invert", image2)
""""-----------------------------------------------"""
56
img = image
def fulltraining():
import Model as mm
def testing():
global testing_screen
testing_screen = Toplevel(main_screen)
testing_screen.title("Testing")
# login_screen.geometry("400x300")
testing_screen.geometry("600x450+650+150")
testing_screen.minsize(120, 1)
testing_screen.maxsize(1604, 881)
testing_screen.resizable(1, 1)
# login_screen.title("New Toplevel")
57
def imgtest():
import_file_path = filedialog.askopenfilename()
image = cv2.imread(import_file_path)
print(import_file_path)
filename = 'Data/Out/Test.jpg'
cv2.imwrite(filename, image)
print("After saving image:")
# result()
# import_file_path = filedialog.askopenfilename()
print(import_file_path)
fnm = os.path.basename(import_file_path)
print(os.path.basename(import_file_path))
# file_sucess()
img1 = cv2.imread(import_file_path)
print(img.shape)
img = cv2.resize(img, ((int)(img.shape[1] / 5), (int)(img.shape[0] / 5)))
original = img.copy()
neworiginal = img.copy()
cv2.imshow('original', img1)
gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
def result():
import warnings
warnings.filterwarnings('ignore')
import tensorflow as tf
classifierLoad = tf.keras.models.load_model('model.h5')
import numpy as np
from keras.preprocessing import image
test_image = image.load_img('./Data/Out/Test.jpg', target_size=(100, 100))
# test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis=0)
result = classifierLoad.predict(test_image)
out = ''
if result[0][0] == 1:
print("knife")
out = "knife"
sendmail("[email protected]", "Prediction Weapon" + out)
messagebox.showinfo("Result", "Classification Result : " + str(out))
elif result[0][1] == 1:
print("pistol")
out = "pistol"
59
sendmail("[email protected]", "Prediction Weapon" + out)
messagebox.showinfo("Result", "Classification Result : " + str(out))
"http://sms.creativepoint.in/api/push.json?apikey=6555c521622c1&route=transsms&s
ender=FSSMSS&mobileno=" + targetno + "&text=Dear customer your msg is " +
message + " Sent By FSMSG FSSMSS")
def Camera():
import newwep
def fire():
import Video
fromaddr = "[email protected]"
toaddr = Mailid
# instance of MIMEMultipart
60
msg = MIMEMultipart()
# Authentication
s.login(fromaddr, "qmgn xecl bkqv musr")
Button(text="UploadImage", font=(
'Verdana', 15), height="2", width="30", command=training,
highlightcolor="black").pack(side=TOP)
Label(text="").pack()
Button(text="Training", font=(
'Verdana', 15), height="2", width="30", command=fulltraining,
highlightcolor="black").pack(side=TOP)
Label(text="").pack()
Button(text="Testing", font=(
'Verdana', 15), height="2", width="30", command=testing).pack(side=TOP)
Label(text="").pack()
Button(text="WeaponCamera", font=(
'Verdana', 15), height="2", width="30", command=Camera).pack(side=TOP)
62
Label(text="").pack()
Button(text="FireCamera", font=(
'Verdana', 15), height="2", width="30", command=fire).pack(side=TOP)
main_screen.mainloop()
main_account_screen()
import cv2
import numpy as np
def sendmail():
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
fromaddr = "[email protected]"
toaddr = "[email protected]"
# instance of MIMEMultipart
msg = MIMEMultipart()
# Authentication
s.login(fromaddr, "qmgn xecl bkqv musr")
64
# Converts the Multipart msg into a string
text = msg.as_string()
def sendmsg(targetno,message):
import requests
requests.post(
"http://sms.creativepoint.in/api/push.json?apikey=6555c521622c1&route=transsms&s
ender=FSSMSS&mobileno=" + targetno + "&text=Dear customer your msg is " +
message + " Sent By FSMSG FSSMSS")
cap = cv2.VideoCapture(0)
flagg = 0
while True:
_, img = cap.read()
height, width, channels = img.shape
# width = 512
# height = 512
65
# Detecting objects
blob = cv2.dnn.blobFromImage(img, 0.00392, (416, 416), (0, 0, 0), True,
crop=False)
net.setInput(blob)
layer_names = net.getLayerNames()
# 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)
66
indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.7, 0.4)
print(indexes)
#if indexes == 0: print("weapon detected in frame")
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.rectangle(img, (x, y), (x + w, y + h), color, 2)
cv2.putText(img, label, (x, y + 30), font, 3, color, 3)
flagg += 1
print(flagg)
if flagg == 2:
flagg = 0
import winsound
filename = 'alert.wav'
winsound.PlaySound(filename, winsound.SND_FILENAME)
cv2.imwrite("alert.jpg", img)
sendmail()
sendmsg("9994761304", " Weapon Detected")
68
69
70
71
72
73
REFERENCES
1. Heinold, Brian. "A practical introduction to Python programming." (2021).
2. Kneusel, Ronald T. Practical deep learning: A Python-based introduction. No
Starch Press, 2021.
3. Dhruv, Akshit J., Reema Patel, and Nishant Doshi. "Python: the most advanced
programming language for computer science applications." Science and
Technology Publications, Lda (2021): 292-299.
4. Sundnes, Joakim. Introduction to scientific programming with Python. Springer
Nature, 2020.
5. Hill, Christian. Learning scientific programming with Python. Cambridge
University Press, 2020.
74