我試圖找到一種方法,方法或算法來將YUV圖像縮小到特定的寬度和高度值而無需將其轉換爲RGB,只需操縱byte[]
我的YUV image
。將YUV字節數組圖像調整爲特定的寬度和高度
我剛剛發現這個另一主題爲Resize (downsize) YUV420sp image
我看到的方式來實現這一目標是刪除像素,但它總是使用4原因色度像素的4個亮度像素之間共享我可以做。
研究我只是實現next方法,重新調整比原始圖像小的YUV image
四次,但要我要實現的是自由地從一個Width x Height resolution
轉換到一個較小的一個之後,我想,不是一個因素4.有可能以某種方式實現這一點?我在使用Renderscript
或任何種類的libraries
時都沒有問題。
/**
* Rescale a YUV image four times smaller than the original image for faster processing.
*
* @param data Byte array of the original YUV image
* @param imageWidth Width in px of the original YUV image
* @param imageHeight Height in px of the original YUV image
* @return Byte array containing the downscaled YUV image
*/
public static byte[] quadYuv420(byte[] data, int imageWidth, int imageHeight) {
Log.v(TAG, "[quadYuv420] receiving image with " + imageWidth + "x" + imageHeight);
long startingTime = System.currentTimeMillis();
byte[] yuv = new byte[imageWidth/8 * imageHeight/8 * 3/2];
// process Y component
int i = 0;
for (int y = 0; y < imageHeight; y += 8) {
for (int x = 0; x < imageWidth; x += 8) {
yuv[i] = data[y * imageWidth + x];
i++;
}
}
// process U and V color components
for (int y = 0; y < imageHeight/2; y += 8) {
for (int x = 0; x < imageWidth; x += 16) {
if (i < yuv.length) {
yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + x];
i++;
yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + (x + 1)];
i++;
}
}
}
Log.v(TAG, "[quadYuv420] Rescaled YUV420 in " + (System.currentTimeMillis() - startingTime) + "ms");
return yuv;
}
非常感謝你提前!
謝謝交配,它真的幫了我,現在我正在和圖書館打架。看看我的新問題,看看你是否可以給我一隻手:http://stackoverflow.com/questions/42960251/problems-when-scaling-a-yuv-image-using-libyuv-library –