Я сделал преобразование изображения из YUV (NV21 Android) в RGB
И я попытался получить цвет пикселя на х, у кординаты
Например, я пытался получить пиксель из центра. Но я получаю цвет из неправильного места.
Собрать изображение YUV
ByteBuffer yBuff = image.getPlanes()[0].getBuffer();
ByteBuffer uBuff = image.getPlanes()[1].getBuffer();
ByteBuffer vBuff = image.getPlanes()[2].getBuffer();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] yByte = new byte[yBuff.remaining()];
byte[] uByte = new byte[uBuff.remaining()];
byte[] vByte = new byte[vBuff.remaining()];
yBuff.get(yByte);
uBuff.get(uByte);
vBuff.get(vByte);
// Create converting byte[] NV21
try {
outputStream.write(yByte);
for (int i=0; i < uByte.length; i++) {
outputStream.write(vByte[i]);
outputStream.write(uByte[i]);
}
} catch (Exception e) {
e.printStackTrace();
}
byte[] imageBytes = outputStream.toByteArray();
Что у меня есть в текущий момент.
// Coordinates
x = width / 2;
y = height / 2;
// Get YUV coordinates for x y position
int YCord = y * width + x;
int UCord = (y >> 1) * (width) + x + total + 1;
int VCord = (y >> 1) * (width) + x + total;
// Get YUV colors
int Y = (0xFF & imageBytes[YCord]) - 16;
int U = (0xFF & imageBytes[UCord]) - 128;
int V = (0xFF & imageBytes[VCord]) - 128;
Я ожидаю, что цвет от центра изображения. Но у меня есть цвет из другого места