C++ opencv grayscale image to color image

Grayscale image to color image______ main function: draw colored lines on the image, etc.

//灰度图转彩色图
cv::Mat grayToRGB(const cv::Mat input_img)
{
    
    
	//创建一个和灰度图一样大小的0值图
    cv::Mat three_channel = cv::Mat::zeros(input_img.rows, input_img.cols, CV_8UC3);
    std::vector<cv::Mat> channels;
    //得到3张单通道图
    for (int i = 0; i < 3; i++)
        channels.push_back(input_img);
        
    //RGB通道图的合并
    cv::merge(channels, three_channel);
    return three_channel;
}

simpler

cv::cvtColor(bmp, bmp, cv::COLOR_GRAY2BGR);

Guess you like

Origin blog.csdn.net/qq_41648925/article/details/125480772