Mca Format Weapon Detection

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 76

CHAPTER 1

INTRODUCTION

1.1 DOMAIN 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

1
fashion, with each layer progressively refining the features extracted from the input
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.

In addition to its technical capabilities, YOLOv5 embodies the spirit of open-source


collaboration and innovation. The model is developed and maintained by a vibrant
community of researchers, engineers, and enthusiasts, who contribute to its ongoing
evolution and improvement. This collaborative ecosystem fosters knowledge sharing,
experimentation, and creativity, driving the advancement of object detection
technology as a whole.

1.2 WHY YOLO IS POPULAR

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.

1.3 REALTIME IMPLEMENTATION IN YOLO

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

3
bounding boxes and 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.

1.4 DEEP LEARNING

Deep learning is an artificial intelligence function that imitates the workings of


the human brain in processing data and creating patterns for use in decision making.
Deep learning is a subset of machine learning in artificial intelligence (AI) that has
networks capable of learning unsupervised from data that is unstructured or unlabeled.
Also known as deep neural learning or deep neural network.

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.

Deep learning, a subset of machine learning, utilizes a hierarchical level of artificial


neural networks to carry out the process of machine learning. The artificial neural
networks are built like the human brain, with neuron nodes connected together like a
web. While traditional programs build analysis with data in a linear way, the

5
hierarchical function of deep learning systems enables machines to process data with
a nonlinear approach.

 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.

 Build, train, and deploy different types of Deep Architectures, including


Convolutional Networks, Recurrent Networks, and Autoencoders.

 Application of Deep Learning to real-world scenarios such as object


recognition and Computer Vision, image and video processing, text analytics,
Natural Language Processing, recommender systems, and other types of
classifiers.

 Master Deep Learning at scale with accelerated hardware and GPUs.

1.5 TYPES OF DEEP LEARNING METHODS

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.

Convolutional Neural Networks (CNN): CNNs are designed for processing


structured grid data such as images. They utilize convolutional layers to automatically
and adaptively learn spatial hierarchies of features from input data. CNNs are widely
used in image recognition and computer vision tasks.

Recurrent Neural Networks (RNN): Unlike feedforward networks, RNNs have


connections that form directed cycles, allowing them to exhibit dynamic temporal
behavior. This makes them suitable for sequence data like time series, text, and
speech. Variants like Long Short-Term Memory (LSTM) and Gated Recurrent Unit
(GRU) are popular for handling long-term dependencies.

6
Generative Adversarial Networks (GAN): GANs consist of two neural networks, a
generator and a discriminator, trained simultaneously. The generator learns to produce
data that is similar to the training data, while the discriminator learns to distinguish
between real and fake data. GANs are used for generating realistic synthetic data,
image-to-image translation, and more.

Autoencoders: Autoencoders are a type of neural network used for unsupervised


learning. They aim to learn efficient representations of data by compressing the input
into a latent-space representation and then reconstructing the input from this
representation. Variants like Variational Autoencoders (VAE) also learn probabilistic
distributions over the latent space.

Recursive Neural Networks (RecNN): These networks are designed to handle


hierarchical structures by recursively applying the same set of weights to different
parts of the input. They are commonly used in tasks involving tree-structured data
such as parsing and semantic compositionality.

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.

1.6 INTRODUCTION OF CONVOLUTIONAL NEURAL NETWORKS (CNN):

Convolutional Neural Networks (CNNs) represent a groundbreaking advancement in


the realm of artificial intelligence, specifically within the domain of computer vision.
Their inception stemmed from the need to automate the process of feature extraction
and pattern recognition from visual data, tasks that were traditionally challenging for
conventional algorithms. At the heart of CNNs lies the concept of convolution, a
mathematical operation that involves combining input data with a predetermined filter
or kernel to produce a feature map. This operation is inspired by the human visual
system, where different parts of the retina are sensitive to different areas of the visual

7
field. By applying convolution operations across multiple layers, CNNs can
effectively learn hierarchical representations of features, gradually transforming raw
pixel values into higher-level abstractions.

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.

CNNs have demonstrated remarkable performance across numerous computer vision


tasks, surpassing human-level accuracy in tasks such as image classification, object
detection, and semantic segmentation. Their success can be attributed to several
factors, including their ability to capture hierarchical representations of features, their
parameter-sharing scheme, which enables efficient learning from limited data, and

8
their translational invariance properties, which make them robust to shifts and
distortions in input images.

CHAPTER 2

LITERATURE SURVEY

2.1. TITLE: WEAPON DETECTION IN REAL-TIME CCTV VIDEOS USING


DEEP LEARNING

AUTHOR: MUHAMMAD TAHIR BHATTI, MUHAMMAD GUFRAN KHAN,


