Camera2 API焦点不适用于Google Pixel



我有一个带有TAP的Android应用程序以焦点功能。它在我尝试过的所有手机(Nexus 5X,Samsung Galaxy S7,Asus Zenfone 3 Deluxe)上都很好地工作。

这是用户点击屏幕时我正在使用的代码:

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();
    }
}

对像素上发生的事情有什么想法?

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);

您是否还将af_mode放在自动上,然后在后续重复请求中将af_rigions和af_rigions放到{rettangle}?

如果它们仅设置为触发请求上的自动,则您可能会立即重置自动对焦,以返回连续_picture/no区域或设置的重复请求。

因此,请确保已将af_mode设置为自动和af_rigions to {Rectangle}以进行重复请求,尽管不设置AF_TRIGGER以比一个capture()调用。

最新更新