Camera2 API 在 Google Pixel 上无法对焦

3

我有一个具备触摸对焦功能的安卓应用。在我尝试过的所有手机上(Nexus 5X,三星Galaxy S7,华硕ZenFone 3 Deluxe)都能正常工作,除了Google Pixel。

下面是用户点击屏幕时我使用的代码:

public void focusAt(Point point) {

    try {
        // compute metering rectangle from the focus point
        // see here: https://github.com/PkmX/lcamera/blob/master/src/pkmx/lcamera/MainActivity.scala (from line 759)
        int meteringRectangleSize = 300;
        int left = activeArraySize.left;
        int right = activeArraySize.right;
        int top = activeArraySize.top;
        int bottom = activeArraySize.bottom;

        float x = (float)point.x / mPreviewSize.getWidth();
        float y = (float)point.y / mPreviewSize.getHeight();

        MeteringRectangle rectangle = new MeteringRectangle(
                Math.max(0, Math.round(left + (right - left) * y - meteringRectangleSize / 2)),
                Math.max(0, Math.round(bottom - (bottom - top) * x - meteringRectangleSize / 2)),
                meteringRectangleSize,
                meteringRectangleSize,
                1
        );

        // create a new capture request
        mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);

        // set the Auto focus mode to auto and set the region computed earlier
        mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
        mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);
        mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[]{rectangle});

        // add the preview surface as a target and start the request
        mPreviewBuilder.addTarget(previewSurface);
        mPreviewSession.capture(mPreviewBuilder.build(), null, mBackgroundHandler);

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

你知道Pixel上正在发生什么吗?

EDI:我是这样获取activeArraySize的:

CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
String cameraId = manager.getCameraIdList()[0];
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
activeArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);

不确定您是否已解决此问题,但问题可能是您的测量权重过低。测量权重为0-1000(https://developer.android.com/reference/android/hardware/camera2/params/MeteringRectangle),数字越高,权重越大。 - wblaschko
1个回答

1
请问您在后续的重复请求中,AF_MODE和AF_REGIONS是否仍然保持在自动模式和矩形区域?如果它们只在触发请求时设置为自动模式,那么可能会立即将自动对焦重新设置为连续拍照/无区域或任何其他重复请求所设置的内容。因此,请确保您已将AF_MODE设置为AUTO并将AF_REGIONS设置为{rectangle},但不要在多次capture()调用中将AF_TRIGGER设置为START。

谢谢您的回答,但是您提到的我的后续重复请求是什么意思? - Tim Autin
在这段代码片段中,您提交一个单独的捕获请求来触发触摸对焦。那么您如何在此之外运行预览呢? - Eddy Talvala

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接