MASOOD ASLAM, MUHAMMAD JUNAID FIAZ1

The introduction of an innovative automatic weapon detection system in this study


represents a significant leap forward in real-time monitoring and control capabilities.
This technology, primarily aimed at enhancing security and upholding law and order,
shows great promise in creating safer environments, particularly in regions plagued by
ongoing violent activities. By tackling the urgent need for effective detection
mechanisms, this system has the potential to bolster community safety and national
stability. A key aspect of this work is its focus on minimizing false positives and
negatives, ensuring the reliability and accuracy of weapon detection. Through the
meticulous construction of a specialized training database tailored for real-time
scenarios and rigorous evaluation using state-of-the-art deep learning models, this
approach has delivered impressive results. By employing both sliding
window/classification and region proposal/object detection methodologies, the system
demonstrates superior performance in identifying weapons within live CCTV streams.
This advancement holds immense significance for security efforts, as it equips
authorities with a powerful tool to promptly detect and respond to potential threats.
Moreover, by enhancing the efficiency of monitoring and control systems, it aids in
maintaining peace and stability in communities affected by violence.

DISADVANTAGES:

 Requires ongoing improvement for reducing errors.

9
 Limited to detecting weapons, may not address other threats.
 Demands significant computational resources for implementation.
 Raises ethical concerns regarding privacy and surveillance.

2.2. TITLE: HAWK-EYE: AN AI-POWERED THREAT DETECTOR FOR


INTELLIGENT SURVEILLANCE CAMERAS

AUTHOR: AHMED ABDELMOAMEN AHMED, MATHIAS ECHI

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:

 Possible limitations in scalability and adaptability to larger datasets.


 Requires further experimentation to ensure robustness.
 Dependency on specific hardware configurations.
 Potential challenges in integrating with existing surveillance systems.

10
2.3. TITLE: GESTURE DETECTION AND RECOGNITION BASED ON
OBJECT DETECTION IN COMPLEX BACKGROUND

AUTHOR: RENXIANG CHEN AND XIA TIAN

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:

 May require substantial computational resources due to the advanced


algorithm.
 Complexity in implementation and understanding for non-experts.
 Dependence on extensive experimentation for validation, which could be time-
consuming.

11
2.4. TITLE: A NOVEL APPROACH FOR OBJECT IDENTIFICATION WITH
DEEP REINFORCEMENT MACHINE LEARNING

AUTHOR: SAURABH TIWARI, DR. S VEENADHARI, DR. SANJEEV K


GUPTA

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:

 Implementation may require a deeper understand of reinforcement learning


concepts.
 The reinforcement learning agent may require substantial computational
resources.
 Effectiveness may vary depending on the complexity.

12
 Performance may be sensitive to hyperparameters tuning.

2.5. TITLE: DEEP LEARNING ALGORITHMS-BASED OBJECT


DETECTION AND LOCALIZATION REVISITED

AUTHOR: SAFA RIYADH WAHEED, NORHAIDA MOHD SUAIB, MOHD


SHAFRY MOHD RAHIM, MYASAR MUNDHER ADNAN, A. A. SALIM

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:

 Despite advancements, computer vision remains in its early stages, suggesting


limitations in fully exploiting its potential.
 The complexity of deep learning algorithms may lead to high computational
requirements and resource intensiveness.

13
2.6. TITLE: A SURVEY ON POLICE PREVENTIVE ACTION TRACKING
SYSTEM USING AI

AUTHOR: DR.A. B. GAVALI, PHULE PRAVINKUMAR, NIMGIRE


PRATHMESH, PARAKHE GANESH, MANE SHUBHAM

Artificial Intelligence (AI) holds immense promise in bolstering law enforcement


efforts by leveraging data analysis, pattern recognition, and insightful conclusions to
thwart and identify criminal activities. A pioneering initiative within this realm is the
development of a Police Preventive Action Tracking System powered by AI. This
innovative system integrates AI methodologies into police operations, facilitating
preemptive measures against criminal behavior. The advantages of such a system are
multifaceted, including heightened situational awareness, enhanced operational
efficiency and effectiveness, reduced costs and risks, and bolstered trust and
satisfaction among communities. Nonetheless, the implementation of such a system is
not without its challenges and constraints. Issues such as the quality and availability
of data, technological infrastructure requirements, ethical and legal considerations,
and social and cultural barriers pose significant hurdles. Despite these obstacles, the
potential of AI in law enforcement remains a beacon of hope for safer, more secure
communities.

DISADVANTAGES:

 Data quality and availability challenges may hinder effectiveness.


 Technology and infrastructure requirements may be complex and costly.
 Ethical and legal issues surrounding AI use in policing need careful
