简体   繁体   中英

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 ?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM