Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用YUV格式从图像中获取中心像素_Java_Image_Yuv - Fatal编程技术网

Java 使用YUV格式从图像中获取中心像素

Java 使用YUV格式从图像中获取中心像素,java,image,yuv,Java,Image,Yuv,我把图像从YUV(NV21安卓)转换成RGB 我试着用x,y坐标测量像素的颜色。 例如,我尝试从中心获取像素。但我从错误的地方得到颜色 收集图像 ByteBuffer yBuff = image.getPlanes()[0].getBuffer(); ByteBuffer uBuff = image.getPlanes()[1].getBuffer(); ByteBuffer vBuff = image.getPlanes()[2].getBuffer(); ByteArrayOutputStr

我把图像从YUV(NV21安卓)转换成RGB

我试着用x,y坐标测量像素的颜色。 例如,我尝试从中心获取像素。但我从错误的地方得到颜色

收集图像

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();
我希望图像的中心有颜色。但是我有不同地方的颜色

我找到了解决方案,如果有人想要更多,请参阅下面我的代码,链接关于获取像素x,y坐标的代码

x = 210; // might be 250
y = height - 215; // might be 150

// Get YUV coordinates  for x y position
int YCord     = y*width+x;
int UCord     = ((y/2)*width+(x&~1)+total+1);
int VCord     = ((y/2)*width+(x&~1)+total);

在这一行中,
intucord=(y>>1)*(宽度)+x+总计+1
您考虑到y分辨率通过移位减半,但对于
x
您不这样做。我认为您需要使用
x>>1
而不是
x
x = 210; // might be 250
y = height - 215; // might be 150

// Get YUV coordinates  for x y position
int YCord     = y*width+x;
int UCord     = ((y/2)*width+(x&~1)+total+1);
int VCord     = ((y/2)*width+(x&~1)+total);