consideration.
 Social and cultural barriers may affect acceptance and implementation.

14
2.7. TITLE: AUTOMATIC WEAPON DETECTION FOR SURVEILLANCE
APPLICATIONS

AUTHOR: SHREYAS GAWADE, DR. R. VIDHYA, DR. R. RADHIKA

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
 Potential for misidentifying harmless objects as weapons.
 Continuous surveillance raises privacy issues and may infringe on individual
rights.
 Focuses primarily on weapon detection, ignoring other aspects of crime
prevention.

2.8. TITLE: WEAPON DETECTION USING ARTIFICIAL INTELLIGENCE


AND DEEP LEARNING FOR SECURITY APPLICATIONS

AUTHOR: MS. S. RAJALAKSHMI, MS. S. DHIVYASHREE, MS. K.


BUSHYA, MS.U. JANANI

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.

16
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.

2.9. TITLE: WEAPON DETECTION USING YOLO V3 FOR SMART


SURVEILLANCE SYSTEM

AUTHOR: SANAM NAREJO, BISHWAJEET PANDEY, DORIS ESENARRO


VARGAS, CIRO RODRIGUEZ, M. RIZWAN ANJUM

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.

17
DISADVANTAGES:

 Increased surveillance may raise privacy issues for individuals


 Over-reliance on automated systems may lead to complacency or errors.
 Initial investment in advanced technology and infrastructure may be
prohibitive for some organizations.

2.10. TITLE: REAL-TIME CONCEALED OBJECT DETECTION FROM


PASSIVE MILLIMETER WAVE IMAGES BASED ON THE YOLOV3
ALGORITHM

AUTHOR: LEI PANG, HUI LIU, YANG CHEN, JUNGANG MIAO

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

18
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:

 Limited PMMW image data diversity hampers training.


 Equipment dependency limits PMMW technology scalability.
 Expanding datasets for diverse contraband types is challenging.

CHAPTER 3

SYSTEM ANALYSIS

3.1 EXISTING SYSTEM

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

19
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.

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

20
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

 Utilizes YOLO technology for precise weapon detection in real-time video


feeds, enhancing security effectiveness.
 Integrates Flask web application for seamless scalability and performance
optimization, ensuring reliable operation under heavy loads.
 Regular updates to deep learning algorithms mitigate false positives,
maintaining high trust levels and bolstering security measures.
 Cutting-edge technology enables instant identification of firearms.

CHAPTER 4

SYSTEM SPECIFICATION

4.1 SOFTWARE REQUIREMENTS

 Processor : Intel core processor 2.6.0 GHZ


 RAM : 4 GB
 Hard disk : 320 GB
 Compact Disk : 650 Mb
 Keyboard : Standard keyboard
 Monitor : 15-inch color monitor

4.2 HARDWARE REQUIREMENTS

 Operating system : WINDOWS OS


 Front End : PYTHON
 IDE : PYCHARM
 Application : Windows Application

21
CHAPTER 5

SYSTEM IMPLEMENTATION

5.1 MODULE LIST

 Dataset Acquisition
 Image Preprocessing
 Features Extraction
 Object Detection
 Weapon Detection

5.2 MODULE DESCRIPTIONS

5.2.1. DATASET ACQUISITION

A weapon detection system in security camera images depends on the image


acquisition module. This module is in charge of pulling down pictures or videos from
the security cameras and getting them ready for processing and analysis. Using the
surveillance cameras, high-quality photos or videos are captured during the image

22
acquisition process, and the data is then pre-processed to remove noise and
distortions. Utilizing image processing methods like scaling, cropping, and
normalizing is one way to achieve this. The pre-processed pictures or movies are then
marked with labels to say if they have weapons in them or not.

5.2.2. IMAGE PREPROCESSING

An important phase in the image analysis process is image preprocessing,


which entails cleaning and improving the collected images to eliminate any noise or
distortions. The goal of preprocessing is to raise the quality of the photos so that
image processing algorithms can more quickly and properly evaluate them. Noise
reduction, lighting correction, deblurring, and normalizing are procedures used in
image preprocessing. In order to avoid distortions, noise reduction entails eliminating
any arbitrary variations or fluctuations in the image's pixel values. To account for
variations in lighting, illumination correction entails altering the contrast and
brightness of the images. Deblurring is the process of eliminating any blurring that
may have developed 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.

5.2.3. FEATURES EXTRACTION

The CNN receives an image as input and afterwards processes it through a


