Inspiration

On an excavation, a record photo is the only copy of a scene that the dig itself destroys. Once a find is lifted or a layer is dug away, it cannot be photographed again. Yet the classic mistakes — the ID board still showing the previous context number, no scale or north arrow, a blurred or dark frame, the find cut off at the edge — are usually discovered weeks later, when someone at a desk works through the photo register. Real archive captions read "Wrong feature number written on photoboard" and "North arrow points South.". Trenches rarely have signal, and many projects can't send photos of sites (or of human remains) to a cloud service.

What it does

In Situ is a field camera and photo register for archaeologists, plus a desktop companion (In Situ Desk).

  • Before fieldwork (Desk, cloud): the team adds a few reference photos per find type; Firebase AI Logic in the cloud writes how this site's finds look, the team approves it and sets the project's photo rules (scale / ID board / north arrow required per shot type, numbering prefix, keep human-remains photos on the phone). The result is a guide.json imported on the phone.
  • In the trench (phone, offline): shoot as usual — the camera never waits. Each photo is checked in the background; a strip over the viewfinder appears only when something needs a look, while the scene is still there:
    • ID board vs. register: ML Kit OCR finds and reads the board; when it reads text but can't confirm the context number, Gemini Nano transcribes the text crops (OCR finds where, Nano reads what).
    • Scale: a classical pattern detector with a paint-colour check, then Gemini Nano.
    • North arrow, expected find in view, find cut off: Gemini Nano.
    • Focus, light, direction (compass, true north), shot numbering, duplicates and gaps: on-device rules.
  • Before moving on: one screen per context lists what is still open — warnings, missing pre-/mid-/post-excavation shots, skipped or duplicated numbers — while a retake is still possible.
  • At the desk (browser, local): drop the phone's export (photos + register CSV); nothing is uploaded. Review what needs a look, recheck a photo with Gemini Nano in Chrome, answer each warning, download the reviewed register.

People stay in charge: every warning can be answered ("check is wrong" / "right" / "checked by eye"), shots can be voided while keeping their number, and the export keeps both the machine result and the person's answer.

How we used Firebase AI Logic (hybrid)

The device/cloud split follows the work, not the other way round:

Moment Where Firebase AI Logic
Prepare the site guide Desk, before fieldwork ONLY_IN_CLOUD — the stronger cloud model reads reference photos once
Every shot in the trench Phone Per-site consent, asked once. Off → ONLY_ON_DEVICE: Gemini Nano only, photos never leave the phone; what Nano can't do is marked "not checked on device". On → PREFER_ON_DEVICE: Nano first, cloud only when Nano declines
Review at the desk Chrome PREFER_ON_DEVICE (Chrome's built-in Gemini Nano first) or ONLY_ON_DEVICE, by the same site consent

We measured that the consent switch really changes behaviour: with consent off, 0 cloud calls; with consent on, every photo Nano declined went to the cloud and was answered. App Check protects all calls (debug provider in debug builds, Play Integrity in release, reCAPTCHA Enterprise on the hosted web app).

How we built it

Android: Kotlin, Jetpack Compose, CameraX, ML Kit text recognition (bundled, offline), Firebase AI Logic with the on-device extension (Gemini Nano on a Galaxy S26), App Check. Web: Vite, Firebase JS SDK (AI Logic + App Check), zip.js for multi-gigabyte exports read in place. The scale detector, line-segment detector (an LSD port) and quality rules are plain Kotlin and unit-tested.

Measured, not assumed

We ran the real pipeline over 463 public excavation photos (Open Context, Flickr) on the phone with the cloud off — 205 edge cases, 40 well-taken controls and 218 more to cover thin categories — and kept only changes that moved the numbers. On the same 205 edge-case photos, first build → current build: north arrow found 22 → 49 / 121, ID board read 32 → 56 / 71, scale 84 → 108 / 122, expected find 11 → 35 / 42. Of 40 well-taken photos, 31 pass with no warning at all. We also report what didn't work (a one-shot reference image made Nano answer "yes" to everything; Nano cannot judge "cut off" directly). Full report: docs/ACCURACY.md.

Challenges we ran into

  • Small boards in wide shots: OCR alone read 28 of 43 readable boards; tiling, re-reading enlarged crops, rotated re-reads and finally letting Nano transcribe the crops OCR found closed most of the gap.
  • False alarms are worse than misses in the field: our first board check flagged 31 of 40 correct photos (dates and misread digits looked like other numbers). Rules that only call a conflict when the same field shows another number brought that to 1.
  • Checkered arrow-shaped scales are both a scale and a north arrow; Nano tends to see only the scale.
  • Long on-device runs heat the phone until it stops charging; our measurement runner pauses itself above 45 °C.

Accomplishments we're proud of

A complete loop — prepare, shoot, check, fix before moving on, review, export — that works with no signal and keeps people in control, with accuracy numbers on real archive photos instead of demos.

What we learned

A small on-device model is strongest when it's given a narrow job next to classical tools (OCR, pattern detection, rules) rather than asked everything at once, and when the question names exactly what the object looks like in the field.

What's next

Field trials with an excavation team; Korean and other languages; QR start/end shots to batch-assign DSLR photos; exports for QGIS and ArcGIS (relative-path CSV, record-ID ↔ attachment CSV).

Built during the submission period

Everything was built from 2026-11-18 on; no pre-existing project code. Third-party libraries are listed in the repository; vision/LineSegments.kt ports OpenCV's LSD (Apache-2.0, see NOTICE). Code, tests and measurements were produced with an AI coding agent (Claude Code), directed and reviewed by the author.

Testing instructions (for judges)

  • Code: https://github.com/raphael1063/in-situ (Apache-2.0)
  • Web (no install): open https://dig-photo-check-lrlr.web.app in desktop Chrome. Review tab: drop the sample export in-situ-sample-export.zip from https://github.com/raphael1063/in-situ/releases/tag/v1.0-hackathon (10 archive photos already checked on a Galaxy S26 with the cloud off; nothing is uploaded). Prepare tab: add 2–6 photos of one find type and let the cloud write a site guide.
  • Android: install in-situ-judge.apk from the same Releases page on an Android 8+ phone. Gemini Nano checks need a phone with Nano through AICore (tested: Galaxy S26). On other phones choose Allow cloud when the app asks, and the same checks run in the cloud; Phone only shows what an offline phone without Nano does. Quick test: write "T3 1012" on paper as an ID board, set the context on the camera screen to "T3 1013", photograph it with a ruler → the ID-board warning appears over the viewfinder.

Built With

  • android
  • camerax
  • chrome-built-in-ai
  • firebase-ai-logic
  • firebase-app-check
  • firebase-hosting
  • gemini
  • gemini-nano
  • javascript
  • jetpack-compose
  • kotlin
  • ml-kit
  • vite
Share this project:

Updates

Submission history