I want to convert a YUV stream into RGB bytes such that they can be displayed through a WPF Image.
All YUV values are placed in their respective arrays per frame y, u, v. chroma width and height are half of the respective luma dimensions.
byte[] y = (byte[])yData;
byte[] u = (byte[])uData;
byte[] v = (byte[])vData;
var ym = new Mat(new[] { lumaHeight, lumaWidth }, MatType.CV_8UC1, y, new long[] { lumaStride });
var um = new Mat(new[] { chromaWidth, chromaHeight }, MatType.CV_8UC1, u, new long[] { chromaStride});
var vm = new Mat(new[] { chromaWidth, chromaHeight }, MatType.CV_8UC1, v, new long[] { chromaStride});
I use the following code to pass the data to openCV:
var combinedSource = new[] { ym, um, vm };
var m = new Mat();
var src = InputArray.Create(combinedSource);
var @out = OutputArray.Create(m);
Cv2.CvtColor(src, @out, ColorConversionCodes.YUV2BGR);
ImageData = @out.GetMat().ToBytes();
But I receive the error: {"!_src.empty()"}
The yuv arrays are definitely not empty.
I try another method using:
var combinedOut = new Mat(new[] { lumaHeight, lumaWidth }, MatType.CV_8UC3);
Cv2.Merge(combinedSource, combinedOut);
var bgra = combinedOut.CvtColor(ColorConversionCodes.YUV2BGR);
ImageData = bgra.ToBytes();
But receive the error {"mv[i].size == mv[0].size && mv[i].depth() == depth"}
Why do I receive these errors and what is the correct way to convert?