1 | initial version |
(disclaimer: no matlab here)
opencv uses "interleaved" color channels, like bgr bgr bgr, matlab has seperate color planes, like rrr ggg bbb
you'll have to split the opencv Mat into channels, stack them to a single buffer, and reverse the operation on the way back:
// ocv 2 matlab:
int h = 376;
int w = 672;
int slice_size = 252672; // w*h
Mat m = ...
Mat chan[3];
split(m, chan);
// careful: this assumes, uv0 points to an allocated buffer !
memcpy(uv0, chan[2].ptr<uchar>(), slice_size); // in R G B order for matlab !
memcpy(&[uv0[slice_size], chan[1].ptr<uchar>(), slice_size);
memcpy(&[uv0[slice_size*2], chan[0].ptr<uchar>(), slice_size);
// ... use uv0
// matlab 2 ocv:
emxArray_uint8_T *outImg;
Mat R(h,w,CV_8U, outImg);
Mat G(h,w,CV_8U, outImg+slice_size);
Mat B(h,w,CV_8U, outImg+(2*slice_size));
Mat chan[] {B,G,R}; // BGR order for opencv !
Mat final;
merge(chan, 3, final);