Convert 1 channel image to 3 channels

I am trying to convert a 1-channel image (16 bit) to a 3-channel image in OpenCV 2.3.1. I am having problems using the merge function and get the following error:

    Mat temp, tmp2;
    Mat hud;
    tmp2 = cv_ptr->image;
    tmp2.convertTo(temp, CV_16UC1);
    temp = temp.t();
    cv::flip(temp, temp, 1);
    resize(temp, temp, Size(320, 240));
    merge(temp, 3, hud);

error: there is no corresponding function to call 'merge (cv :: Mat &, int, cv :: Mat &)

Can anyone help me with this? Thanks in advance!

+3
source share
3 answers

If tempthis is a 1-channel matrix that you want to convert to 3 channels, then the following will work:

cv::Mat out;
cv::Mat in[] = {temp, temp, temp};
cv::merge(in, 3, out);

Browse Documenation for more information.

+11
source

, , 3- . 3 , , ( ). . openCV cv:: mixChannels, ,

// copy channel 0 from the first image to all channels of the second image
int from_to[] = { 0,0, 0,1, 0,2}; 
Mat threeChannelImage(singleChannelImage.size(), CV_8UC3);
mixChannels(&singleChannelImage, 1, & threeChannelImage, 1, from_to, 3);
+2

, merge . , . , , Python :

cv.Merge(temp, temp, temp, None, hud)

opencv documentation:

cvMerge: .

+1

All Articles