Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Flame Detection and recognition in OpenCV Video

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you the example analysis of flame detection and identification in OpenCV video, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's learn about it!

Mainly completes the flame detection in two videos, mainly combines the RGB criterion and the HIS criterion, sets the appropriate threshold condition, detects the area of the corresponding pixel of the flame, binarizes the original image, and eliminates some noise and discrete points and connects some missing areas through image processing such as median filtering and mathematical morphology expansion operation. Based on the open source library of OpenCV, the flame detection in two videos is realized on VS2013 platform.

Using OpenCV has a powerful image processing library, the image is directly separated into three RGB channels, the conditions are limited, the pixel position of the flame is found, and the original image is processed into a binary image. For flame detection, this paper combines RGB criterion and HIS criterion to segment the flame region. The general color model used for human eye viewing is the RGB model. For the flame, the red component (R) and the green component (G) will be very large, and the green component (G) will be larger than the blue component (B). HIS color model uses H (chromaticity) S (saturation) I (luminance) to describe color characteristics respectively, which is closely related to the way people feel the color. Considering that the accuracy of the criterion of single color model is not high enough, the HIS constraint is added on the basis of RGB criterion. The specific conditions [1] are:

Among them, Rt is the red component threshold, St is the saturation threshold, and the flame pixel mainly depends on the hue and saturation of the red component (R). If satisfied (1), the position is judged to be a flame pixel, displayed as white, otherwise displayed as black. The selection of threshold in the criterion is very important for flame detection. Generally, it depends on experience. In order to get the best effect of flame recognition, set two sliding bars, change the size of threshold Rt and St, and select the most appropriate value.

Since only the S component in HIS is needed in (1), the color model conversion function is not needed, and the S component can be calculated directly.

After obtaining the binary image, we need to preprocess it, find the missing points and eliminate the abnormal points. Due to the existence of noise and discrete points, the image is smoothed and filtered, this paper uses the median filter, which is a typical nonlinear filter, and uses the median value of the neighborhood gray value of the pixel to replace the gray value of the pixel. It is very helpful to eliminate some pixels which are mistakenly judged as flame.

Because the color of part of the flame is not between red and yellow, it is impossible to identify, so it is necessary to achieve regional connectivity, so the mathematical morphology operation is carried out on the binary image. Morphology is a powerful image processing tool, it can achieve image denoising, image segmentation and other functions, the most basic morphological operations are expansion and corrosion. They can derive many powerful morphological algorithms to achieve the functions we want. The most basic expansion operation of morphological processing is used to act on the binary image of flame.

Write CheckColor function to realize the above three functions.

In order to show the region of the flame in the video, after preprocessing, the flame outline is marked with a rectangular box, and the function DrawFire for drawing the rectangular box is compiled, in which OpenCV's function findContours is used to find the outline. Because the flame position of the test2 is scattered in different places, the whole image is divided into regions and different rectangles are used to mark the flames in different regions.

Based on the library of OpenCV, the algorithm is implemented on VS2013. Since the flame detection in the video is real-time and dynamic, the following images are captured to show the experimental results:

This paper adopts the method of combining RGB criterion with HIS criterion, selects the appropriate threshold according to the empirical method and continuous debugging, and implements the algorithm on VS2013 based on OpenCV. From the experimental results of test1, it can be seen that when the background is monotonous and different from the flame, the effect is good, and almost no noise interferes with it. From the test2 experimental results, we can see that when the background is complex or similar to the flame color, noise and misjudgment will occur from time to time, so the algorithm needs to be further improved.

List the specific codes for processing test2 videos:

# include#include using namespace cv;int redThre = 49; / 1150135 int saturationTh = 7; / / 55065 Mat CheckColor (Mat & inImg); void DrawFire (Mat & inputImg, Mat foreImg); int main () {VideoCapture capture ("test2.avi"); while (1) {Mat frame; capture > > frame If (frame.empty ()) break; namedWindow ("Control", CV_WINDOW_AUTOSIZE); cvCreateTrackbar ("redThre", "Control", & redThre, 255); cvCreateTrackbar ("saturationTh", "Control", & saturationTh, 255); CheckColor (frame) WaitKey (1);} return 0;} / / The Color Check is According to "An Early Fire-Detection Method Based on Image Processing" / / The Author is:Thou-Ho (Chao-Ho) Chen, Ping-Hsueh Wu, and Yung-Chuen Chiou Mat CheckColor (Mat & inImg) {Mat fireImg; fireImg.create (inImg.size (), CV_8UC1); Mat multiRGB [3] Int a = inImg.channels (); split (inImg, multiRGB); / / split the picture into R _ Magi G ~ B, three-channel color for (int I = 0; I).

