【问题标题】:How to specific area to get YUV value如何获取特定区域的 YUV 值
【发布时间】:2014-11-13 02:53:02
【问题描述】:

我为显示图像流形式的相机创建了表面视图,并且我有用于检测特定区域的矩形。我只需要在矩形中获取 Y 值我该怎么做。我发现代码表单网站代码将 YUV 更改为 RGB,但我通过仅返回 Y 值来调整它。 请告诉我如何在特定区域仅获取矩形中的 Y 值。

我尝试改变 i , j , width ,height。是收藏吗? 举个例子吧。

我是新的安卓程序员。 谢谢

public void decodeYUV420(int[] rgb, byte[] yuv420, int width, int height) {
    final int frameSize = width * height;

for (int j = 0, yp = 0; j < height; j++) {
    int uvp = frameSize + (j >> 1) * width, u = 0, v = 0;
    for (int i = 0; i < width; i++, yp++) {
        int y = (0xff & ((int) yuv420[yp])) - 16;
        if (y < 0) y = 0;
        if ((i & 1) == 0) {
            v = (0xff & yuv420[uvp++]) - 128;
            u = (0xff & yuv420[uvp++]) - 128;
        }

        int y1192 = 1192 * y;
        int r = (y1192 + 1634 * v);
        int g = (y1192 - 833 * v - 400 * u);
        int b = (y1192 + 2066 * u);

        if (r < 0) r = 0; else if (r > 262143) r = 262143;
        if (g < 0) g = 0; else if (g > 262143) g = 262143;
        if (b < 0) b = 0; else if (b > 262143) b = 262143;

        //rgb[yp] = 0xff000000 | ((r << 6) & 0xff0000) | ((g >> 2)
            //    & 0xff00) | ((b >> 10) & 0xff);

          rgb[yp] = y;     // i need only y value
    }
}
}

【问题讨论】:

    标签: android image-processing camera yuv rect


    【解决方案1】:

    类似这样的:

    public int[] extractY(byte[] yuv420, Size szYuv, Rect rcY) 
    {
        rcY.intersect(0, 0, szYuv.width, szYuv.height);
        final int[] res = int[rcY.width()*rcY.height()];
    
        int yCount = 0;
        for (int row=rcY.left; row<rcY.right; row++)
        {
            for (int col=rcY.top; col<rcY.bottom; col++) 
            {
                res[yCount++] = yuv420[col+rcY.left+(row+rcY.top)*szYuv.width];
            }
        }
        return res;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-10
      • 2011-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-04
      • 1970-01-01
      相关资源
      最近更新 更多