Sapmle Report Fire Detection - Python
Sapmle Report Fire Detection - Python
By
SATHYABAMA
INSTITUTE OF SCIENCE AND TECHNOLOGY
(DEEMED TO BE UNIVERSITY)Accredited with Grade “A” by
NAAC JEPPIAAR NAGAR, RAJIV GANDHI SALAI, CHENNAI –
600 119
MARCH - 2022
SATHYABAMA
INSTITUTE OF SCIENCE AND TECHNOLOGY
(DEEMED TO BE UNIVERSITY)
Accredited with “A” grade by NAAC
Jeppiaar Nagar, Rajiv Gandhi Salai, Chennai – 600 119
www.sathyabama.ac.in
BONAFIDE CERTIFICATE
This is to certify that this project report is the bonafide work of PETA MANISH
KUMAR REDDY(Reg. No.38110404) and POTU LAKSHMI PRANEETH
REVANTH KUMAR(Reg. No.38110414) who carried out the project entitled
“COMPUTER VISION-BASED EARLY FIRE DETECTION USING OPEN CV AND
MACHINE LEARNING ” under my supervision from August 2021 to March 2022.
Internal Guide
DATE:
I wish to express my thanks to all Teaching and Non-teaching staff members of the
Department of Computer Science and Engineering who were helpful in many
ways for the completion of the project.
ABSTRACT
1. INTRODUCTION 9
1.1 Overview 9
1.2 Scope and Objective 10
1.3 Domain Overview 10
1.3.1 Machine Learning Model 11
1.3.2 Data Pre-processing 12
1.3.3 Supervised Learning 14
1.3.4 Regression 16
1.3.5 Unsupervised Learning 17
1.3.6 Training and testing the 26
model of data
1.3.7 Validation Set 19
2. LITERATURE SURVEY 22
2.1 Analysis of literature 22
2.2 Literary review 23
3. SYSTEM ANALYSIS 26
3.1 Existing System 26
3.2 Problem Statement 26
3.3 Proposed System 26
3.4 System Design 28
3.5 Haar Like Features 29
3.6 Working Principle 32
3.7 System Requirements 33
4. RESULTS 34
6. REFERENCE PAPERS 36
7. APPENDIX 38
A. Sample Code 38
B. Plagarism Report 43
LIST OF FIGURES
Computer Vision based fire detection using image processing has the potential to
be useful in conditions in which conventional methods cannot be adopted. The fire
detection algorithm uses visual characteristics of fires like brightness, color,
spectral texture, spectral flicker, and edge trembling to discriminate them from
other visible stimuli.There are various fire detection techniques such as infrared
sensor, a thermal detector, smoke detector, flame detector, and optical smoke
detector. These methods are not always reliable as they do not always detect the
fire itself but detect one or more phenomena resulting from fire, such as smoke,
heat, infrared, ultraviolet light radiation or gas, which could be produced in other
ways and hence, produces many false alarms.By the help of computer vision and
image processing techniques, it is possible to get better results than conventional
systems because images can provide more reliable information.
In recent times, research on detection of flame and smoke using surveillance
cameras with machine vision has gained momentum. The image processing
approach involves the extraction of the smoke-plume or flame from the
background by using frame difference technologies. In the case of the
segmentation of fire features, color processing scores over gray-scale processing.
Color processing can avoid the generation of false alarms due to variations in the
lighting conditions, e.g. natural background illumination, better than gray-scale
processing. Further, a video camera is a volume sensor, and potentially monitors a
larger area. The traditional point sensor looks at a point in space. Since the point
sensor may not be affected by smoke or flame, fire would be undetected.
However, vision-based flame and smoke detection still has great technical
challenges, since flame and smoke are non-rigid objects, with none of the primitive
image features and variability in density, lighting, etc.
1.2 SCOPE AND OBJECTIVE
● Step 4: Training
● Step 5: Evaluation
● Step 7: Prediction
Introduction:
In this blog, we will discuss the workflow of a Machine learning project this
includes all the steps required to build the proper machine learning project from
scratch.We will also go over data pre-processing, data cleaning, feature
exploration and feature engineering and show the impact that it has on Machine
Learning Model Performance. We will also cover a couple of the pre-modelling
steps that can help to improve the model performance.
1. Gathering data
2. Data pre-processing
3. Researching the model that will be best for the type of data
5. Evaluation
The machine learning model is nothing but a piece of code; an engineer or data
scientist makes it smart through training with data. So, if you give garbage to the
model, you will get garbage in return, i.e. the trained model will provide false or
wrong prediction
Gathering Data:
The process of gathering data depends on the type of project we desire to make, if
we want to make an ML project that uses real-time data, then we can build an IoT
system that using different sensors data. The data set can be collected from
various sources such as a file, database, sensor and many other such sources but
the collected data cannot be used directly for performing the analysis process as
there might be a lot of missing data, extremely large values, unorganized text data
or noisy data. Therefore, to solve this problem Data Preparation is done.We can
also use some free data sets which are present on the internet. Kaggle and UCI
Machine learning Repository are the repositories that are used the most for
making Machine learning models. Kaggle is one of the most visited websites that
is used for practicing machine learning algorithms, they also host competitions in
which people can participate and get to test their knowledge of machine learning.
1.3.2 Data pre-processing:
As we know that data pre-processing is a process of cleaning the raw data into
clean data, so that can be used to train the model. So, we definitely need data
pre-processing to achieve good results from the applied model in machine
learning and deep learning projects.Most of the real-world data is messy, some of
these types of data are:
● Missing data: Missing data can be found when it is not continuously created
or due to technical issues in the application (IOT system).
● Noisy data: This type of data is also called outliners, this can occur due to
human errors (human manually gathering the data) or some technical
problem of the device at the time of collection of data.
● Inconsistent data: This type of data might be collected due to human errors
(mistakes with the name or values) or duplication of data.
How can data pre-processing be performed?
These are some of the basic pre — processing techniques that can be used to
convert raw data.
Our main goal is to train the best performing model possible, using the
pre-processed data.The Machine learning is divided into two parts namely
Supevised Learning and Unsupervised Learning.So these methods will help us
with the best model.
Classification:
Classification problem is when the target variable is categorical (i.e. the output
could be classified into classes — it belongs to either Class A or B or something
else).
A classification problem is when the output variable is a category, such as “red” or
“blue” , “disease” or “no disease” or “spam” or “not spam”.
As shown in the above representation, we have 2 classes which are plotted on the
graph i.e. red and blue which can be represented as ‘setosa flower’ and ‘versicolor
flower’, we can image the X-axis as there ‘Sepal Width’ and the Y-axis as the
‘Sepal Length’, so we try to create the best fit line that separates both classes of
flowers.
● K-Nearest Neighbor
● Naive Bayes
● Logistic Regression
1.3.4 Regression:
1.4 Prediction of IQ
As shown in the above representation, we can imagine that the graph’s X-axis is
the ‘Test scores’ and the Y-axis represents ‘IQ’. So we try to create the best fit line
in the given graph so that we can use that line to predict any approximate IQ that
isn’t present in the given data.
● Linear Regression
● Ensemble Methods
The unsupervised learning is categorized into 2 other categories which are “Clustering”
and “Association”.
Clustering:
A set of inputs is to be divided into groups. Unlike in classification, the groups are
not known beforehand, making this typically an unsupervised task.
● Gaussian mixtures
● K-Means Clustering
● Boosting
● Hierarchical Clustering
● K-Means Clustering
● Spectral Clustering
For training a model we initially split the model into 3 three sections which are
‘Training data’ ,‘Validation data’ and ‘Testing data’.You train the classifier using
‘training data set’, tune the parameters using ‘validation set’ and then test the
performance of your classifier on unseen ‘test data set’. An important point to note
is that during training the classifier only the training and/or validation set is
available. The test data set must not be used during training the classifier. The test
set will only be available during testing the classifier.
Fig 1.8 Training set
Training set:
The training set is the material through which the computer learns how to process
information. Machine learning uses algorithms to perform the training part. A set of
data used for learning, that is to fit the parameters of the classifier.
In a data set, a training set is implemented to build up a model, while a test (or
validation) set is to validate the model built. Data points in the training set are
excluded from the test (validation) set. Usually, a data set is divided into a training
set, a validation set (some people use ‘test set’ instead) in each iteration, or
divided into a training set, a validation set and a test set in each iteration.
The model uses any one of the models that we had chosen in step 3/ point 3.
Once the model is trained we can use the same trained model to predict using the
testing data i.e. the unseen data. Once this is done we can develop a confusion
matrix, this tells us how well our model is trained. A confusion matrix has 4
parameters, which are ‘True positives’, ‘True Negatives’, ‘False Positives’ and
‘False Negative’. We prefer that we get more values in the True negatives and true
positives to get a more accurate model. The size of the Confusion matrix
completely depends upon the number of classes.
True positives : These are cases in which we predicted TRUE and our predicted
output is correct.
We can also find out the accuracy of the model using the confusion matrix.
Evaluation:
To improve the model we might tune the hyper-parameters of the model and try to
improve the accuracy and also looking at the confusion matrix to try to increase
the number of true positives and true negatives.
Conclusion:
In this blog, we have discussed the workflow a Machine learning project and gives
us a basic idea of how a should the problem be tackled.
CHAPTER 2
LITERATURE SURVEY
Z.-J. Zhang, J.-S. Fu, H.-P. Chiang, and Y.-M. Huang et al. said fire is a common
and disastrous phenomenon in subway transportation systems because of closed
environment and large passenger row. Traditional methods detect and forecast re
incidents by fusing the data collected by wireless sensor networks and compare
the fusion result with a threshold. However, this approach has a signicant
shortcoming. Fusion of data decreases the amount of useful information since the
distribution of data is not considered. In this paper, a novel mechanism based on
wireless sensor networks is proposed and we can use the mechanism to detect re
in subway transportation systems. e core algorithm in this mechanism is an
alternative of data fusion in wireless sensor networks. e mechanism uses the
quantity information acquired from the data and also considers the distribution
information of the data in order to predict the occurrence of re incidents. e
simulation results show that re incidents can be detected fast and eciently.
Forest Fire Smoke Detection Based on Visual Smoke Root and Diffusion
(IEEE2019)
The damage caused by forest fire to forestry resources and economy is quite
serious. As one of the most important characters of early forest fire, smoke is
widely used as a signal of forest fire. In this paper, we propose a novel forest fire
smoke detection method based on computer vision and diffusion model. Unlike
the video-based methods that usually rely on image characters extraction, we try
to find the shape of smoke that is at the generation stage. To combine vision and
diffusion model together, the basic concept of smoke root is proposed. In the
frame processing stage, none characters of fire smoke are extracted (like texture,
color, frequency information etc.), and continuous frames are only used to extract
stable points in dynamic areas as the smoke root candidate points. In the diffusion
model simulation stage, all smoke root candidate points information is adopted by
the model to generate the simulation smoke. Finally, the match algorithm based
on
color, dynamic areas and simulation smoke is implemented to get the final results.
In order to reduce the complexity of computation, we ignored the simulation
process of the smoke details, such as texture and turbulence, and only retained
the contour features in two-dimensional form.
The paper presents an early fire-alarm raising method based on video processing.
The basic idea of the proposed of fire-detection is to adopt a RGB (red, green,
blue) model based chromatic and disorder measurement for extracting fire-pixels
and smoke-pixels. The decision function of fire-pixels is mainly deduced by the
intensity and saturation of R component. The extracted fire-pixels will be verified if
it is a real fire by both dynamics of growth and disorder, and further smoke. Based
on iterative checking on the growing ratio of flames, a fire-alarm is given when the
alarm-raising condition is met. Experimental results show that the developed
technique can achieve fully automatic surveillance of fire accident with a lower
false alarm rate and thus is very attractive for the important military, social security,
commercial applications, and so on, at a general cost.
CHAPTER 3
SYSTEM ANALYSIS
The main motivation for fire prediction is to provide proper resource allocation and
to help in best possible way to firefighters of Fire Management team. The main
factors of fire are Meteorological conditions. the climatic information is gotten from
nearby sensors which are fused in the closest meteorological stations. Land with a
possible high fire risk has many indicators that can be used to measure the
forecast by closely evaluating the indications. Every year, fire destroys millions of
hectares of land. These fires have burned vast areas and generate more carbon
monoxide than total vehicle traffic.Monitoring potential danger areas and early
warning of fire can greatly reduce response time, as well as the potential for
damage and firefighting costs.
Here In Fire Detection, We Are Using The Haar Cascade Classifier, Which Is Very
Popular In Object Detection Through The Image Or Any Other Video Feeds.For
Detection We Use Open Cv Which Is A Library Of Python Bindings Designed To
Solve Computer Vision Problems.We Use Adaboost Algorithm Which Is A
Learning Algorithm Used To Train The Classifier And Selects The Best Subset Of
Features.Cascade Classifier Is Used For The Accuracy Of Identification. It Is
Composed Of Several Stages Consisting Of A Strong Classifier.
ADVANTAGES:
The system can be used in various areas like in parking areas, road traffic congestions,
agriculture, farming, there are many uses of object detection.
In future, this approach can be extended by for other disasters as well.
BLOCK DIAGRAM:
3.4 SYSTEM
DESIGN Modules:
● Detection
● Haar-like Features
● Integral Image
● Training and Learning
● Adaptive Boosting (Ada Boost)
● Cascading
Detection:
The procedure for detecting fire classifies images based on the value of simple
features from an image. While detecting the fire, first of all, image is converted into
grayscale since it is easy to work with, and it has less data rather than RGB color
images
The algorithm outlines a box and searches for the fire in the image,, the box is
searching for Haar-like features.
Along with small steps, the box detects the features like edges, brightness level
from the image of fire, and then data collected by boxes are put together, which
helps to determine where the fire is located
Haar features are similar to convolutional kernels, which are used to detect the
presence of those features in the given image.
The grayscale has some features some of the regions are black, some regions are
white, and some region is slightly darker or vice-versa from each other which
helps the machine to understand an image.
He Haar features like edge features, line features, center-surround features
rectangle is moved around the image.
The color white and black is decided according to the region. Which compares the
brightness and extracts features by assigning some values as it goes and inspects
through that region in an image.
⦁ The construction of the haar is like that of a confirmed egg and is utilized to
⦁ Dim has a few dark regions and some have white regions, some are hazier or
some are a method for aiding the vehicle feel the picture.
⦁ He Haar has side highlights, line elements, and elements around the focal
point of the square shape.
⦁ White and dark are territorially supported. It represents light and disposes of
the trademark by allocating a particular worth as it goes through the photo and
controlling the region.
Formula:
Integral Image:
The integral image plays an important role. It gives a boost to the calculation,
which makes the approach as fast as possible because there are thousands of
pixels that need to be calculated.
While applying rectangular haar features the sum of pixels in unshaded rectangles
sides are subtracted from the sum of the pixel in the shaded side of rectangles.
Even for a small size images there are lots of features (over 160,000 for a 24x24
image).
Since due to large number of features the algorithm requires iterating overall
features, the features must be computed efficiently. So to solve this issue integral
image is introduced.
The sum of the pixel in rectangle D can be calculated with reference to four arrays.
The value of the image at location 1 is the sum of pixels in a rectangle.
Respectively value at position 2 is A+B, value at position 20 3 is A+C, and value at
position 4 is A+B+C+D.
Adaboost algorithm is a learning algorithm used to train the classifier and selects
the best subset of features. The algorithm learns from the data that is given and
determine the false positive and true negatives in data.
F(x)= a1f1(x) + a2f2(x) + ....
Here F(x) is the strong classifier, and a1f1(x), a2f2(x) are weak classifiers where
a1, a2 are the weights, and f1, f2 are the features.
So the strong classifier is made up of many weak classifiers since one weak
classifier is not good as adding more classifiers makes the algorithm stronger and
accurate, which is called an ensemble.
Cascading:
The first step is the training of the classifier, as mentioned early. Training for the
highly accurate classifier needs lots of time and processing power, so here we
only used a little number of pictures.
After training the fire cascade classifier, the captured frame from the webcam is
converted into grayscale. The reason for converting frame into grayscale is
because the frame captured by webcam is in RGB color.
Since RGB images have three channels of colors, so if the image is converted into
grayscale, there will be only one channel, either black or white, which is easy to
process.
After the conversion, the fire classifier is used, which will help to find the features
and location of images. Parameters like scale factor and min neighbor are passed.
These factors are an essential factor in detecting fire. A scale factor is used for
creating of scale pyramid because while training the classifier fixed size of the
image is trained, so the scale factor will allow rescaling the size of an input frame
to detect the fire.
Another parameter min 24 neighbor will determine the quality of an image here
for thesis min neighbor factor
HARDWARE REQUIREMENTS:
SOFTWARE REQUIREMENTS:
displayed as FIRE.
5.1 Conclusion:
The project aimed to detect fire with a different approach rather than using an
existing system. As technology is getting better and better as to keep it up with the
technology and to minimize the limitations also, the new system has created. By
using image processing technology for detecting the fire, these limitations can be
reduced because in this system camera acts like a human eye, as it detects a fire,
the video is captured, and the image is processed using the software alert user. It
can be used everywhere eg. Hospital, railway station, forest etc. The designed
prototype successfully detects fire. gives the review analysis, designing system,
and algorithm, test, and result.
Currently, we not used the systems like a smoke detector and sprinkler water
discharge systems, but in future it can be included.
Due to safety reasons, the effectiveness of the system cannot be tested in the full
phase, so here for the prototype demo, the lighter is used as the source of fire as it
has the same features and characteristics of the fire. There is some error in
detection when the fire is far away from the camera because of the size of the
flame. The system can be made more accurate and precise by using other
machine learning algorithms like YOLO(You Only Look Once), Tensorflow, Keras
algorithm, neural network like CNN, RCNN, which are more advanced than the
current algorithm.
REFERENCE PAPERS:
A.SAMPLE CODING
import cv2
import numpy as np
import math
import pygame
pygame.init()
pygame.mixer.music.load("alarm.wav")
windowName = "OpenCV Video Player"
cv2.namedWindow(windowName)
cap = cv2.VideoCapture(0)
t=5
p=1
k = cv2.getStructuringElement(cv2.MORPH_CROSS, ((t, t,)))
# print(k)
dil = cv2.dilate(im, k, iterations=p)
er = cv2.erode(im, k, iterations=p)
fin = cv2.bitwise_and(er, dil)
# cv2.imshow("FIRE",frame)
# cv2.imshow("segmented fire",cv2.bitwise_and(frame,frame,mask=fin))
im = cv2.bitwise_and(bin_cie, im)
# cv2.imshow("RGBCIE",im)
for i in range(retval):
if i > 0:
if stats[i][4] > 2:
NOc = NOc + stats[i][4]
# print(NOc)
if NOc > NOl:
CGO = CGO + 1
NOl = NOc
NOc = 0
fps = 24
if x % fps == 0:
dt = CGO * 1.0 / fps
print(dt)
CGO = 0
x=1
x=x+1
# print(dt)
lframe = cframe
if dt > 0.3:
count = count + 1
if count > 10:
mc = mc + 1
if mc % 15 == 1:
print("fire")
try:
pygame.mixer.music.play()
except:
pass
count = 0
if dt < 0.2:
print("not fire")
k = cv2.waitKey(1)
if k == ord('q'):
break
cv2.destroyAllWindows()
cap.release()
B.PLAGARISM REPORT