1

使用下面的代码片段无法为具有固定焦距的预览创建 CaptureRequest。即使来自 TotalCaptureRequest 的报告另有说明,预览中显示的图像始终聚焦在无穷远处。

这是代码片段:

mPreviewBuilder = mCameraDevice.createCaptureRequest(SCameraDevice.TEMPLATE_PREVIEW);
mPreviewBuilder.set(SCaptureRequest.LENS_FOCUS_DISTANCE, 9.5f);
mPreviewBuilder.set(SCaptureRequest.CONTROL_AF_MODE, SCaptureRequest.CONTROL_AF_MODE_OFF);

我的设备是三星 Galaxy S7,它报告后置摄像头的以下属性:[code]CamId:0 LensFace:BACK HwdSupportLevel:FULL SensorOrientation:90 LensCalibration:CALIBRATED LensMinFocusDist:10.0[/code]

这是我在onCaptureComplete()

 callback: AF_STATE: 0 Lens Focus Distance: 9.555555 LENS_STATE: 0 HAS FOCUS RANGE: true Focus Range Min: 9.762765, Max: 9.348346

我已经尝试过使用普通的 Android Camera2 API 以及三星 SDK(在这里找到:http: //developer.samsung.com/galaxy/camera

三星自己的相机应用程序以及 Camera FV-5 支持此功能没有任何问题。

我怎样才能让它工作?

为上下文添加更多代码

/**
 * Start the camera preview.
 */
private void startPreview() {
    if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) {
        return;
    }
    try {
        closePreviewSession();
        SurfaceTexture texture = mTextureView.getSurfaceTexture();
        assert texture != null;
        texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
        mPreviewBuilder = mCameraDevice.createCaptureRequest(SCameraDevice.TEMPLATE_PREVIEW);
        //mPreviewBuilder.set(SCaptureRequest.CONTROL_CAPTURE_INTENT, SCaptureRequest.CONTROL_CAPTURE_INTENT_MANUAL);
        //mPreviewBuilder.set(SCaptureRequest.CONTROL_MODE, SCaptureRequest.CONTROL_MODE_OFF);
        mPreviewBuilder.set(SCaptureRequest.CONTROL_AF_MODE, SCaptureRequest.CONTROL_AF_MODE_OFF);
        mPreviewBuilder.set(SCaptureRequest.CONTROL_AE_MODE, SCaptureRequest.CONTROL_AE_MODE_ON);
        mPreviewBuilder.set(SCaptureRequest.LENS_FOCUS_DISTANCE, 9.5f);

        Surface previewSurface = new Surface(texture);
        mPreviewBuilder.addTarget(previewSurface);

        mCameraDevice.createCaptureSession(Arrays.asList(previewSurface), new SCameraCaptureSession.StateCallback() {

            @Override
            public void onConfigured(SCameraCaptureSession cameraCaptureSession) {
                mPreviewSession = cameraCaptureSession;
                updatePreview();
            }

            @Override
            public void onConfigureFailed(SCameraCaptureSession cameraCaptureSession) {
                Toast.makeText(getApplicationContext(),"Failed", Toast.LENGTH_SHORT).show();
            }
        }, mBackgroundHandler);


    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}


/**
 * Update the camera preview. {@link #startPreview()} needs to be called in advance.
 */
private void updatePreview() {
    if (null == mCameraDevice) {
        return;
    }
    try {
        setUpCaptureRequestBuilder(mPreviewBuilder);
        HandlerThread thread = new HandlerThread("CameraPreview");
        thread.start();
        mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), mCaptureCallBack, mBackgroundHandler);
        Log.i(TAG, "New Session values, control mode " + mPreviewBuilder.get(SCaptureRequest.CONTROL_MODE) +
                ", AF mode: " + mPreviewBuilder.get(SCaptureRequest.CONTROL_AF_MODE) +
                ", Focus value; " + +mPreviewBuilder.get(SCaptureRequest.LENS_FOCUS_DISTANCE));
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
4

1 回答 1

0

您是否在 mPreviewBuilder 中添加了表面?

 Surface surface = new Surface(texture);
 //Add surfaces
 mPreviewBuilder.addTarget(surface);
 surfaces.add(surface);

其次,在设置 LENS_FOCUS_DISTANCE 之前将 AF_MODE 设置为关闭,最后在 CaptureSesion 上使用 setRepeatingRequest 更新您的会话。有了它,它必须工作。

 mCaptureSession.setRepeatingRequest(mPreviewBuilder.build(),
                callback, mHandler);

使用 Log 检查 CaptureRequest 的值,以检查一切是否正确,并且您没有在 AF 上重叠某些内容:

 Log.i(TAG, "New Session values, control mode " + mPreviewRequestBuilder.get(CaptureRequest.CONTROL_MODE) +
            ", AF mode: " + mPreviewRequestBuilder.get(CaptureRequest.CONTROL_AF_MODE) +
            ", Focus value; " + +mPreviewRequestBuilder.get(CaptureRequest.LENS_FOCUS_DISTANCE));
于 2016-09-20T08:46:57.350 回答