Ask Your Question

Revision history [back]

Combining multiple cv::Mat images into single cv::Mat

I am working with the new C++ - style interface. I thought I could use the following trick to create an image based on 3 existing images, but the window stays clear of information. Anyone has an idea what I am doing wrong?

split(input_color,color_channels);
blue_channel = color_channels[0];
green_channel = color_channels[1];
red_channel = color_channels[2];

Above code show splitting into color channels which I want to represent next to eachother.

int rows = input_color.rows;
int cols = input_color.cols;

Mat result_channel(rows, cols * 3, CV_8UC1);
result_channel( Rect(0, 0, cols, rows) ) = blue_channel;
result_channel( Rect(cols, 0, cols, rows) ) = green_channel;
result_channel( Rect(cols*2, 0, cols, rows) ) = red_channel;

imshow("color channels", result_channel); cvWaitKey(10);

By using the roi parameter I wanted to assign the color channels to a region in the larger image. Result however is a blank window. Anyone has an idea what is happening?