-
大小: 4.26MB文件类型: .zip金币: 1下载: 0 次发布日期: 2023-11-19
- 语言: 其他
- 标签: fire-detecti
资源简介
VS2017+opencv写的火焰检测,带检测视频哦,亲测可用,VS建立的空项目,OPENCV环境配置参考网上
代码片段和文件信息
#include
#include
using namespace cv;
using namespace std;
int redThre = 220; // 115~135 115 或 49
int saturationTh = 7; //55~65 45 或 7
Mat CheckColor(Mat &inImg);
Mat ta tb src morphImage;
void DrawFire(Mat &inputImg Mat foreImg);
int main()
{
VideoCapture capture(“E:/1.mp4“);
while (1)
{
Mat frame;
capture >> frame;
if (frame.empty())
break;
namedWindow(“Control“ CV_WINDOW_AUTOSIZE);
const char*tract_title = “redThre“;
const char*saturationTh_title = “saturationTh“;
createTrackbar(tract_title “Control“ &redThre 255);
createTrackbar(saturationTh_title “Control“ &saturationTh 255);
CheckColor(frame);
waitKey(1);
}
//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); //将图片拆分成RGB三通道的颜色
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); //每个像素的RGB值动态地址计算法
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>=B S>=((255-R)*ST/RT)
if (R > redThre &&R >= G && G >= B && S >((255 - R) * saturationTh / redThre))
{
fireImg.at(i j) = 255;
}
else
{
fireImg.at(i j) = 0;
}
}
}
//erode(fireImg fireImg Mat(3 3 CV_8UC1));
//GaussianBlur(fireImg fireImg Size(5 5) 0 0);
//char output_title[] = “morphology demo“;
//namedWindow(output_title CV_WINDOW_AUTOSIZE);
//Mat kernel = getStructuringElement(MORPH_RECT Size(9 9) Point(-1 -1));
//morphologyEx(fireImg fireImg CV_MOP_GRADIENT kernel);
medianBlur(fireImg fireImg 5);
dilate(fireImg fireImg Mat(5 5 CV_8UC1));
imshow(“Binary“ fireImg);
//vector> contours;
//vector hireachy;
//findContours(morphImage contours hireachy CV_RETR_EXTERNAL CHAIN_APPROX_SIMPLE Point());
//Mat connImage = Mat::zeros(src.size() CV_8UC3);
//for (size_t t = 0; t < contours.size(); t++);
//Rect rect = boundingRect(contours[t]);
//if (rect.width < src.cols / 2)continue;
DrawFire(inImg fireImg);
return fireImg;
}
void DrawFire(Mat &inputImg Mat foreImg)
{
vector> contours_set;//保存轮廓提取后的点集及拓扑关系
findContours(foreImg contours_set CV_RETR_EXTERNAL CV_CHAIN_APPROX_NONE);
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 * inpu
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-07-23 21:20 火焰检测\
文件 5453 2018-07-20 09:46 火焰检测\1.cpp
文件 4468228 2017-07-19 21:58 火焰检测\1.mp4
评论
共有 条评论