Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Take a look at THIS ANSWER, which explains how the YUV image is stored in memory. You need to use the Mat constructor that takes a pointer to access each component separately, then resize them individually into an appropriately sized buffer.

For a 100 Rows, 100 Cols of RGB, you would have 150 Rows, 100 Cols of YUV422. So to double the size, you need a 300x200 buffer. Example code for a doubling of size is below. Note that I'm not sure which is U and which is V, but since you're just resizing, it doesn't matter.

Mat oldImg;
Mat newImg(300, 200, CV_8UC1);

Mat Y_in(100, 100, CV_8UC1, oldImg.ptr<uchar>(0));
Mat Y_out(200, 200, CV_8UC1, newImg.ptr<uchar>(0));
resize(Y_in, Y_out, Size(200, 200), 0, 0, INTER_LINEAR);

Mat U_in(50, 50, CV_8UC1, oldImg.ptr<uchar>(100));
Mat U_out(100, 100, CV_8UC1, newImg.ptr<uchar>(200));
resize(U_in, U_out, Size(100, 100), 0, 0, INTER_LINEAR);

Mat V_in(50, 50, CV_8UC1, oldImg.ptr<uchar>(125));
Mat V_out(100, 100, CV_8UC1, newImg.ptr<uchar>(250));
resize(V_in, V_out, Size(100, 100), 0, 0, INTER_LINEAR);

You get example code because I had to test it to make sure I wasn't giving you bad advice, and since it's already written...