本文介绍了Camera2设置预览(查看)并获取预览回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Camera2获取预览,还希望从byte []回调中获取用于处理帧的信息

I want to get preview from Camera2 and also byte[] callback for processing frames

mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),
        ImageFormat.RAW_SENSOR,1);
mImageReader.setOnImageAvailableListener(
        mOnImageAvailableListener, mBackgroundHandler);

.

SurfaceTexture texture = mTextureView.getSurfaceTexture();
assert texture != null;

// We configure the size of default buffer to be the size of camera preview we want.
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());

// This is the output Surface we need to start preview.
Surface surface = new Surface(texture);

// We set up a CaptureRequest.Builder with the output Surface.
mPreviewRequestBuilder
        = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
mPreviewRequestBuilder.addTarget(surface);
// also for preview callbacks
mPreviewRequestBuilder.addTarget(mImageReader.getSurface());

但是当我添加第二个目标(ImageReader的表面)fps时,它的糟糕表现是10-15,而不是30

But when I add second target (ImageReader's surface) fps get very bad 10-15 instead of 30

使用Legacy Camera API可以正常工作

With Legacy Camera API it was working ok

byte []个帧回调

mCamera.setPreviewCallback(this);

@Override
public void onPreviewFrame(byte[] data, Camera camera) {

}

预览

mCamera.setPreviewDisplay(mSurfaceView.getSurfaceHolder());

使用旧版Camera API不会影响FPS质量

It didn't effect FPS quality with legacy Camera API

那么如何用Camera2获得相同的结果?

So how to get they same result with Camera2?

推荐答案

您正在请求全分辨率RAW帧;不能保证以30fps的速度提供这些内容(因为它们往往很大).您可以通过 StreamConfigurationMap 查询.

You're requesting full-resolution RAW frames; those aren't guaranteed to be available at 30fps (because they tend to be large). You can check their max frame rate via StreamConfigurationMap queries.

如果要匹配旧的API行为,则要设置ImageReader分辨率以匹配预览分辨率,并将格式设置为YUV_420_888.
在高端设备上,您可以使用YUV_420_888将分辨率设置为最大,甚至可以使用RAW输出,但这将是特定于设备的(查找支持 BURST_CAPTURE 功能)

If you want to match the old API behavior, you want to set the ImageReader resolution to match your preview resolution, and the format to YUV_420_888.
On higher-end devices, you can probably set the resolution to maximum with YUV_420_888, or even use RAW output, but that's going to be device specific (look for devices that support the BURST_CAPTURE capability)

这篇关于Camera2设置预览(查看)并获取预览回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 17:41