【问题标题】:How to get color saturation or brightness from YUV420SP format in Eclipse如何在 Eclipse 中从 YUV420SP 格式获取颜色饱和度或亮度
【发布时间】:2014-01-18 14:30:54
【问题描述】:

我必须制作一个简单的应用程序,该应用程序会从 Android 上的相机预览中弄乱饱和度、亮度等。我的代码现在正在将图像发送到数据中:

public void onPreviewFrame(byte[] data, Camera camera){

}

...如果我没记错的话,它是 YUV420SP 格式。我试图找到有关此的一些信息,但没有成功。谁能告诉我如何管理这种格式?

【问题讨论】:

    标签: android eclipse camera preview yuv


    【解决方案1】:

    见安卓文档:http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setPreviewFormat(int);图像格式在此处描述:http://www.fourcc.org/yuv.php#NV21

    简而言之,这个byte[] 包含两部分:亮度和色度。您可以使用 camera 对象来查找当前参数(不要在每次调用 onPreviewFrame() 时在生产代码中使用它,因为这些调用是性能负担,但重用这些值):

    int w = camera.getParameters().getPreviewSize().width;
    int h = camera.getParameters().getPreviewSize().height;
    
    byte[] luma = new byte[w*h];
    byte[] chroma = new byte[w*h/2];
    System.arraycopy(data, 0, luma, 0, w*h);
    System.arraycopy(data, w*h, chroma, 0, w*h/2);
    
    int Y_at_x_y = luma[x + y*w];           // or data[x + y*w]
    int U_at_x_y = chroma[x/2 + y*w/2 + 1]; // or data[w*h + x/2 + y*w/2 + 1]
    int V_at_x_y = chroma[x/2 + y*w/2];     // or data[w*h + x/2 + y*w/2]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-01
      • 2020-10-29
      • 1970-01-01
      • 1970-01-01
      • 2014-07-05
      • 2023-03-25
      • 2011-05-17
      相关资源
      最近更新 更多