标签:opencv mat
场景
在进行烟雾检测的过程中,需要访问Mat指定区域的像素值,然后判断是否符合烟雾的像素特征(当然,在网上查询到的烟雾像素特征,实际上,并没有正确识别出烟雾),可通过如下的方式进行操作
int similarDegree = 0;
int channel = srcMat.channels();
for (int i=info.smokeLeftTopPos.y; i<maxHeight; i++)
{
for (int j=info.smokeLeftTopPos.x; j<maxWidth; j++)
{
int r = srcMat.at<uchar>(i, j*channel);
int g = srcMat.at<uchar>(i, j*channel+1);
int b = srcMat.at<uchar>(i, j*channel+2);
if ((r>=200) && (g>=200) && (b<=180))
{
similarDegree++;
}
}
}
当然在实际的应用过程中,像素的值很可能不是无符号字符型,还有可能是浮点型,短整型等,可以使用如下的方式进行判断:
int type = 0;
switch(srcMat.type())
{
case CV_8UC3:
type = 0;
break;
case CV_8SC3:
type = 1;
break;
case CV_16UC3:
type = 2;
break;
case CV_16SC3:
type = 3;
break;
case CV_32SC3:
type = 4;
break;
case CV_32FC3:
type = 5;
break;
case CV_64FC3:
type = 6;
break;
}
参考
http://www.cnblogs.com/wangguchangqing/p/4016179.html
标签:opencv mat
原文地址:http://fengyuzaitu.blog.51cto.com/5218690/1946642