Posted on

Fire detection in video

Stefan Linner

The main aim of this example is to automatically detect fire in video, using computer vision methods, implemented in real-time with the aid of the OpenCV library. Proposed solution must be applicable in existing security systems, meaning with the use of regular industrial or personal video cameras. Necessary solution precondition is that camera is static. Given the computer vision and image processing point of view, stated problem corresponds to detection of dynamically changing object, based on his color and moving features.

While static cameras are utilized, background detection method provides effective segmentation of dynamic objects in video sequence. Candidate fire-like regions of segmented foreground objects are determined according to the rule-based color detection.

Input

linner_input

Process outline

linner_process

Process steps

  1. Retrieve current video frame
    capture.retrieve(frame);
    
  2. Update background model and save foreground mask to
    BackgroundSubtractorMOG2 pMOG2;
    Mat fgMaskMOG2,
    pMOG2(frame, fgMaskMOG2);
    
  3. Convert current 8-bit frame in RGB color space to 32-bit floating point YCbCr color space.
    frame.convertTo(temp, CV_32FC3, 1/255.0);
    cvtColor(temp, imageYCrCb, CV_BGR2YCrCb);
    
  4. For every frame pixel, check if it is foreground and if it meets the expected fire color features.
    colorMask = Mat(frame.rows, frame.cols, CV_8UC1);
    for (int i = 0; i < imageYCrCb.rows; i++){
    	const uchar* fgMaskValuePt = fgMaskMOG2.ptr<uchar>(i);
    	uchar* colorMaskValuePt = colorMask.ptr<uchar>(i);
    	for (int j = 0; j < imageYCrCb.cols; j++){ if (fgMaskMOG2[j] > 0 && isFirePixel(i, j))
    			colorMaskValuePt[j] = 255;
    		else
    			colorMaskValuePt[j] = 0;
    	}
    }
    
    …
    
    const int COLOR_DETECTION_THRESHOLD = 40;
    bool isFirePixel(const int row, const int column){
    	…
    		if (valueY > valueCb
    			&& intValueCr > intValueCb
    			&& (valueY > meanY && valueCb < meanCb && valueCr > meanCr)
    			&& ((abs(valueCb - valueCr) * 255) > COLOR_DETECTION_THRESHOLD))
    			return true;
    
  5. Draw bounding rectangle
    vector<Point> firePixels;
    …
    if (colorMaskPt[j] > 0)
    firePixels.push_back(Point(j, i));
    …
    rectangle(frame, boundingRect(firePixels), Scalar(0, 255, 0), 4, 1, 0);
    

Samples

linner_mask
Foreground mask
linner_mask2
Fire region mask
Linner_Fire
Result

References

CELIK, T., DEMIREL, H.: Fire detection in video sequences using a generic color model. In: Fire Safety Journal, 2008, 44.2: 147-158.