简体   繁体   中英

Is it possible (if yes, how) to access a MIUI phone's depth camera directly?

I know that my phone and other models have a depth camera. I have used Portrait mode and extracted the depth information from the image using Desktop tools. I have attempted to use Unity's WebCamTexture.depthCameraName to do this on the device, but to no avail. Is this possible, or is the depth camera reserved for the camera app on MIUI?

Certainly, there might be the possibility to make the user take a photograph in the camera app and import it, but my application would benefit greatly from being able to read out this data in real time. I would appreciate any pointers on what to research, thank you in advance.

I would just like to add that if this is doable in Unity, that would be my preferred solution. However, if it has to be, I can make do with any other XR solution for android (position info will be relevant to the project)

As I know, there is a way to get depth image on Android studio. With camera2 API, you can use CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_DEPTH_OUTPUT to find depthcamera's CameraId and use it.

such as:

private String DepthCameraID() {
    try {
        for (String camera : cameraManager.getCameraIdList()) {
            CameraCharacteristics chars = cameraManager.getCameraCharacteristics(camera);
            final int[] capabilities = chars.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);
            boolean facingFront = chars.get(CameraCharacteristics.LENS_FACING) == CameraMetadata.LENS_FACING_BACK;
            boolean depthCapable = false;
            for (int capability : capabilities) {
                boolean capable = capability == CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_DEPTH_OUTPUT;
                depthCapable = depthCapable || capable;
            }
            if (depthCapable && facingFront) {
                SizeF sensorSize = chars.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE);
                Log.i(TAG, "Sensor size: " + sensorSize);
                float[] focalLengths = chars.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS);
                if (focalLengths.length > 0) {
                    float focalLength = focalLengths[0];
                    double fov = 2 * Math.atan(sensorSize.getWidth() / (2 * focalLength));
                    Log.i(TAG, "Calculated FoV: " + fov);
                }
                return camera;
            }
        }
    } catch (CameraAccessException e) {
        Log.e(TAG, "Could not initialize Camera Cache");
        e.printStackTrace();
    }
    return null;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM