【OpenCV】将单通道的Mat对象转换为三通道的Mat

http://blog.csdn.net/wx7788250/article/details/70261615

/*************************************************
//  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;
}

 

posted @ 2017-12-13 13:53  Henry2017  阅读(10269)  评论(0编辑  收藏  举报