Build an iPhone Sensing App Part 1: Four Sensors in One Handheld
The GEMINI project collects plant measurements across hundreds of plots every season. A drone covers the whole field, but a lot of the ground truth has to be taken by hand: canopy temperature, plant height, leaf orientation, and the weather at the moment of capture.
For a while that meant carrying a thermal camera, a laser distance meter, a handheld weather station, and a notebook. Each device wrote its own file with its own clock, and matching them afterwards in a spreadsheet was slow and error-prone.
I built an iPhone app that records all of these in one capture. This series has four parts.
The idea
An iPhone already contains a 12 MP camera, a LiDAR depth sensor, GPS, an IMU, and Bluetooth. The missing piece was a thermal camera, which the FLIR ONE Pro adds through the Lightning port.
The weather station was built as a separate device first. Its Bluetooth link to the app came later, in the weather station series.
A thermal image alone shows leaf temperature. Aligned with the RGB frame, the canopy depth, and the air temperature at the same second, it can be used in a model.
What one capture produces
Pressing the shutter writes five files. They share a timestamp and a sequential index, so a capture is never ambiguous:
| File | Sensor ID | Content |
|---|---|---|
YYMMDD_IMG_XXXXX.jpg |
401 | RGB still from the iPhone camera |
YYMMDD_IMG_XXXXX_flir.jpg |
402 | Thermal frame from the FLIR ONE |
YYMMDD_IMG_XXXXX.json |
403 | GPS, attitude, air temperature, humidity, settings |
YYMMDD_IMG_XXXXX_depth.tiff |
404 | Depth map (32-bit float) |
YYMMDD_IMG_XXXXX_confidence.tiff |
405 | Per-pixel depth confidence |
The JSON sidecar describes each capture. It follows the same collections.json schema the drone and rover pipelines already used:
{
"collection_device_id": 104,
"sensor_id": 401,
"date_collected": "2023-09-26",
"file_name": "230926_IMG_00142.jpg"
}
| Field | Value | Meaning |
|---|---|---|
collection_device_id |
103 |
drone |
104 |
rover / handheld | |
sensor_id |
401 |
rgb_jpg |
402 |
flir_jpg | |
403 |
meta_json | |
404 |
depth_tiff | |
405 |
confidence_tiff |
Using the existing IDs meant the iPhone data could be dropped into the same processing scripts without a special case.
Depth
The LiDAR depth map is coarse, but in bench tests at 0.3 to 1 m above the canopy it was good enough to separate leaves from soil and to estimate canopy height per frame. Field data were collected from a rover at about 1.5 m and from a drone at 5 m and 10 m.
To check alignment I wrote a small desktop viewer that opens a capture and draws four panels: RGB, depth, confidence, and the RGB again with the measured distance printed on it.
The viewer also showed a problem. In the third panel the confidence drops to near zero over bare soil in full sun, and the depth values there are wrong by tens of centimetres. For this reason the app always stores confidence with depth, and the analysis masks low-confidence pixels.
Metadata
Every capture carries the phone’s GPS fix, compass heading, pitch and roll, and the weather station reading. The FLIR image also gets its own EXIF block, so the thermal file is not dependent on the sidecar JSON if it ever gets separated.
exiftool on a thermal image after adding GPS tagging. Latitude, longitude, altitude, and image direction are written into the FLIR XMP block, so the thermal file stays georeferenced on its own.Writing GPS into the FLIR metadata was not automatic. The FLIR SDK exposes a gpsInfo object on the image, and the app fills it from Core Location before saving:
guard let location = self.location else { return }
var gpsInfo = image.getGpsInformation()
gpsInfo.latitudeRef = location.coordinate.latitude >= 0 ? "N" : "S"
gpsInfo.longitudeRef = location.coordinate.longitude >= 0 ? "E" : "W"
gpsInfo.latitude = Float(location.coordinate.latitude)
gpsInfo.longitude = Float(location.coordinate.longitude)
gpsInfo.altitude = Float(location.altitude)
gpsInfo.gpsMapDatum = "WGS84"
gpsInfo.timeStamp = NSDate()
image.setGpsInformation(gpsInfo)
What this version could not do
The first working version used ARKit for everything. It gave RGB and depth in the same frame with the camera pose attached, which the depth reconstruction needed.
It also capped the RGB image at 1920×1440. Compared with the same phone’s native camera app, the 2023 flight images were lower in resolution, and some were soft in a way sharpening did not fix. Part 2 covers these problems.
References
- GEMINI Project, UC Davis: projectgemini.ucdavis.edu
- Apple Developer: Capturing depth using the LiDAR camera
- Apple Developer: Setting Up a Capture Session
- Teledyne FLIR: FLIR Atlas Mobile SDK downloads and documentation
- ExifTool: exiftool.org (used to verify FLIR GPS tags)