我有一个图像大小,640 x480
我想使用 yv12 作为输出格式。图像正在由一些 API 处理,我想获得 YV12 格式的输出。
我现在正在尝试的是
整数宽度 = 640;
整数高度 = 480;byte[] byteArray = new byte[Convert.ToInt32((width * height + (2 * ((width * height) / 4))) * 1.5) ];
captureDevice.GetPreviewBufferYCbCr(byteArray)");
int YLength = Convert.ToInt32(width * height * 1.5);
// UVlength multipled by 2 because it is for both u and v
int UVLength = Convert.ToInt32(2 * (width / 2) * (weight / 2)) * 1.5);
var inputYBuffer = byteArray.AsBuffer(0, YLength);
var inputUVBuffer = byteArray.AsBuffer(YLength, UVLength);
var inputBuffers = new IBuffer[] { inputYBuffer, inputUVBuffer };
var inputScanlines = new uint[] { (uint)YLength, (uint)UVLength };
/////Creating input buffer that supports Nv12 format
Bitmap inputBtm = new Bitmap(
outputBufferSize,
ColorMode.Yvu420Sp,
inputScanlines, // 1.5 bytes per pixel in Yuv420Sp mode
inputBuffers);
//As v length is same as u length in output buffer so v length can be used in both place.
int vLength = UVLength / 2;
var outputYBuffer = byteArray.AsBuffer(0, YLength);
var outputVBuffer = byteArray.AsBuffer(YLength, vLength);
var outputUBuffer = byteArray.AsBuffer(YLength + vLength, vLength);
var outputBuffers = new IBuffer[] { outputYBuffer, outputVBuffer, outputUBuffer };
//
var outputScanlines = new uint[] { (uint)YLength, (uint)vLength, (uint)vLength };
Bitmap outputBtm = new Bitmap(
outputBufferSize,
ColorMode.Yuv420P,
outputScanlines,
outputBuffers);**strong text**
所以我想问的是我是否根据 YUV420P 格式正确创建了输出缓冲区。有一个 API,我在其中传递 NV12 中的输入缓冲区,我假设它会给我 YV12(YUV420P)格式的输出缓冲区。所以我创建了 Y 平面,它有width x height x 1.5
字节。1.5 因为 YV12 是一个 12 位的 mat 并且类似地 U 平面具有width/2 x height/2 x 1.5
字节并且类似地 V 平面。我现在不关心 YUV420P 和 YVU420P,只要我的格式正确,我只需要交换 U 和 V 平面。