Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

First off, check out the OpenCV docs for the Mat class. It shows a bunch of different ways to access, copy, create Mats.

The easiest way would be to use the built-in OpenCV function merge(). Normally, this is used to merge three single channel images into a 3-channel image. For instance, if you split the red, green, and blue channels, process them, and then put them back into a single matrix. But it can actually be used on an arbitrary number of channels, and it accepts a vector of matrices to be merged. So in your for loop, you can push your grayscale image into your vector<Mat>, and then after the loop you can merge() all those matrices into a new matrix.