2017-03-18 531 views
0

我試圖找到一種方法,方法或算法來將YUV圖像縮小到特定的寬度和高度值而無需將其轉換爲RGB,只需操縱byte[]我的YUV image將YUV字節數組圖像調整爲特定的寬度和高度

我剛剛發現這個另一主題爲Resize (downsize) YUV420sp image

我看到的方式來實現這一目標是刪除像素,但它總是使用4原因色度像素的4個亮度像素之間共享我可以做。 enter image description here

研究我只是實現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; 
    } 

非常感謝你提前!

回答

1

看看libyuv https://chromium.googlesource.com/libyuv/libyuv/

您可能需要編寫JNI封裝和轉換YUV使用包含在項目中的轉換功能,以平面 - https://chromium.googlesource.com/libyuv/libyuv/+/master/include/libyuv/convert.h

+0

謝謝交配,它真的幫了我,現在我正在和圖書館打架。看看我的新問題,看看你是否可以給我一隻手:http://stackoverflow.com/questions/42960251/problems-when-scaling-a-yuv-image-using-libyuv-library –

相關問題