#include <opencv2\opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
/*************************************************
// Method: convertTo3Channels
// Description: 将单通道图像转为三通道图像
// Returns: cv::Mat
// Parameter: binImg 单通道图像对象
*************************************************/
Mat convertTo3Channels(const Mat &binImg)
{
Mat three_channel = Mat::zeros(binImg.rows,binImg.cols,CV_8UC3);
vector<Mat> channels;
for(int i = 0;i < 3; i ++)
{
channels.push_back(binImg);
}
merge(channels,three_channel);
return three_channel;
}
int main()
{
Mat src;
src = imread("D:/lena.png");
if (src.empty()) {
printf("could not find the picture!");
return-1;
}
//方法1
int height = src.rows;//row表示行,rows表示行的总数,即图像的高
int width = src.cols;//col表示列,cols表示列的总数,即图像的宽
//方法2
cout<<src.size()<<endl;
//获取通道数
int channels = src.channels();
//打印输出
printf("height
OpenCV 获取图像的通道数,实现单通道转3通道
最新推荐文章于 2024-05-13 01:56:09 发布
本文介绍了一种将单通道图像转换为三通道图像的方法,并提供了详细的C++代码实现。该方法通过复制单通道图像三次并合并来创建三通道图像。此外,还展示了如何读取图像、检查图像通道数并显示图像。

最低0.47元/天 解锁文章
1180

被折叠的 条评论
为什么被折叠?



