zoukankan      html  css  js  c++  java
  • 【计算机视觉】森林火灾检测-1

    转载请注明出处:http://blog.csdn.net/xiaowei_cqu/article/details/7522467

    前段时间做了一个火灾检测的小程序,因为时间紧,实现的算法也简单。只用了两步处理:运动检测和颜色检测。日后还会再改进~

    运动检测

    其实就是检测背景,对背景建模然后提取前景中运动的物体作为候选火灾样本。尝试了两种简单的背景算法:高斯背景建模和背景相减,还是背景相减的效果较好。以下是代码:
    [cpp] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. //背景相减  
    2. void FireDetector:: CheckFireMove(IplImage *pImgFrame/*, IplImage* pInitBackground, IplImage *pImgMotion*/)  
    3. {  
    4.     int thresh_low = 80;//30  
    5.   
    6.     cvCvtColor(pImgFrame, pImgMotion, CV_BGR2GRAY);  
    7.     cvConvert(pImgMotion, pMatFrame);  
    8.     cvConvert(pImgMotion, pMatProcessed);  
    9.     cvConvert(pImgBackground, pMatBackground);  
    10.   
    11.     cvSmooth(pMatFrame, pMatFrame, CV_GAUSSIAN, 3, 0, 0);  
    12.     //计算两幅图的差的绝对值  
    13.     cvAbsDiff(pMatFrame, pMatBackground, pMatProcessed);  
    14.     //cvConvert(pMatProcessed,pImgProcessed);  
    15.     //cvThresholdBidirection(pImgProcessed,thresh_low);  
    16.     //对单通道数组应用固定阈值操作,此处得到二值图像  
    17.     cvThreshold(pMatProcessed, pImgMotion, thresh_low, 255.0, CV_THRESH_BINARY);  
    18.     //使用 Gaussian 金字塔分解对输入图像向下采样,再向上采样  
    19.     cvPyrDown(pImgMotion,pyrImage,CV_GAUSSIAN_5x5);  
    20.     cvPyrUp(pyrImage,pImgMotion,CV_GAUSSIAN_5x5);  
    21.     //腐蚀和膨胀操作  
    22.     cvErode(pImgMotion, pImgMotion, 0, 1);  
    23.     cvDilate(pImgMotion, pImgMotion, 0, 1);   
    24.   
    25.     //使用当前帧0.3的比例对背景图像更新  
    26.     int pUpdate=0.3;//0.0003  
    27.     cvRunningAvg(pMatFrame, pMatBackground, pUpdate, 0);                      
    28.     cvConvert(pMatBackground, pImgBackground);  
    29. }  

    颜色检测
    颜色检测最初用的是Thou-Ho (Chao-Ho) Chen, Ping-Hsueh Wu, and Yung-Chuen Chiou 于2004年在ICIP发表的文章《An Early Fire-Detection Method Based on Image Processing》中建立的颜色模型:

    其中R、G、B为RGB模型中的颜色分量S为HSI颜色模型中的饱和度;Rt为R分量的阈值经试验得到可设定在55~56之间;St为饱和度的阈值经试验得到可设定在115~135之间。虽然简单,确很有效。之后自己又增加了些亮度之类的信息,并调整了阈值。
    [cpp] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. //论文《An Early Fire-Detection Method Based on Image Processing》中的颜色模型  
    2. void FireDetector::CheckFireColor2(IplImage *RGBimg)  
    3. {  
    4.     int RedThreshold=115;  //115~135   
    5.     int SaturationThreshold=45;  //55~65  
    6.   
    7.     for(int j = 0;j < RGBimg->height;j++)  
    8.     {  
    9.         for (int i = 0;i < RGBimg->widthStep;i+=3)  
    10.         {  
    11.             uchar B = (uchar)RGBimg->imageData[j*RGBimg->widthStep+i];  
    12.             uchar G = (uchar)RGBimg->imageData[j*RGBimg->widthStep+i+1];  
    13.             uchar R = (uchar)RGBimg->imageData[j*RGBimg->widthStep+i+2];  
    14.             uchar maxv=max(max(R,G),B);   
    15.             uchar minv=min(min(R,G),B);   
    16.             double S = (1 - 3.0*minv/(R+G+B));  
    17.               
    18.             //火焰像素满足颜色特征  
    19.             //(1)R>RT   (2)R>=G>=B   (3)S>=( (255-R) * ST / RT )  
    20.             if(R>RedThreshold&&R>=G&&G>=B&&S>0.20/*&&/*S>(255-R)/20&&S>=((255-R)*SaturationThreshold/RedThreshold)*/)  
    21.                 pImgFire->imageData[i/3+pImgFire->widthStep*j] = 255;  
    22.             else  
    23.                 pImgFire->imageData[i/3+pImgFire->widthStep*j] = 0;  
    24.               
    25.         }  
    26.     }  
    27. }  

    经过两部检测后的备选像素,大于一定值则判定为火,标框并报警,效果如下:


  • 相关阅读:
    一个标准的类通常要拥有下面四个组成部分
    局部变量和成员变量的区别
    Java学习: 面向对象的使用与注意事项
    学习:内存的申请与释放
    虚拟内存与物理内存
    实现:win32实现EDIT控件读取和保存
    学习:生产者和消费者模式实现线程同步
    学习:线程互斥
    学习:多线程
    实现:服务程序增删
  • 原文地址:https://www.cnblogs.com/alan666/p/8312349.html
Copyright © 2011-2022 走看看