資源簡介
具體描述看我博客。2、 具體的操作方法:將原圖像進行RGB三通道分離,去取各個通道像素的值,根據(jù)實驗得出的經驗,對火災像素定規(guī)則,規(guī)定各個分量之間的關系。根據(jù)這個規(guī)則對輸入圖像進行判斷,創(chuàng)建一個新的圖像,符合就在這個新的圖像中保存火災像素的位置,否則不保存(如圖所示);將創(chuàng)建的二值圖像進行檢測輪廓,根據(jù)輪廓組數(shù)進行火災識別框的繪制,最后輸出結果圖像。

代碼片段和文件信息
#include
#include
#include
using?namespace?cv;
using?namespace?std;
void?DrawFire(Mat?&inputImg?Mat?foreImg)
{
vector>?contours_set;//保存輪廓提取后的點集及拓撲關系??
findContours(foreImg?contours_set?CV_RETR_EXTERNAL?CV_CHAIN_APPROX_NONE);//CV_CHAIN_APPROX_NONE獲取輪廓上所有像素點
vector?>::iterator?iter?=?contours_set.begin();//iterator迭代器
for?(;?iter?!=?contours_set.end();)
{
Rect?rect?=?boundingRect(*iter);//1、計算*iter點集的矩形?獲取包含點集對象的垂直矩陣
if?(rect.area()>?0)
{
rectangle(inputImg?rect?Scalar(0?255?0));//2、1和2共同構成點集對象的垂直矩陣
++iter;
}
else
{
iter?=?contours_set.erase(iter);
}
}
namedWindow(“showFire“);
imshow(“showFire“?inputImg);
imwrite(“火焰識別.jpg“?inputImg);
waitKey(0);
}
Mat?CheckColor(Mat?&inImg)
{
Mat?fireImg;
fireImg.create(inImg.size()?CV_8UC1);
int?redThre?=?115;?//?115~135??
int?saturationTh?=?45;?//55~65??
Mat?multiRGB[3];
int?a?=?inImg.channels();
split(inImg?multiRGB);?//將圖片拆分成RGB三通道的顏色??
for?(int?i?=?0;?i? {
for?(int?j?=?0;?j? {
float?B?G?R;
B?=?multiRGB[0].at(i?j);?//每個像素的RGB值??
G?=?multiRGB[1].at(i?j);
R?=?multiRGB[2].at(i?j);
int?maxValue?=?max(max(B?G)?R);
int?minValue?=?min(min(B?G)?R);
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?>0.20?&&?S?>((255?-?R)?*?saturationTh?/?redThre))
{
fireImg.at(i?j)?=?255;
}
else
{
fireImg.at(i?j)?=?0;
}
}
}
dilate(fireImg?fireImg?Mat(5?5?CV_8UC1));
imshow(“fire“?fireImg);
imwrite(“火焰像素點.jpg“?fireImg);
waitKey(0);
DrawFire(inImg?fireImg);
return?fireImg;
}
int?main()
{???//主函數(shù)
Mat?inputImg?=?imread(“2.jpg“);
CheckColor(inputImg);
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????114176??2017-10-06?17:36??火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.exe
?????文件?????559280??2017-10-06?17:36??火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.ilk
?????文件????1846272??2017-10-06?17:36??火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.pdb
?????文件??????70368??2017-10-05?13:46??火災識別代碼精簡精煉\火災識別代碼精簡精煉\2.jpg
?????文件?????576512??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\vc120.idb
?????文件????1372160??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\vc120.pdb
?????文件?????501864??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\源.obj
?????文件???????2397??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.log
?????文件????????608??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.tlog\cl.command.1.tlog
?????文件???????9566??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.tlog\CL.read.1.tlog
?????文件????????408??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.tlog\CL.write.1.tlog
?????文件???????1920??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.tlog\li
?????文件???????4944??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.tlog\li
?????文件????????392??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.tlog\li
?????文件????????179??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.tlog\火災識別代碼精簡精煉.lastbuildstate
?????文件???????2063??2017-10-06?16:26??火災識別代碼精簡精煉\火災識別代碼精簡精煉\源.cpp
?????文件???????4106??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\火災識別代碼精簡精煉.vcxproj
?????文件????????944??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\火災識別代碼精簡精煉.vcxproj.filters
?????文件??????55956??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\火焰像素點.jpg
?????文件?????139759??2017-10-06?17:37??火災識別代碼精簡精煉\火災識別代碼精簡精煉\火焰識別.jpg
?????文件???13434880??2017-10-06?17:37??火災識別代碼精簡精煉\火災識別代碼精簡精煉.sdf
?????文件???????1036??2017-10-06?16:17??火災識別代碼精簡精煉\火災識別代碼精簡精煉.sln
????..A..H.?????21504??2017-10-06?17:37??火災識別代碼精簡精煉\火災識別代碼精簡精煉.v12.suo
?????目錄??????????0??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug\火災識別代碼精簡精煉.tlog
?????目錄??????????0??2017-10-06?17:36??火災識別代碼精簡精煉\火災識別代碼精簡精煉\Debug
?????目錄??????????0??2017-10-06?17:36??火災識別代碼精簡精煉\Debug
?????目錄??????????0??2017-10-06?17:37??火災識別代碼精簡精煉\火災識別代碼精簡精煉
?????目錄??????????0??2017-10-06?17:37??火災識別代碼精簡精煉
-----------?---------??----------?-----??----
?????????????18721294????????????????????28
............此處省略1個文件信息
評論
共有 條評論