Is there any way to convert from RGB to YUYV (YUY 4: 2: 2) format? I noticed that OpenCV has the opposite operation, but not RGB for YUYV for some reason. Maybe someone can point out the code that does this (even outside of the OpenCV library)?
UPDATE
I found a libyuv library that can work for this purpose by making BGR to convert ARGB and then ARGB to YUY2 format (hopefully this is the same as YUYV 4: 2: 2). But it doesn't seem to work. Do you happen to know what the size / type of the yuyv buffer looks like? What is his step?
To clarify YUYV and YUY2, these are the same formats if that helps.
UPDATE 2
Here is my libyuv library usage code:
Mat frame;
cvtColor(im, frame, CVX_BGR2BGRA);
int from_to[] = { 0,3, 1,2, 2,1, 3,0 };
mixChannels(&frame, 1, &frame, 1, from_to, 4);
const uint8_t* argb_data = frame.data;
int argb_stride = 8;
Mat yuyv(frame.rows, frame.cols, CVX_8UC2);
uint8_t* yuyv_data = yuyv.data;
int yuyv_stride = 16;
libyuv::ARGBToYUY2(argb_data, argb_stride, yuyv_data, yuyv_stride,
frame.cols, frame.rows);
UPDATE 3
Mat frame;
cvtColor(im, frame, CVX_BGR2BGRA);
int from_to[] = { 0,3, 1,2, 2,1, 3,0 };
Mat rgba(frame.size(), frame.type());
mixChannels(&frame, 1, &rgba, 1, from_to, 4);
const uint8_t* argb_data = rgba.data;
int argb_stride = rgba.cols*4;
Mat yuyv(rgba.rows, rgba.cols, CVX_8UC2);
uint8_t* yuyv_data = yuyv.data;
int yuyv_stride = width * 2;
int res = libyuv::ARGBToYUY2(argb_data, argb_stride, yuyv_data, yuyv_stride, rgba.cols, rgba.rows);
