1 | initial version |
opencv has a reshape method, that will flatten your image quite cheap(no memory is moved, it's just rearranging the header)
Mat m = ...
Mat m_flat = m.reshape(1,1); // flat 1d
// also note, that it *returns* a new Mat header (common pitfall, folks tend to forget to catch it)
if you really need to seperate the channels, it gets more expensive:
vector<Mat> chans;
split(m, chans);
Mat res; // stack the channels into a new mat:
for (size_t i=0; i<chans.size(); i++)
res.push_back(chans[i]);
res = res.reshape(1,1); // flat 1d, again.