Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Train fire detection using opencv SVM [closed]

Tags:

c++

opencv

svm

I'm using SVM since I need ML to train my classifier, and I saw on several papers on fire detection that they used SVM and logistic regression but since there is no logistic regression in 2.4.9 I'm planning on using SVM. I'm using opencv 2.4.9 since people said opencv 3 is buggy.

Im new to this so it will be helpful if we start from basic

I have prepared several fire and non-fire videos ready to be extracted into frames. I'm new to opencv and everything about classifiers. My question is what are the basics in training a classifier specifically SVM, What format do I need my images to be and how do I train them? Are there any good links for a tutorial? I found one in opencv documentation but it doesn't teach on training using image. What do I need in determining parameters and what are the parameters for? Thanks in advance

like image 492
Red Viper Avatar asked Feb 04 '16 10:02

Red Viper


2 Answers

This is a conceptual question that calls for lots of papers and tutorials to explain. However, As it was explained in the comments I try to elaborate on feature extraction. Feature descriptors should be robust against scaling, translate and rotation. This robustness is literally referred to as invariant features. For instance, moments and its derivatives are one of the most famous type of invariant against rotation, scaling and translate. You may find the usage of Hu moments as explained in this paper. Flame or fire detection is something different. The feature corresponds to flame can be extracted from fire's dynamic texture. For instance, fire has a special color texture that segregates it from the background. The conventional flame detectors make use of infrared sensors to detect a flame. In image processing, or RGB world, we can do the same by considering the nature of flame itself. Flame emits a significant portion of its energy through heat and infrared ray. So, one can expect a major portion of red channel to be devoted to flame. See the following image for example.enter image description here enter image description here

In the processed image, the red channel is converted to BW image by imposing a threshold. To be more clear, I have separated the 3 channels as below.
R:red channel G:green channel B:blue channel
It is evident the Red channel has more to say about the flame. Therefore, it can be concluded that the flame is where R channel has a portion of its information, then G and finally B channel. See this.
Your feature vector, then, will be a three dimensional vector about, for example, the contour of the flame in three RGB channels. SVM classifiers are now ready to be used. Sometimes, the video may contain flam-liked segments that should be avoided and they lead to false alarms otherwise. SVM, assists you to accept or reject a flame candidate. To train your support vector machine, collect some true flames and some images that may be misjudged by your feature extractor. Then, label them with positive and negative features. Finally, let opencv do the magic and train it. For more information about SVM, please watch this video by Patrick Winston, MIT on youtube.

UPDATE ---- As you are curious about creating feature vector, I brought to you the following example. Assume that R,G,B channels are finely segregated so as to one can call them statistically independent as the follow; This is not true in real images wherein R,G,B planes are not statistically independent. enter image description here
Therefore, a point in the RGB image will have 3 representations in RGB channels. For instance, a flame will make 3 spots on all the R,G,B planes. The area of each spot, for example, is being traced here. Label the flame spot in RGB image as "A". enter image description here
The representations of the area A were depicted above in R , G , B images. A_r , A_g , A_b denote the corresponding area of the area A on R,G,B planes, respectively.

enter image description here Therefore, point A will be represented by a triplet (Ar,Ag,Ab) in xyz plane. SVM, now accepts this vector as input and decide if it signifies a real flame.
The areas, normalized format, is one of the many geometrical features that you can involve in decision making process. Other useful features of this kind are aspect ratios, moments and so on.

In a nutshell, you have to do the following:
1 - Find the flame-liked areas.
2 - Trace the candidate spot in all of the R,G,B planes.
3 - Extract the feature( I suggest moments) in every plane.
4 - Form the feature vector
5 - Feed the SVM with this vector

I hope you find this useful.

like image 161
Davood Falahati Avatar answered Nov 13 '22 03:11

Davood Falahati


Yes right so your job now is to make a .txt file with data on each image that you gonna process. The ones which are true will be denoted by +1 followeed with feature set and end it with a -1 and the ones which are false images of fires will start with -1 followed with feature sets and end it with -1 again before starting with feature set of next image its gonna b a tedious job but I am sure ul manage that and finally save that file with extension of .train and not .txt so your training file name gonna be filename.train

like image 2
Piyush Rumao Avatar answered Nov 13 '22 03:11

Piyush Rumao