我正在制作曝光融合应用,但我的中兴测试设备上有一个小打嗝。在Pixel模拟器上,我可以从ImageReader中获取一个Image并将其转换为Mat,然后返回到Bitmap以在ImageView中显示。这是代码:
int width = image.getWidth();
int height = image.getHeight();
Image.Plane yPlane = image.getPlanes()[0];
Image.Plane uPlane = image.getPlanes()[1];
Image.Plane vPlane = image.getPlanes()[2];
ByteBuffer yBuffer = yPlane.getBuffer();
ByteBuffer uBuffer = uPlane.getBuffer();
ByteBuffer vBuffer = vPlane.getBuffer();
int ySize = yBuffer.remaining();
int uSize = uBuffer.remaining();
int vSize = vBuffer.remaining();
int uvPixelStride = uPlane.getPixelStride();
Mat yuvMat = new Mat(height + (height / 2), width, CvType.CV_8UC1);
byte[] data = new byte[ySize + uSize + vSize];
yBuffer.get(data, 0, ySize);
uBuffer.get(data, ySize, uSize);
vBuffer.get(data, ySize + uSize, vSize);
if (uvPixelStride == 1) {
yuvMat.put(0, 0, data);
Mat rgb = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC4);
Imgproc.cvtColor(yuvMat, rgb, Imgproc.COLOR_YUV420p2RGBA);
return rgb;
现在,对于中兴通讯来说,U和V平面的像素跨度是2,但我似乎无法正确显示它。
这是我现在正在使用的代码:
Mat yuv = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC1);
yuv.put(0, 0, data);
Mat rgb = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC4);
Imgproc.cvtColor(yuv, rgb, Imgproc.COLOR_YUV2RGBA_NV21);
return rgb;
非常感谢任何帮助。