< inImg.rows; i++) { for (int j = 0; j < inImg.cols; j++) { float B, G, R; B = multiRGB[0].at(i, j); //每个像素的R,G,B值,动态地址计算法 G = multiRGB[1].at(i, j); R = multiRGB[2].at(i, j); float maxValue = max(max(B, G), R); float minValue = min(min(B, G), R); //与HSI中S分量的计算公式 double S = (1 - 3.0*minValue / (R + G + B));// //R >

RT R > = G > = BS > = ((255Mir) * ST/RT) if (R > redThre & R > = G & & G > = B & & S > ((255Mir) * saturationTh / redThre)) {fireImg.at (I, j) = 255i } else {fireImg.at (I, j) = 0;} / / erode (fireImg, fireImg, Mat (3,3, CV_8UC1)) / GaussianBlur (fireImg, fireImg, Size (5,5), 0,0); medianBlur (fireImg, fireImg, 5); dilate (fireImg, fireImg, Mat (5,5, CV_8UC1)); imshow ("Binary", fireImg); DrawFire (inImg, fireImg); return fireImg;} void DrawFire (Mat & inputImg, Mat foreImg) {vector contours_set / / Save the point set and topological relations findContours (foreImg, contours_set, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE) after contour extraction; Point point1; Point point2; float a = 0.4, b = 0.75; float xmin1 = a*inputImg.cols, ymin1 = inputImg.rows, xmax1 = 0, ymax1 = 0 Float xmin2 = b*inputImg.cols, ymin2 = inputImg.rows, xmax2 = a*inputImg.cols, ymax2 = 0; float xmin3 = inputImg.cols, ymin3 = inputImg.rows, xmax3 = b*inputImg.cols, ymax3 = 0; Rect finalRect1; Rect finalRect2; Rect finalRect3; vector::iterator iter = contours_set.begin (); for (; iter! = contours_set.end () ) {Rect rect = boundingRect (* iter); float radius; Point2f center; minEnclosingCircle (* iter, center, radius); if (rect.area () > 0) {point1.x = rect.x Point1.y = rect.y; point2.x = point1.x + rect.width; point2.y = point1.y + rect.height; if (point2.x

< a*inputImg.cols) { if (point1.x < xmin1) xmin1 = point1.x; if (point1.y < ymin1) ymin1 = point1.y; if (point2.x >

Xmax1 & & point2.x

< xmax2) xmax1 = point2.x; if (point2.y >

Ymax1) ymax1 = point2.y;} if (point2.x

< b*inputImg.cols&&point2.x >

A*inputImg.cols) {if (point1.x

< xmin2 && point1.x>

Xmin1) xmin2 = point1.x; if (point1.y

< ymin2) ymin2 = point1.y; if (point2.x >

Xmax2 & & point2.x

< xmax3) xmax2 = point2.x; if (point2.y >

Ymax2) ymax2 = point2.y;} if (point2.x

< inputImg.cols&&point2.x >

B*inputImg.cols) {if (point1.x

< xmin3 && point1.x>

Xmin2) xmin3 = point1.x; if (point1.y

< ymin3) ymin3 = point1.y; if (point2.x >

Xmax3) xmax3 = point2.x; if (point2.y > ymax3) ymax3 = point2.y } + + iter;} else {iter = contours_set.erase (iter) }} if (xmin1 = = axiinputImg.colsgiving & ymin1 = = inputImg.rows&&xmax1 = = 0 & & ymax1== 0) {xmin1 = ymin1 = xmax1 = ymax1= 0 } if (xmin2 = = broominputImg.colsfolk & ymin2 = = inputImg.rows&& xmax2 = = axiinputImg.colsfolk & ymax2 = = 0) {xmin2 = ymin2 = ymax2 = 0;} if (xmin3 = = inputImg.cols&&ymin3 = = inputImg.rows&& xmax3 = = bauxinputImg.colsfolk & ymax3 = = 0) {xmin3 = ymin3 = xmax3 = ymax3 = 0 } finalRect1= Rect (xmin1, ymin1, xmax1-xmin1, ymax1-ymin1); finalRect2 = Rect (xmin2, ymin2, xmax2-xmin2, ymax2-ymin2); finalRect3 = Rect (xmin3, ymin3, xmax3-xmin3, ymax3-ymin3); rectangle (inputImg, finalRect1, Scalar (0,255,0); rectangle (inputImg, finalRect2, Scalar (0255,0)); rectangle (inputImg, finalRect3, Scalar (0255,0)) Imshow ("Fire_Detection", inputImg);} above is all the contents of the article "sample Analysis of Flame Detection and recognition in OpenCV Video". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report