Geolocation as External Prior for Area Targets¶
This article describes how to use GPS (Global Positioning System) coordinates as External Prior to relocalize large Area Targets.
Applications with Area Targets for scanned areas that are very large require injected External Priors to initialize tracking. In some other scenarios, the Device Tracking over longer distances may get lost, or localization purely based on visual information proves difficult, using the External Priors with geolocation may be the solution.
To get started, please see Area Targets for obtaining your own scan to create an Area Target from and see also the Area Target API Overview -- External Prior for an introduction to the concept of injecting an external position for better environment detection and tracking.
Geopositioning on Mobile Platforms¶
Originally, GPS-localization has been designed for outdoor, large-scale, use cases and relies on a clear signal between your device and multiple satellites orbiting Earth. Today's "GPS"-receivers use additional Global Navigation Satellite Systems (GNSS) such as GLONASS, BeiDou, Galileo and others -- which all are limited from similar line-of-sight and other radio-problems like the original GPS system. The accuracy of geopositioning significantly drops or is even in some cases impossible in indoor environments due to such issues.
To overcome this, all mobile platform providers have implemented hybrid or fused mobile positioning systems that rely in addition to GNSS on Network Location Provider (NLP) positioning using cellular antennas, Wifi-signals, as well as magnetometer, and other sensors. Such a fused geolocation provides accurate, smooth, ubiquitous, and instant geopositioning for mobile devices.
The device location can be determined by a platform API that consolidates information based on the different sources and provides a fused location in the World Geodetic System -- in its latest revision, the WGS 84 geographic coordinate system. The location consists of latitude, longitude, and elevation -- alongside with other information, such as timestamps and accuracy information.
Area Targets and Geolocation¶
Vuforia Engine pose-information and Area Targets use a Cartesian reference frame with coordinates in meters (Further information on Vuforia's system coordinates is available on the Spatial Frame of Reference page).
A location prior (external position) from a device geolocation must therefore take the same reference frame before being injected. To compute this transformation, you need to know the geolocation and orientation of the Area Target's origin.
You will need to align the target in the WGS 84 coordinate system -- commonly called georeference. Once this reference has been established, the device pose provided during tracking in the Area Target's coordinate system, and asset- or augmentation locations in WGS 84 can be transformed between the two coordinate systems freely back and forth.
NOTE: In this description and sub-sequent pages we may sometimes refer to the location in the geographic coordinate system WGS 84 simply as "geolocation".
Overall Workflow¶
The general workflow consists of three stages:
- Georeference the Area Target: Obtain the location of your Area Target's origin and its rotation angle with respect to the WGS 84 geographic coordinate system. We describe two different options to achieve this:
- Align the Area Target in the Unity Editor with a satellite image of the surrounding area to retrieve geolocation and orientation of the origin.
- Measure a few points with a custom app, logging both Vuforia Area Target poses and GPS readings on-site. Use the provided Python script to compute the offset of the Area Target origin.
- Use device geolocation as prior: To kickstart Area Target tracking or aid localization using an external prior, convert during app-runtime the measured GPS-device-location to Area Target Cartesian coordinates. Inject these as an external prior to your Area Target. Do this every time a new GPS position is available.
- Render georeferenced assets: Optionally, display georeferenced information, such as IoT-sensor data, BIM-created assets, or labels in your augmentation, by transforming their geolocation into the Area Target's Cartesian coordinate system.
Three alternative paths to georeference your Area Target prior to application development is described on the Georeferencing Area Target page. The result of your alignment yields the latitude and longitude of the Area Target's origin, and its orientation with respect to Earth's North Pole. This information will be needed in the next sections below.
NOTE: This guide only shows how to inject the latitude and longitude as external prior.
Use Device Geolocation as Prior¶
Use the results of the georeferenced Area Target as prior at runtime. To do so, we show:
- How the fused geolocation can be obtained in Unity,
- Which transformations need to be applied.
- What it takes to inject the geolocation as a prior.
Get Device Geolocation in Unity
Read the geolocation of a mobile device using the Unity Input.location
API to receive global coordinates for cross-platform apps. Refer to Unity - Scripting API: LocationService for more details.
The location service can be started with:
To query the last reported geolocation, use:
The below script shows the handling of this API checking and continuous coordinate updates, provided that the user has allowed the location service to run. Attach the below GPSLocationProvider
script to a new GameObject to obtain the device's geolocation as a debug output. To conserve battery, you can indicate the accuracy requirements and the update-rate when the OS provides updated geolocation information. Based on these settings the most optimal sources and operational mode is chosen by the OS.
GPSLocationProvider.cs | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
NOTE: You will need to specifically ask for runtime permission for the location services to be used. See Unity's Request User Permission API for more details.
Convert Geolocation GPS-Coordinates to Cartesian Coordinates¶
It is necessary to convert the geolocation obtained in the previous section to cartesian (XY) coordinates relative to the local reference frame of the Area Target.
To perform this step, it is necessary to know the following information:
- The fused geolocation (Latitude, Longitude) of the origin of the Area Target,
- The orientation angle of one of its main axes with regard to the local geographic North direction.
This data can be obtained by following the Georeferencing Area Target guide. To store the origin values, create a script named GeoLocation.cs
.
Use then the following GPSLocationMapper.cs
script with the geographic reference of the Area Target's origin to convert the output values from the user position that is provided at runtime by the GPSLocationProvider.cs
script and convert those to cartesian coordinates. Add the GPSLocationMapper.cs
to an empty GameObject and attach the necessary objects and parameters to its component in the Inspector.
Once the cartesian (XY) coordinates of a GPS location have been determined in the local reference frame of the Area Target 3D space, it is injected into the SetExternal2DPosition
method of the Vuforia Area Targets API:
The above script needs an additional utility script to convert from geographic to cartesian coordinates.
NOTE: For higher accuracy, use System.Math
for calculations involving double-precision (64 bit) floating point numbers, as opposed to using UnityEngine.Mathf
which operates on single-precision (32bit) floating point numbers.