[英]Resize YUV byte array image to a specific width and height
我正在尝试找到一种方法,方法或某种算法,可以将YUV图像缩小到特定的宽度和高度值,而无需将其转换为RGB,而只需操纵YUV image
的byte[]
。
我刚刚发现了另一个与此相关的主题,如调整大小(缩小)YUV420sp图像
我看到实现此目的的方法是删除像素,但是我总是可以使用4倍来完成此操作,因为色度像素在4个亮度像素之间共享。
经过研究,我只是实现了下一个方法,该方法将YUV image
重新缩放为原始图像的四倍,但是我想要实现的是将Width x Height resolution
自由转换为我想要的较小Width x Height resolution
,而不是4倍有可能以某种方式实现这一目标吗? 使用Renderscript或任何类型的库我都没有问题。
/**
* 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;
}
看看libyuv https://chromium.googlesource.com/libyuv/libyuv/
您可能需要编写JNI封装和转换YUV使用包含在项目中的转换功能,以平面- https://chromium.googlesource.com/libyuv/libyuv/+/master/include/libyuv/convert.h
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.