number of layers, each of which draws out progressively intricate information from
the image. A collection of outputs from the CNN's final layer correspond to various
categories or classes. A sizable collection of labelled images—each image belonging
to one of many classes—is used to train the CNN. The CNN learns the connections
between the input image as well as the intended output class throughout the training
process. Using the most likely class for each picture based on its attributes, the CNN
may be used to categories new images once it has been trained.

5.2.4. OBJECT DETECTION

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

23
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.

5.2.5. ALERT SYSTEM

When a weapon is shown in the images captured by surveillance cameras, an


alarm system could be used to immediately notify security personnel. Among other
things, the alarm system can be set up to send emails to a security guard's mobile
device. The alert system's objective is to give security professionals timely
information they may use to react swiftly to threats.

CHAPTER 6

SYSTEM DESIGN

6.1 SYSTEM ARCHITECTURE

24
Fig: 6.1.SYSTEM ARCHITECTURE

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

25
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.

6.2.1 LEVEL 0

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

26
represents the entire system as a single bubble with input and output data indicated by
incoming/outgoing arrows.

Training Phase Trained Data

Stored on
Database

Fig: 6.2.1 DATA FLOW DIAGRAM - LEVEL 0

27
6.2.2 LEVEL 1

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.

Testing Phase Testing Data

Object Detecting
Using YOLO
Algorithm

Matched with trained


Pre-processing dataset using CNN

Performance
Evaluation

Fig: 6.2.2 DATA FLOW DIAGRAM - LEVEL 1

28
6.3 UML DIAGRAMS

6.3.1 USE CASE DIAGRAM

A use case diagram is a dynamic or behavior diagram in UML. Use case


diagrams model the functionality of a system using actors and use cases. Use cases
are a set of actions, services, and functions that the system needs to perform.

Fig:6.3.1 UML diagram

29
6.3.2 CLASS DIAGRAM

In software engineering, a class diagram in the Unified Modeling Language


(UML) is a type of static structure diagram that describes the structure of a system by
showing the system's classes, their attributes, operations (or methods), and the
relationships among objects.

Fig: 6.3.2 CLASS DIAGRAM

30
6.3.3 SEQUENCE DIAGRAM

A sequence diagram simply depicts interaction between objects in


a sequential order i.e. the order in which these interactions take place. We can also use
the terms event diagrams or event scenarios to refer to a sequence diagram.

Fig :6.3.3 SEQUENCE DIAGRAM

31
6.3.4 COLLABORATION DIAGRAM

A collaboration diagram, also known as a communication diagram, is an


illustration of the relationships and interactions among software objects in the Unified
Modeling Language (UML). These diagrams can be used to portray the dynamic
behavior of a particular use case and define the role of each object.

Fig: 6.3.4 COLLABORATION DIAGRAM

32
6.3.5 ACTIVITY DIAGRAM

An activity diagram is a behavioral diagram i.e. it depicts the behavior of a


system. An activity diagram portrays the control flow from a start point to a finish
point showing the various decision paths that exist while the activity is being
executed.

Fig : 6.3.5 ACTIVITY DIAGRAM

33
CHAPTER 7

SOFTWARE DESCRIPTION
7.1 PYTHON

Python is an interpreted high-level programming language for general-purpose


programming. Created by Guido van Rossum and first released in 1991, Python has a
design philosophy that emphasizes code readability, notably using significant
whitespace. It provides constructs that enable clear programming on both small and
large scales. In July 2018, Van Rossum stepped down as the leader in the language
community. Python features a dynamic type system and automatic memory
management. It supports multiple programming paradigms, including object-oriented,
imperative, functional and procedural, and has a large and comprehensive standard
library.

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".

Python's developers strive to avoid premature optimization, and reject patches


to non-critical parts of Python that would offer marginal increases in speed at the cost

34
of clarity. When speed is important, a Python programmer can move time-critical
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.

A common neologism in the Python community is pythonic, which can have a


wide range of meanings related to program style. To say that code is pythonic is to
say that it uses Python idioms well, that it is natural or shows fluency in the language,
that it conforms with Python's minimalist philosophy and emphasis on readability. In
contrast, code that is difficult to understand or reads like a rough transcription from
another programming language is called unpythonic. Users and admirers of Python,
especially those considered knowledgeable or experienced, are often referred to as
Pythonists, Pythonistas, and Pythoneers.

Python is an interpreted, object-oriented, high-level programming language


