简体   繁体   中英

ARCore – How to know if a device has a Time-of-Flight sensor?

I wonder what is the code to know if a device has a ToF sensor.

Thanks

There is no api provided by the android platform for ToF sensors as only very few devices are operational with this feature.

You can check this question. Only huawei is providing support using the AR Engine SDK.

From what I understand, ARCore enables to provide us the depth of each point from the camera using nothing but matching learning But they do mention in some places that devices that have some kind of depth sensor may be used during their calculation but I'm not sure if there is a way to check if a device does have a sensor using their API. If you want ARCore to ignore any sensor and use only their algorithm you can configure the camera like that:

// Create a camera config filter for the session.
val filter = CameraConfigFilter(session)

// Return only camera configs that will not use the depth sensor.
filter.depthSensorUsage = EnumSet.of(CameraConfig.DepthSensorUsage.DO_NOT_USE)

Since a depth data in ARCore can be calculated from motion and then might be merged with data from a hardware iToF sensor, devices running Android AR apps do not need a time-of-flight camera to support the Full Depth API or Raw Depth API. So at the moment there's no property in ARCore 1.29 to check if device has a hardware depth sensor. N.netheless, @NivSaparov offered some solution.

However, to check whether a device supports Depth mode or not use the following code in Java:

Config config = session.getConfig();

if (session.isDepthModeSupported(Config.DepthMode.AUTOMATIC)) {
    config.setDepthMode(Config.DepthMode.AUTOMATIC);
}
session.configure(config);

...or in Kotlin:

if (session.isDepthModeSupported(Config.DepthMode.AUTOMATIC)) {
    session.configure(session.config.apply { 
        depthMode = Config.DepthMode.AUTOMATIC 
    })
}

By default, depth feature is disabled on ARCore, to save resources. Not every ARCore-compatible device supports the Depth API due to its high processing requirements.

But it's possible to indirectly determine whether a given device has an iToF sensor (but it's not 100% sure). For that, check if devices can support the Raw Depth API.

session = new Session(this);

if (!session.isDepthModeSupported(Config.DepthMode.RAW_DEPTH_ONLY)) {
    message = "Current device doesn't support Raw Depth API.";
}

My logic is simple: if the device supports the Raw Depth API, then as a rule such a device has an iToF sensor.

If your AR app requires Depth API support, just add the following line to your AndroidManifest.xml:

<uses-feature android:name="com.google.ar.core.depth" />

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