【发布时间】:2019-05-12 12:33:52
【问题描述】:
我在每个onDrawFrame() 上都收到byte[] 中的YUV420 图像数据。我需要从给定的字节数组中找出图像中存在的颜色。如何提取每个像素的 U 和 V 值并使用它们来确定该图像中是否存在特定颜色(类似于 HSV 颜色范围)。
我已将 UV 阵列与原始图像数据分开,如下所示:
byte[] data = image.getData();
int inputYLength = image.getWidth() * image.getHeight();
int inputUVLength = image.getWidth() * image.getHeight() / 2;
ByteBuffer uvBuffer = ByteBuffer.allocateDirect(inputUVLength);
uvBuffer.put(image.getData(), inputYLength, inputUVLength);
uvBuffer.position(0);
uvBuffer 保存 U 和 V 分量的字节值。如何使用它进行颜色检测?
【问题讨论】:
-
我的回答解决了你的问题吗?如果是这样,请考虑接受它作为您的答案 - 通过单击计票旁边的空心对勾/复选标记。如果没有,请说出什么不起作用,以便我或其他人可以进一步帮助您。谢谢。 meta.stackexchange.com/questions/5234/…
-
图像的大小约为 700x500,
uvBuffer的长度在 100000 以上。因此,在每个onDrawFrame()上采样这么多数据根本不可行,而且提到的公式还需要一些其他计算也。我正在尝试YuvImage和OpenCV
标签: android image-processing yuv hsv color-detection