File size: 2,765 Bytes
1a003d0
15e840b
 
 
 
1a003d0
 
15e840b
1a003d0
 
 
 
2cc007d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15e840b
2cc007d
 
15e840b
 
 
 
 
 
 
 
 
 
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
---
title: Object Distance Estimator
emoji: πŸ“
colorFrom: purple
colorTo: yellow
sdk: gradio
sdk_version: 6.19.0
python_version: "3.11"
app_file: app.py
pinned: false
---

# Object Distance Estimator

Segment two objects in a photo with a text prompt (SAM3), estimate metric
depth (Depth Anything 3), and compute the real-world distance between the
two objects.

## Usage

1. Upload one image (required) and optionally 1–4 more photos of the same
   scene from different angles β€” extra views improve metric accuracy.
2. List two or more objects, comma-separated, e.g.
   `the red chair, the wooden table, the floor lamp`.
3. (Optional) place a printed ArUco `DICT_4X4_50` marker of known size in the
   scene and enter its side length for automatic scale calibration.
4. Click **Estimate distances**.

The app returns a mask overlay (each object gets a distinct color) and a
pairwise distance matrix between every pair of objects β€” not just one
distance. If a prompt fails to match anything, that object is skipped with a
warning rather than aborting the whole run.

## Accuracy features

- **Blur gate** β€” flags visibly blurry uploads before they reach the models;
  a bad extra view can otherwise quietly degrade DA3's joint depth solve.
- **EXIF-derived intrinsics** β€” if the primary image's EXIF has a 35mm-equivalent
  focal length, the app uses it instead of DA3's network-estimated intrinsics.
- **Automatic scale calibration** β€” an ArUco marker of known size in frame
  lets the app self-calibrate metric scale instead of requiring a manual
  measurement.

## Notes

- `facebook/sam3` is a gated model. Accept the license at
  [huggingface.co/facebook/sam3](https://huggingface.co/facebook/sam3), then
  add an `HF_TOKEN` secret to this Space (Settings β†’ Repository secrets) with
  a token that has access to gated repos.
- Use a GPU Space (T4 or better) β€” both models are slow on CPU.
- Only the metric checkpoints (`da3metric-large`, `DA3NESTED-GIANT-LARGE-1.1`)
  give distances in real meters; the mono/relative checkpoints do not carry
  true scale.
- `requirements.txt` installs `depth_anything_3` directly from its GitHub
  source rather than PyPI. Its PyPI availability has been inconsistent
  (sometimes resolvable, sometimes not, depending on when/where you build) β€”
  installing from the maintainers' repo directly sidesteps that entirely,
  at the cost of a longer build (it compiles from source rather than pulling
  a prebuilt wheel).
- `python_version: "3.11"` is still pinned above. Even installing from
  GitHub, the package's own metadata declares `Requires-Python: <=3.13,>=3.9`,
  and a `3.13.x` patch release can fail that check due to how version
  comparison works (`3.13.14` sorts after `3.13`) β€” keep this pin.