with dynamic semantics. Its high-level built in data structures, combined with
dynamic typing and dynamic binding, make it very attractive for Rapid Application
Development, as well as for use as a scripting or glue language to connect existing
components together. Python's simple, easy to learn syntax emphasizes readability
and therefore reduces the cost of program maintenance. Python supports modules and
packages, which encourages program modularity and code reuse. The Python
interpreter and the extensive standard library are available in source or binary form
without charge for all major platforms, and can be freely distributed. Often,
programmers fall in love with Python because of the increased productivity it
provides. Since there is no compilation step, the edit-test-debug cycle is incredibly
fast. Debugging Python programs is easy: a bug or bad input will never cause a
segmentation fault. Instead, when the interpreter discovers an error, it raises an
exception. When the program doesn't catch the exception, the interpreter prints a stack
trace. A source level debugger allows inspection of local and global variables,
evaluation of arbitrary expressions, setting breakpoints, stepping through the code a

35
line at a time, and so on. The debugger is written in Python itself, testifying to
Python's introspective power. On 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:

1. Python is an interpreted language, which precludes the need to compile code


before executing a program because Python does the compilation in the
background. Because Python is a high-level programming language, it
abstracts many sophisticated details from the programming code. Python
focuses so much on this abstraction that its code can be understood by most
novice programmers.

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.

Python Use Cases

• Creating web applications on a server


• Building workflows that can be used in conjunction with software
• Connecting to database systems
• Reading and modifying files

36
• Performing complex mathematics
• 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.

Features and Benefits of Python

 Compatible with a variety of platforms including Windows, Mac, Linux,


Raspberry Pi, and others
 Uses a simple syntax comparable to the English language that lets developers
use fewer lines than other programming languages
 Operates on an interpreter system that allows code to be executed
immediately, fast-tracking prototyping
 Can be handled in a procedural, object-orientated, or functional way
Python Syntax
 Somewhat similar to the English language, with a mathematical influence,
Python is built for readability
 Unlike other languages that use semicolons and/or parentheses to complete a
command, Python uses new lines for the same function
 Defines scope (i.e., loops, functions, classes) by relying indentation, using
whitespace, rather than braces (aka curly brackets)

Python Flexibility

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.

The Less Great Parts of Python

37
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
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.

How Easy Is It to Learn Python?

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.

38
Python Is a Scripting Language

A scripting language is a programming language that’s designed for automating tasks.


Scripting languages, such as Python, are interpreted and executed directly by an
interpreter or runtime environment. Scripting languages are not compiled into
machine code before being run, whereas traditional programming languages like C++
or Java are compiled at runtime. Because Python is a scripting language, it excels at
tasks such as file operations, system administration, web scraping, network
programming and network automation, as well as big data operations such as data
processing, scientific computing and data analysis.

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.

Introduction to Python Programming

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.

39
Python is a single-threaded language. The Global Interpreter Lock (GIL) is essentially
a lock that keeps one thread of Python in a state of execution at a time. Since the GIL
is specific to Python, there are interpretations of Python that don’t include the GIL.

Introduction to Python Coding Fundamentals

Variables and Data Types

Python stores data in variables.

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.

Dictionaries store data in key-value pairs.

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

MySQL is the world's most used open-source relational database management


system (RDBMS) as of 2008 that run as a server providing multi-user access to a
number of databases. The MySQL development project has made its source code
available under the terms of the GNU General public License, as well as under a
variety of proprietary agreements. MySQL was owned and sponsored by a single for-
profit firm, the Swedish company MySQL AB, now owned by Oracle corporation.

MySQL is a popular choice of database for use in web applications, and is a


central component of the widely used LAMP open-source web application software
stack—LAMP is an acronym for "Linux, Apache, MySQL, perl/PHP/python. “Free

40
software-open-source projects that require a full-featured database management
system often use MySQL. For commercial use, several paid editions are available,
and offer additional functionality. Applications which use MySQL databases include:
TYPO3, 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

MySQL is primarily an RDBMS and ships with no GUI tools to administer


MySQL databases or manage data contained within the databases. Users may use the
included command line tools, or use MySQL "front-ends", desktop software and web
applications that create and manage MySQL databases, build database structures,
back up data, inspect status, and work with data records. The official set of MySQL
front-end tools, MySQL Workbench is actively developed by Oracle, and is freely
available for use.

Graphical

The official MySQL Workbench is a free integrated environment developed


by MySQL AB, that enables users to graphically administer MySQL databases and
visually design database structures. MySQL Workbench replaces the previous
package of software, GUI tools. Similar to other third-party packages, but still
considered the authoritative MySQL frontend, MySQL Workbench lets users manage
database design & modeling, SQL development (replacing MySQL Query Browser)
and Database administration (replacing MySQL Administrator).MySQL Workbench
is available in two editions, the regular free and open source Community Edition
which may be downloaded from the MySQL website, and the proprietary Standard
Edition which extends and improves the feature set of the Community Edition.

PhpMyAdmin and MySQL

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,

41
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. However, keep in mind that phpMyAdmin won’t work properly if the
database is misconfigured or broken.

