Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Right, other libraries or old code is making it difficult. Not surprising.

So, you need to do three things. First, convert to YUV. That's simple. The output has YUV each as a channel.

To access them individually, you need to split the Mat into separate channels.

Then you merely access the members, and there you are.

To put them back together, you reverse the process. First map the pointers into Mats.

Then merge the Mats into one Mat, and convert back to BGR.

Mat CamFrame;
//Fill CamFrame.

cvtColor(CamFrame, CamFrame, COLOR_BGR2YUV);
//The YUV are each channel of the Mat.  ie: YUVYUVYUV

vector<Mat> YUV; //A vector of Mats, to hold the split channels.
split(CamFrame, YUV);
//YUV is now of size 3, with the first holding just Y values, the second just U, ect.

YUV[0].ptr<uchar>();//Y buffer.
YUV[1].ptr<uchar>();//U buffer.
YUV[2].ptr<uchar>();//V buffer.
YUV[0].step[0]; //Y stride.
//ect...
//sendFrame

//At the other end
vector<Mat> YUV(3);
YUV[0] = Mat(height, width, CV_8UC1, y, ystride); //Y Mat
//ect.

Mat img;//image buffer.
merge(YUV, img);
cvtColor(img, img, COLOR_YUV2BGR);
imshow("Captured Cam", img);
waitKey(0);

.