coin cheung
coin cheung

Reputation: 1107

How could I create an opencv matrix with separate rgb channel data

Suppose I have three char arrays r[1024], g[1024], b[1024] which contains the rgb data of one image. How could I create a cv::Mat with these channel data ?

Upvotes: 1

Views: 477

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207670

Something like this:

// Create three single channel Mats
cv::Mat R(rows,cols,CV_8UC1,&r[0]);
cv::Mat G(rows,cols,CV_8UC1,&g[0]);
cv::Mat B(rows,cols,CV_8UC1,&b[0]);

Then merge into single image:

// Now merge the 3 individual channels into 3-band bad boy
auto channels = std::vector<cv::Mat>{B, G, R};
cv::Mat ThreeBandBoy;
cv::merge(channels, ThreeBandBoy);

Upvotes: 4

Related Questions