MySQL Features

MySQL is a relational database management system (RDBMS) based on the SQL


(Structured Query Language) queries. It is one of the most popular languages for
accessing and managing the records in the table. MySQL is open-source and free
software under the GNU license. Oracle Company supports it.

The following are the most important features of MySQL:

Relational Database Management System (RDBMS)

MySQL is a relational database management system. This database language is based


on the SQL queries to access and manage the records of the table.

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.

Client/ Server Architecture: MySQL follows the working of a client/server


architecture. There is a database server (MySQL) and arbitrarily many clients
(application programs), which communicate with the server; that is, they can query
data, save changes, etc.

Free to download: MySQL is free to use so that we can download it from MySQL
official website without any cost.

It is scalable: MySQL supports multi-threading that makes it easily scalable. It can


handle almost any amount of data, up to as much as 50 million rows or more. The
default file size limit is about 4 GB. However, we can increase this number to a
theoretical limit of 8 TB of data.

42
Speed: MySQL is considered one of the very fast database languages, backed by a
large number of the benchmark test.

High Flexibility: MySQL supports a large number of embedded applications, which


makes MySQL very flexible.

Compatible on many operating systems: MySQL is compatible to run on many


operating systems, like Novell NetWare, Windows* Linux*, many varieties of
UNIX* (such as Sun* Solaris*, AIX, and DEC* UNIX), OS/2, FreeBSD*, and others.
MySQL also provides a facility that the clients can run on the same computer as the
server or on another computer (communication via a local network or the Internet).

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

Following are the few disadvantages of MySQL:

 MySQL version less than 5.0 doesn't support ROLE, COMMIT, and stored
procedure.

43
 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.
 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 a Relational Database Management system which is free Open-Source


Software Under GNU License. It is also supported by Oracle Company. It is fast,
scalable, easy to use database management System. MySQL support many operating
system like Windows, Linux, MacOS etc.

MySQL is a Structured Query Language which is used to manipulate, manage and


retrieve data with the help of various Queries.

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:

Architecture of MySQL describes the relation among the different components of


MySQL System. MySQL follow Client-Server Architecture. It is designed so that
end user that is Clients can access the resources from Computer that is server using
various networking services. The Architecture of MY SQL contain following major
layer’s:

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:

44
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 thread for its connection. With the help of this thread all the queries from
client side are executed.

Authentication:

Authentication is performed on the server side when client is connected to the


MySQL server. Authentication is done with the help of username and password.

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

45
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.

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.

Buffer and 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.

Table Metadata Cache:

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:

46
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.

CHAPTER 8

SYSTEM TESTING

8.1. TESTING PROCESS

Testing is a set activity that can be planned and conducted systematically.


Testing begins at the module level and work towards the integration of entire
computers-based system. Nothing is complete without testing, as it is vital success of
the system.

Testing Objectives:

There are several rules that can serve as testing objectives, they are

1. Testing is a process of executing a program with the intent of finding an


error

2. A good test case is one that has high probability of finding an


undiscovered error.

3. A successful test is one that uncovers an undiscovered error.

If testing is conducted successfully according to the objectives as stated above,


it would uncover errors in the software. Also testing demonstrates that software
functions appear to the working according to the specification, that performance
requirements appear to have been met.

8.2 STRATEGIC APPROACH TO SOFTWARE TESTING

47
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
 Validation Test
 Acceptance Test

8.2.1 Unit Testing:

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.

8.2.2 Functional Testing:

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.

8.2.3 Integration Testing:

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

48
distributed or even distributed to the public at large in hopes that they will buy the
final product when it is released.

8.2.4 White Box Testing:

Testing based on an analysis of internal workings and structure of a piece of


software. This testing can be done sing the percentage value of load and energy. The
tester should know what exactly is done in the internal program. It includes
techniques such as Branch Testing and Path Testing. White box testing also called as
Structural Testing or Glass Box Testing.

8.2.5 Black Box Testing:

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.

8.2.6 System Testing

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.

8.2.7 Validation Testing

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.

8.2.8 Acceptance Testing

This is a type of testing done by users, customers, or other authorised entities to


determine application/software needs and business processes. Acceptance testing is

49
the most important phase of testing as this decides whether the client approves the
application/software or not. It may involve functionality, usability, performance, and
U.I of the application. It is also known as user acceptance testing (UAT), operational
acceptance testing (OAT), and end-user testing.

CHAPTER 9

CONCLUSION AND FUTURE ENHANCEMENT

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,

50
and refinement of this system are vital to further improving its accuracy, reliability,
and scalability in ensuring public safety.

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.

51
APPENDIX 1

