2020.6.14P54将RGB彩色图像转换为多通道Mat
只需将imread的flags修改一下,就可以将彩色图像转换为三通道的Mat对象,对于彩 色图像的每一个方格,我们可以理解为一个Vec3b。需要注意的是,每一个像素的向量不 是按照R、G、B分量排列的,而是按照B、G、R顺序排列的,
所以通过split函数分离通道 后,先后得到的是B、G、R通道。
//cvp52
#include
#include
using namespace cv;
#include
using namespace std;
int main(int argc, char *argv[])
{
//Mat img = imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE);
Mat img = imread(argv[1], CV_LOAD_IMAGE_COLOR);
if (img.empty())
return -1;
string winname = "txwtech原图";
namedWindow(winname,WINDOW_AUTOSIZE);
imshow(winname,img);
vector planes;
split(img,planes);
imshow("B",planes[0]);
imshow("G",planes[1]);
imshow("R",planes[2]);
waitKey(0);//k要大写的K
//把exe文件与图片文件放在同一个文件夹。即可运行看到效果
//打开cmd.exe
//cd D:\Users\TT2018\source\repos\cvp52\x64\Debug
//D:\Users\TT2018\source\repos\cvp52\x64\Debug>cvp52.exe 111.png
}