gpt4 book ai didi

Android Camera2,我从 ImageReader 获取 YUV 图像。 U 和 V 缓冲区只有一行(跨步)数据,其余为零

转载 作者:行者123 更新时间:2023-11-29 01:18:23 27 4
gpt4 key购买 nike

这就是我实例化 ImageReader 的方式。

Size[] sizes = configs.getOutputSizes(ImageFormat.YUV_420_888);
mImageReader = ImageReader.newInstance(width, height, ImageFormat.YUV_420_888, 2);

mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, null);

Surface rgbCaptureSurface = mImageReader.getSurface();
List<Surface> surfaces = new ArrayList<Surface>();
surfaces.add(rgbCaptureSurface);

//surfaces.add(surface);

mPreviewRequestBuilder
= mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
//mPreviewRequestBuilder.addTarget(surface);

mPreviewRequestBuilder.addTarget(rgbCaptureSurface);

mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {


@Override
public void onConfigured(CameraCaptureSession cameraCaptureSession) {
// The camera is already closed
if (null == mCameraDevice) {
return;
}

// When the session is ready, we start displaying the preview.
mCaptureSession = cameraCaptureSession;
try {
// Auto focus should be continuous for camera preview.
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO);

// Flash is automatically enabled when necessary.
//setAutoFlash(mPreviewRequestBuilder);

// Finally, we start displaying the camera preview.
mPreviewRequest = mPreviewRequestBuilder.build();
mCaptureSession.setRepeatingRequest(mPreviewRequest,
mCaptureCallback, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}

阅读是这样进行的:

  public void onImageAvailable(ImageReader reader) {
Image image;
while (true) {
image = reader.acquireLatestImage();

if (image == null) return;


Image.Plane Y = image.getPlanes()[0];
Image.Plane U = image.getPlanes()[1];
Image.Plane V = image.getPlanes()[2];

int Yb = Y.getBuffer().remaining();
int Ub = U.getBuffer().remaining();
int Vb = V.getBuffer().remaining();

byte[] data = new byte[Yb + Ub + Vb];


Y.getBuffer().get(data, 0, Yb);
U.getBuffer().get(data, Yb, Ub);
V.getBuffer().get(data, Yb + Ub, Vb);

我尝试了几种不同的图像格式。我正在 LG G3、API 21 上进行测试并出现问题。在 Nexus 4 上我没有问题,API 22。

最佳答案

我升级到 API 23,同样的代码运行良好。还在 API 22 上进行了测试,它也有效。

同于:Using Camera2 API with ImageReader

关于Android Camera2,我从 ImageReader 获取 YUV 图像。 U 和 V 缓冲区只有一行(跨步)数据,其余为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38325463/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com