简体   繁体   English

将YUV字节数组图像调整为特定的宽度和高度

[英]Resize YUV byte array image to a specific width and height

I'm trying to find a method, way or kind of algorithm to downsize YUV images to an specific width and height values without converting it into RGB, just manipulating the byte[] of my YUV image . 我正在尝试找到一种方法,方法或某种算法,可以将YUV图像缩小到特定的宽度和高度值,而无需将其转换为RGB,而只需操纵YUV imagebyte[]

I just found another topics about this as Resize (downsize) YUV420sp image 我刚刚发现了另一个与此相关的主题,如调整大小(缩小)YUV420sp图像

I see that the way to achieve this is removing pixels, but I can just do it always using a factor of 4 because chroma pixels are shared between 4 luma pixels. 我看到实现此目的的方法是删除像素,但是我总是可以使用4倍来完成此操作,因为色度像素在4个亮度像素之间共享。

在此处输入图片说明

After researching I just achieve the next method, which rescale a YUV image four times smaller than the original image, but want I want to achieve is freely convert from a Width x Height resolution to a smaller one that I want, not a factor of 4. It is possible to achieve this in some way? 经过研究,我只是实现了下一个方法,该方法将YUV image重新缩放为原始图像的四倍,但是我想要实现的是将Width x Height resolution自由转换为我想要的较小Width x Height resolution ,而不是4倍有可能以某种方式实现这一目标吗? I don't have problems in use Renderscript or any kind of libraries. 使用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;
    }

Take a look at libyuv https://chromium.googlesource.com/libyuv/libyuv/ 看看libyuv https://chromium.googlesource.com/libyuv/libyuv/

You may need to write a jni wrapper and convert the yuv to planar using the convert functions included in the project - https://chromium.googlesource.com/libyuv/libyuv/+/master/include/libyuv/convert.h 您可能需要编写JNI封装和转换YUV使用包含在项目中的转换功能,以平面- https://chromium.googlesource.com/libyuv/libyuv/+/master/include/libyuv/convert.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM