Fire Detection System in Python using Opencv

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello world this is Jia from Jia tech school in this video I'm going to teach you how to create a fire detector in python using computer reason so let's get started what we're gonna do in this video we're gonna create a computer system which is going to predict file in video sequences for example the system has main three features those features it can't detect file and video flames and it can't turn on alarm then it can send emails to file engine services to alert them please request for this tutorial you should have some basic programming skill a little bit of Python skill because I'm not gonna teach you any basic syntax like if conditions of for loop so instead of teaching those I'm likely gonna dive into writing code for this project okay the tools I'm gonna use fight on 3.6 and open CV open CV is a computer vision library for C++ and Python and play sound I'm gonna use place on to play the alarm sound okay I hope you guys you can install these dependencies and tools by yourself and the algorithms I'm gonna use HSV color model it just be color model it's it's simply like RGB but it is useful development purposes so these are the colors so the basic algorithm is I'm gonna do we're gonna search for particular color in video flame in order to track the file for example you can see this is the Louisville and Apple color which is responsible for fire and what we're gonna do we're gonna search for this color so if you want to develop any effective methods you should use yellow operates as the deep learning method for creating effective effective models so in this video we're going to only use HSV color model so let's see before I develop the system I think it is for the important is for you the demonstration of the whole system I have already written this software so I'm gonna run this so I have a simple video clip and you can see this video has been recorded on my mobile phone and what we're gonna do I'm gonna put this video inside my system to process it so let's see in order to on my computer's in order to run this program I have the time Python and the name of the system so that's fate so now you can see the file is detecting and after it 10 second it will say and you can see once it's the file it turn on the alarm and it send an email to my mail which is the mail of the file Indian studies so now you can see this is my email address I got a new email and which is from 0 minutes ago and saying warning a final accident has really put it on ABC company so this is the message that the file engine is going to get so this is the system we're gonna build in this tutorial stay tuned we're gonna dive into programming alright guys now we're gonna write the system in Python so I have created a folder in my step called PI fire detection in Python I have a script file now which is empty right now and we're gonna write code inside it and I have a video file which is figure into process videos and I have an alarm sound which is used to turn on the alarm ok now first of all I want to import the CV to liability then I think I know why this video is up here ok and now I have imported the CV - then what I need to do I have to capture the video in order to capture the video CV - or provides a function called capture capture video CV - dot video capture video capture the index of the camera so if you put 0 it is going to access your first webcam if you put 1 it is going to XS here second-wave calm but according to this case what we're gonna do we're going to load load this video clip therefore I'm gonna put the video name inside this it is a MOV file so it is very important for the expansion of the video the second code we're gonna light is avoiding true this this this voice loop is going to one forever so while this loop is running we need to extract flames from the video therefore we had to light this chord red flame flame flame flame then video doc we do okay so what is gonna happen while this loop warning it is going to extract flame from this video and the flame is going to stored here then there's a boolean belly will be here this boolean value is indicating whether we are getting famous or not so it is very useful to stop like if it is equal is equal to false we're going to we're going to like the system like if the video ends Blake the system so that's the meaning of this playing the fool boiled open that's the meaning of the if condition so next I'm gonna do we're going to M so this say v2 dot M so the window name name of the window okay so I'm gonna put name as output okay then we're gonna flame so we're gonna display the flame below we kinda tied if raki if cv to make e 1 and then 0 X F have an equal to all the high th and easy understand this code Q and it's gonna be ended so what is what this line of what is the meaning of this line of code it means when in even plus Q in the in the program okay when anyone passes the Q in the program so that is the meaning of the code so you don't we destroy all windows then video dot release okay now I'm going to execute this program I'm going to execute this placenta program and see what's happening okay in order to execute this program we need to first open CMT and I have to activate to my environment where I have installed all of my dependencies but in your case if you don't use an accountant you can simply run it if you use any wonder if you created your children if you created on the environment you need to do this oh it's learning and you can see the flame is working fine so you can see the flame is working fine but it is very big IIT it is very important to the size this flame you know this flame and in inside here when you lied we're gonna light a piece of code which is going to resize this flame so I take flame flame is equal to CB to resize oh my god I can't access to this we sighs then I have to put this eyes of the window upgrade to resize the window in to do some hundred thousand I'm greatly satisfying two thousand into 600 or something so now I feel on the program and you can see the window has been resized so what we're gonna do right now after we completed this we're going to detect file inside this video so it is just a video clip oh if you want if you put the CCTV camera so if you access your web combat typing 0 here so it is going to access your webcam and you can see my webcam will be turned on like that if you won't exercise I can Caroline we have to put one here if you want access the third camera happy happy put co2 here and so on and so forth so according to this video the according to this tutorial we are accessing video from a source therefore we need to put the video name with the extension so if you hope you do find in a part we have to put the path inside this parameter so what we have done so far we have all these lights the flames or let it run the program to check out what we have done so far they just need to be healthy since event oh and now what we're gonna do I am going to apply certain blood cold cases here blow so reason why I'm green apply the cases in blood in order to remove some noises from the video so if you apply this blow to the video some noises will be removed then the program will be worked much better so I'm going to display the blur right now if you this if you output flame it is going to output the flame if you have output blow it is going to output the latest flame which is given clock and you can see the video has been blurred lot not blood it's no it's not saved yeah that's fine and you can see the video has been build a lot with the reason we have blurred this video if you need your lawyer we need to eliminate some gneisses from the video that's why we can below the video a lot the next we have to convert this 500 this flame into s HP is HP format HSV color so now the video is in VG ow now we need to convert it into HSV so in order to do this we can do obviously we provide a fraction score cv g'v VG color and we're gonna convert below in what format we're gonna convert we are going to convert into color we're gonna convert them to Carlo oh my god I can't access to this Carlo V geometry it just B now we have convert the video five individual to it just see it just me and if we just provide this and you can see a different effect you can see the the video has been converted into HSV what we're gonna do we're gonna search for this particle color inside this video frame so which is you can see the the the the file is a different color I'm going to look for in this video okay next after that we have to apply our our a public value on local value so the Upper Valley is 18 is 18 and 50 and 50 okay the Louisville Valley Apple Valley is that is the lower value the Po Valley is 35 255 and 255 so now we need to convert this into numpy our way because computer cannot work with the numpy Allah is easy it's Anu Malik Al Ahly instructional we have to use inside OpenCV to convert some kinds of flame into numerical value so in order to convert this value into numpy now what we need to do we need to put the variable name then we need to type in B dot Ali then what we're going to convert or convert the L over in format you gonna convert in a kind of a D type d type T type d type into you need 8 format so we have to do it for upper also there from the copy this code and here we'll try upper then a pal okay the next things I'm going to do I'm going to search for masks I need to create the mask you know to create the Moscow types a v2 dot in Linde and I'm going to looking for some color England what sauce I'm going to use the HSV then I'm looking for Louisville and Apple color so basically what this line of code means we are looking for these two types of color teachers of color inside this sssp HSV format okay the next we need to do some kinds of thing which is the output data we're going to get the output data okay output okay simply speak its output and we'll type C to C B - to breed wise okay it just is a confusing one but don't worry you go feet wise and we're gonna do we're gonna do fiercer flame so we're gonna put the HSV then we're gonna put mask equal to a mask okay now we have created our data detector now the next step is to display it just clean okay now if I execute my program for under PI which is gonna do you can see the file is detecting we are only detecting file the other elements are not visible in the video only the file is detecting the next step is to enter the alarm or we can we can simply turn on the alarm instead of doing like that we need to create at first hold in order to check if the file not in order to do that we have to first hit the number of total okay I'm going to use some kinds of course Eevee to dot count so you to dot count non non zero is gonna be I'm gonna put output which is going to do you ask integer value which is going to give a numerical value I'm gonna convert it into in I'm gonna convert that valley into in and I'm gonna check if she's clear than if it is greater than 15,000 okay if it is greater than 15,000 it is a file basically what we are doing with these two lines of code we are measuring the size of the file sometimes if it is a small dot so I need to underscore 18 and she passed this year okay so the problem is like secure it's not actually hitting wrong output zero and it put under the mask actually I need to count the mask okay how many yeah okay and if you see if you see there's a small tiny tiny dot but that's not file so you know what we're doing with this two lines of code we are measuring the size of the file it is very important so if surprise is is gonna be more than this first hold you can adjust this first of all according to your desire we're gonna do we're going to plan file detector okay and you can see only file is detecting if the file size is gonna be I think I have put long or not okay now you can see if it's a bigger file it is saying files detector file is detected okay the next step of the problem is to implement the sound so you need to turn on the alarm so so far what we have done is we have import open CBT and we have analyzed the flames and we detect file so next we need to turn on the alarm so what we have done so far we have detected file we have detected file the next step is to play the turn on the alarm in other words play that audio okay so I think it is important to explain the aerbook code a little bit in order to understand a concept okay so what we are doing here we are loading the video in this variable then this loop will run so many times per second the reason we are doing flame analyzation what we are doing we are doing find a flame analyzation so for a second this world loop one more many times this while loop on many times for example this world loop me one more than ten times or 20 times depending on the frame size okay and here what we are doing we are getting the flame then we are assessing the flame in two hundred thousand into 600 then we are playing case you can blow this blow will smooth the image in in other words we are reducing reducing noises from the image then we are converting to HSV the reason we are using HSV because we need to search for this pattern this pattern representing the color of the file listen carefully okay listen carefully this this pattern representing representing the color of the file the next step is to be a we need to search this this color in HSV then we can find the file so this is how this algorithm works we have defined the Halal of the file here then we are converting this color of the file into numpy away the reason we have converted because in order to work with it it is very important to convert the kernel otherwise it won't work then you can look at this look at this line of code we are searching in vain HSV we are searching this alone upper value which represents the column of the fire again repeating which represents the column of the file so next we are outputting and with later we are playing it then we are calculating the size of the file which is a total number of total which means the size of the file I think you have to precise so it makes much sense than that so size of file then we decide should be more than 15,000 I have put 15,000 you can adjust this you can you can adjust that let's resolve you cannot just as well if you want to detect tiny file if you give 8,000 if you want to detect a large fire you can increase this one sold okay then then what we are doing it is printing from flame detected flame detector so what's the problem and so the next step is to play them play the alarm in order to play the alarm we can type the code here but the problem is it's never gonna work the reason if you like the code here the computer is gonna cost the computer that's gonna last the reason like I said before we are doing flame analyzation this block of code repeat in so many times per second more than 10 or 20 depending on the frame size because if we play the if we play the audio here the audio being played so many times then the computer is gonna be classed for example if you look at the terminal the last output of the system you can say file detected fire detector it's printed so many times oh listen this block of code one so many times but it's okay for printing but if you are trying to play this audio clip this audio clip with 11 seconds of audio clip that's never gonna work because this this block of codes one so many times per second in order to sort out this problem we have what we need to use a technique so first of all I am importing the play sound module which is used to play sound then what I need to do I have to create a variable called fire reporter fire reporter said to 0tm creating another variable called alarm status equal to false okay so what i'm doing here i'm just come here and type file wait for that equal to file wait for third equal to 1 not equal to 1 plus 1 which means when you which means whenever the file is detected you need to increase the fire reported valley y1 so that's the meaning of this code next what I'm gonna do I'm gonna search for like this if fire reported is greater than or equal to 1 which means file detected okay which means fire detected next what I need to do I need to alternate to do I need to 1 the alarm I need to check for another if condition goal if alarm status if the alarm status is equal to phones we need to one the program okay we need to one the audio clip yeah so you know the one that I'm gonna create a small function here that play audio play audio then what I'm going to do I'm gonna play sound odd place ound the name of the Fourier is [Music] clean sound I put on mp3 clearly sound whenever you you cluster set to true ok so what I'm gonna do here when the file is detected unity increased sapphire reported if the file report it is go equal to 1 equal to agree that one and that means file detected if the alarm is equal to phones in u21 this when this function then after that said the alarm status equal to four true so this this means this this means the program is never going to one again for example if the alarm is set one the alarm is going to turn on then it will never turn and you can turn on again because we have used if if condition to check if the alarm is equal to when you know the lamina T equal to false is going to 1 but here the alarm alarm skaters will be true then it will never become false again so if you want this piece of code so see what will happen and you can see it's detecting the file and it needs to turn on the alarm it's turning on the alarm the next step is to send email okay all right what we have done so far we have detected file then we are turning on the alarm so why do we like this piece of code we light this piece of code we load this piece of code in order to Clemen the recent ingly playing we playing over now again playing problem for example we're doing flame analyzation this value points more than 10 times or many times per second in order to quit that in order to get it off pit we are using this this line of code to block it's not just for example I have created a variable called fire detect file a porter set to zero then I checking if the file and I am increasing whenever file detect whenever it detects the file in a in the flame in a video frame it increases number y1 so I'm checking in file report it is equal to or greater than 1 that means fire is detected next I'm gonna check if our alarm status is equal to false if the alarm status is equal two folds this means when the program runs is gonna be nice to false we need to display the alarm then what we need to do we need to set it to true if you don't set it to true what will happen the key feature is trying to send if play the el amor no more no more again it's going to class so we don't want that functionality so there we have built that function or we have know that functions file I think this if condition so next is we are going to send email in order to send email we need to import SM ok SMP lips functionalities or modules the next then we need to we need to do as similar things like this ok female status the reason is we should do it because we know it because the same things we're gonna do it here if the main status is equal to false that means we need to send email ok send email sent a email Omega email function can send the image function then what I need to do email statistic for sure because I don't want the message to send a email although all again to stop my computer so if I put this send email functions we talk to lighting this piece of code what will happen the computer will send the email on own on again so it cannot be done the third one is going to be class so you notice to do that we have do that so what is the sent email function we have endo tchen these functions yet so we need to find these functions over here okay the video is getting too long I think it's almost passed to 20 minutes so I have written I have written this piece of code I'm gonna copy in space and explain what's inside it so this is the send email functions which is executed in which we are calling over here okay or here then each to it is the recipient email you need to put the file engine service email address over here then on then what you need to do you need to setup you our email address here and your password here and the password here then you have to put a email address on here when you are login you have to put a email address at the same time you have to put the email address your system email addresses means your email trust the system is going to use the system this system is going to use a particular email address so you create an email address so it may be gmail address okay it should be Gmail then you're going to put the gmail address here and the password here and the message over here so for the privacy purpose I'm not going to type my password so I am going to post the screen recording and type my password and I will come to the demonstration the system has been completed this is the complete system we are trying to develop see another thing unity minimum fine it is very important you can send email directly okay in in order to send a Gmail you need to log into a Gmail and turn on the secular app tap option if you don't turn on that secure knock happy option you cannot send email from bought like this okay it is a bot you cannot send email like this so in order to do that you have to log in your email your email means the system email that you are going to use and go to settings to the Gmail if you don't know how to setup just Google secure app so for example in order to turn on securely less app in each of your log in your gmail address then go to your security then then after that in the below you can say secure less like you have access and you need to be turn on in order to turn on unity turn like this okay if you if you switch like this you can access this gmail icon programmatically otherwise you can't okay you have to make you have to do the settings in your gmail account before you send emails or programmatically okay that's it that's all about it you have to set the file engine file engine email address which means recipient email others who is going to send you email he is going to send this message to them they need to type your email address and password then your email address that said okay I've been on the program will automatically send emails to this recipe end so before that you have to turn on less secure app features which I showed earlier ok don't forget to do that now we're going to do the demonstration we're going to do the demonstration okay all right guys it's working perfectly but there's a small issues for example if in each one these two function at the same time otherwise it's never going to send the email address for example what is happening it's first playing the audio after the audio completed it's sending the email this is not I want I want to send the email first then I want to play the audio i can give solution in both way and we need to make a small change in code it need to copy and put this functionable and we need to delete this piece of code and you also on don't want this demon status okay what's happening here we made a small changes in our code it does not impact anything we made a small change in the code we have one the main function first first of all and the files detected we need to send the mail then we have to play the audio okay so although the otherwise I can give a solution by using threading okay I'm not gonna use sledding here but easily I can do like this so now it video perfectly so now I'm gonna see what's happening okay all right now the system works perfectly now I'm going to execute the program hi turn write a mission type in low case the one okay and so you see it's detecting the file next it's going to send the email to my email okay and it's turn on the alarm okay so DiMeo okay now you can say it's send email and it made sense then I'm gonna check my mail this is my main hi I got I got an email from my testing male here here's my testing man is saying morning filed accident has been reported on ABC company ok that's it this is the source code I'm also going to upload this source code and github you can download the source code and reuse it or you can reprogram it or adding extra features and putting or training your own model using yellow or something you can integrate with it you can use it for any other reasons and and that's it guys that's all about this and don't forget to subscribe to my youtube channel thank you for watching this video if you subscribe to the YouTube channel I'm going to upload many videos on the field of AI KP divisions and also some programming that's it thank you very much once again for watching this video this is gia from G attack school [Music]
Info
Channel: GR Tech Institute
Views: 47,306
Rating: undefined out of 5
Keywords: Fire-Detection-System, Python, opencv, computer-vision, fire detection, fire detection system, fire detection system using arduino, object detection using python, fire detection alert email, fire detection panel, fire detection alert, fire protection systems, fire detection project, fire detection camera, fire detection cctv camera, object detection, early fire detection, forest fire detection., send email using python
Id: 2uxfqlDbVV4
Channel Id: undefined
Length: 34min 22sec (2062 seconds)
Published: Sat Mar 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.