网上很多提取颜色分量的博客,就是我提取出来的为啥不一样,然后用了其他方法得到了一样效果的图,就是白色很尴尬。
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
using namespace cv;
using namespace std;
void GetRedComponet(Mat srcImg)
{
//如果直接对srcImg处理会改变main()函数中的实参
Mat dstImg = srcImg.clone();
Mat_<Vec3b>::iterator it = dstImg.begin<Vec3b>();
Mat_<Vec3b>::iterator itend = dstImg.end<Vec3b>();
for (; it != itend; it++)
{
if ((*it)[2] > 150)//对红色分量做阈值处理
{
(*it)[0] = 0;
(*it)[1] = 0;
(*it)[2] = 255;//红色分量保持不变
}
else
{
(*it)[0] = 0;
(*it)[1] = 0;
(*it)[2] = 0;
}
}
imshow("红色分量图 by 阈值法", dstImg);
waitKey(1);
}
// 将整幅图中的红色分量都提取出来
void GetRedComponetBySplit(Mat srcImg)
{
Mat imgROI;
vector<Mat>channels;
split(srcImg, channels);
Mat blueComponet = channels.at(0);
Mat greenComponet