(SAMPLE CODE)
# Part 1 - Building the CNN

# Importing the Keras libraries and packages


from metamodels import Sequential
from keras.layers import Convolution2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
from keras.models import model_from_json
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
batch_size = 32

from tensorflow.keras.preprocessing.image import ImageDataGenerator

train_datagen = ImageDataGenerator(rescale=1/255)

52
train_generator = train_datagen.flow_from_directory('Data', target_size=(100, 100),
batch_size=batch_size, classes = ['knife','pistol'], class_mode='categorical')

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),
# 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()

from tensorflow.keras.optimizers import RMSprop


53
early = tf.keras.callbacks.EarlyStopping(monitor='val_loss',patience=5)
model.compile(loss='categorical_crossentropy',
optimizer=RMSprop(lr=0.001),
metrics=['accuracy'])

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)
model.save('model.h5')

acc = history.history['accuracy']
loss = history.history['loss']

epochs = range(1, len(acc) + 1)


plt.plot(epochs, acc, 'b', label=' accurarcy')
plt.title('accurarcy')
plt.legend()
plt.show()

plt.plot(epochs, loss, 'b', label=' loss')


plt.title(' loss')
plt.legend()
plt.show()

54
import tensorflow as tf
import numpy as np

from tkinter import *


import os
from tkinter import filedialog
import cv2
import time
from matplotlib import pyplot as plt
from tkinter import messagebox

def endprogram():
print("\nProgram terminated!")
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
55
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")

Label(training_screen, text='''Upload Image ''', background="#d9d9d9",


disabledforeground="#a3a3a3",
foreground="#000000", width="300", height="2", font=("Calibri", 16)).pack()
Label(training_screen, text="").pack()
Label(training_screen, text="").pack()
Label(training_screen, text="").pack()

options = [
"knife",
"pistol"

# datatype of menu text


clicked = StringVar()

# initial menu text


clicked.set("knife")

# Create Dropdown menu


drop = OptionMenu(training_screen, clicked, *options)
drop.config(width="30")

drop.pack()
56
ttype = clicked.get()

Button(training_screen, text='''Upload Image''', font=(


'Verdana', 15), height="2", width="30", command=imgtraining).pack()

def imgtraining():
name1 = clicked.get()

print(name1)

import_file_path = filedialog.askopenfilename()
import os
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:")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

cv2.imshow('Original image', image)


cv2.imshow('Gray image', gray)
# import_file_path = filedialog.askopenfilename()
print(import_file_path)
fnm = os.path.basename(import_file_path)
print(os.path.basename(import_file_path))
57
from PIL import Image, ImageOps

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)

""""-----------------------------------------------"""

img = image

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)


cv2.imshow('Original image', img)
# cv2.imshow('Gray image', gray)
# dst = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 21)
dst = cv2.medianBlur(img, 7)
cv2.imshow("Nosie Removal", dst)

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")
58
testing_screen.minsize(120, 1)
testing_screen.maxsize(1604, 881)
testing_screen.resizable(1, 1)
# login_screen.title("New Toplevel")

Label(testing_screen, text='''Upload Image''', disabledforeground="#a3a3a3",


foreground="#000000", width="300", height="2", font=("Calibri", 16)).pack()
Label(testing_screen, text="").pack()
Label(testing_screen, text="").pack()
Label(testing_screen, text="").pack()
Button(testing_screen, text='''Upload Image''', font=(
'Verdana', 15), height="2", width="30", command=imgtest).pack()

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()

print("\n*********************\nImage : " + fnm + "\


n*********************")
img = cv2.imread(import_file_path)
59
if img is None:
print('no data')

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)

img1S = cv2.resize(img1, (200, 200))

cv2.imshow('Original image', img1S)


grayS = cv2.resize(gray, (200, 200))
cv2.imshow('Gray image', grayS)

dst = cv2.fastNlMeansDenoisingColored(img1, None, 10, 10, 7, 21)


cv2.imshow("Noise Removal", dst)
result()

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)
60
result = classifierLoad.predict(test_image)

out = ''
if result[0][0] == 1:
print("knife")
out = "knife"
sendmail("mohammedadhil467@gmail.com", "Prediction Weapon" + out)
messagebox.showinfo("Result", "Classification Result : " + str(out))

elif result[0][1] == 1:
print("pistol")
out = "pistol"
sendmail("mohammedadhil467@gmail.com", "Prediction Weapon" + out)
messagebox.showinfo("Result", "Classification Result : " + str(out))

sendmsg("9994761304", "Prediction Weapon" + out)

def sendmsg(targetno, message):


