[英]formatting buffer according to the YUV420P format
我的圖像尺寸為640 x480
x480,我想使用yv12作為輸出格式。 該圖像正在由某些API處理,我想獲取YV12格式的輸出。
我目前正在嘗試的是
int寬度= 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是mat的12位,並且類似地,U平面具有width/2 x height/2 x 1.5
字節,並且類似地具有V平面。 只要我的格式正確,我現在就不在乎YUV420P和YVU420P,只需要交換U和V平面即可。
YUV 4:2:0平面看起來像這樣:
----------------------
| Y | Cb|Cr |
----------------------
哪里:
Y = width x height pixels (bytes)
Cb = Y / 4 pixels (bytes)
Cr = Y / 4 pixels (bytes)
Total num pixels (bytes) = width * height * 3 / 2
這是像素在4:2:0子采樣中的放置方式:
如您所見,每個色度值在4個亮度像素之間共享。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.