import requests
requests.post(
"http://sms.creativepoint.in/api/push.json?
apikey=6555c521622c1&route=transsms&sender=FSSMSS&mobileno=" + targetno
+ "&text=Dear customer your msg is " + message + " Sent By FSMSG FSSMSS")

def Camera():
import newwep

def fire():
import Video
61
def sendmail(Mailid, message):
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 = "projectmailm@gmail.com"
toaddr = Mailid

# instance of MIMEMultipart
msg = MIMEMultipart()

# storing the senders email address


msg['From'] = fromaddr

# storing the receivers email address


msg['To'] = toaddr

# storing the subject


msg['Subject'] = "Alert"

# string to store the body of the mail


body = message

# attach the body with the msg instance


msg.attach(MIMEText(body, 'plain'))

# creates SMTP session


s = smtplib.SMTP('smtp.gmail.com', 587)

# start TLS for security


62
s.starttls()

# Authentication
s.login(fromaddr, "qmgn xecl bkqv musr")

# Converts the Multipart msg into a string


text = msg.as_string()

# sending the mail


s.sendmail(fromaddr, toaddr, text)

# terminating the session


s.quit()

def main_account_screen():
global main_screen
main_screen = Tk()
width = 600
height = 600
screen_width = main_screen.winfo_screenwidth()
screen_height = main_screen.winfo_screenheight()
x = (screen_width / 2) - (width / 2)
y = (screen_height / 2) - (height / 2)
main_screen.geometry("%dx%d+%d+%d" % (width, height, x, y))
main_screen.resizable(0, 0)
# main_screen.geometry("300x250")
main_screen.title("Weapon Detection")

Label(text="Weapon Detection", width="300", height="5", font=("Calibri",


16)).pack()

Button(text="UploadImage", font=(

63
'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)

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

64
fromaddr = "projectmailm@gmail.com"
toaddr = "mohammedadhil467@gmail.com"

# instance of MIMEMultipart
msg = MIMEMultipart()

# storing the senders email address


msg['From'] = fromaddr

# storing the receivers email address


msg['To'] = toaddr

# storing the subject


msg['Subject'] = "Alert"

# string to store the body of the mail


body = "Weapon Detection"

# attach the body with the msg instance


msg.attach(MIMEText(body, 'plain'))

# open the file to be sent


filename = "alert.jpg"
attachment = open("alert.jpg", "rb")

# instance of MIMEBase and named as p


p = MIMEBase('application', 'octet-stream')

# To change the payload into encoded form


p.set_payload((attachment).read())

# encode into base64


encoders.encode_base64(p)

65
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)

# attach the instance 'p' to instance 'msg'


msg.attach(p)

# creates SMTP session


s = smtplib.SMTP('smtp.gmail.com', 587)

# start TLS for security


s.starttls()

# Authentication
s.login(fromaddr, "qmgn xecl bkqv musr")

# Converts the Multipart msg into a string


text = msg.as_string()

# sending the mail


s.sendmail(fromaddr, toaddr, text)

# terminating the session


s.quit()

def sendmsg(targetno,message):
import requests
requests.post(
"http://sms.creativepoint.in/api/push.json?
apikey=6555c521622c1&route=transsms&sender=FSSMSS&mobileno=" + targetno
+ "&text=Dear customer your msg is " + message + " Sent By FSMSG FSSMSS")

66
net = cv2.dnn.readNet("yolov3_training_2000.weights", "yolov3_testing.cfg")
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_DEFAULT)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
classes = ["weapon"]

cap = cv2.VideoCapture(0)
flagg = 0
while True:
_, img = cap.read()
height, width, channels = img.shape
# width = 512
# height = 512

# Detecting objects
blob = cv2.dnn.blobFromImage(img, 0.00392, (416, 416), (0, 0, 0), True,
crop=False)
net.setInput(blob)

layer_names = net.getLayerNames()

output_layers =[layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]


colors = np.random.uniform(0, 255, size=(len(classes), 3))
outs = net.forward(output_layers)

# Showing information on the screen


class_ids = []
confidences = []
boxes = []
for out in outs:
for detection in out:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
if confidence > 0.3:
67
# Object detected
center_x = int(detection[0] * width)
center_y = int(detection[1] * height)
w = int(detection[2] * width)
h = int(detection[3] * height)

# 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)

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'
68
winsound.PlaySound(filename, winsound.SND_FILENAME)

cv2.imwrite("alert.jpg", img)
sendmail()
sendmsg("9994761304", " Weapon Detected")

# frame = cv2.resize(img, (width, height), interpolation=cv2.INTER_AREA)


cv2.imshow("Image", img)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
APPENDIX 2
(SCREEN SHOT)

69
70
71
72
73
74
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.

75
76

You might also like