File size: 3,179 Bytes
166c438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Scene calibration configurations

## Files and source keys

| Configuration | Source keys | Master source |
| --- | --- | --- |
| `WS1_2.json` | video1-video6 | video4 |
| `WS3.json` | video1-video3 | video2 |
| `WS4_5.json` | video1-video4 | video1 |
| `WS6_7.json` | video1-video3 | video2 |

Use the scene JSON and the `--source videoN` value associated with the raw CSV in `configs/source_manifest.csv`. Pixel centers and bounding-box corners must use the same image coordinate view as the control points. Source-image coordinates are mapped into the scene's master-image frame before metric conversion.

## Configuration fields

| Field | Meaning and units |
| --- | --- |
| `template_only` | `false` for the supplied actual scene configurations |
| `scene_id` | Observation-group identifier |
| `master_source` | Source key defining the master-image coordinate frame |
| `origin_px` | Two-element `[x,y]` origin in master-image pixels |
| `rotation_rad` | Zero for the supplied road-aligned workflow |
| `reference_segments` | Measured segments expressed in master-image pixels and meters |
| `reference_segments[].point_a`, `point_b` | Two-element pixel endpoints in the master image |
| `reference_segments[].real_distance_m` | Positive measured length in meters |
| `sources.videoN.src_points` | Nx2 source-image fitting control points, in pixels |
| `sources.videoN.master_points` | Matched Nx2 master-image fitting control points, in pixels |

The master source has an empty source entry because its image frame is already the master frame. Non-master fitting arrays must have equal lengths, at least four point pairs and noncollinear finite coordinates.

## Transformation

For each measured reference segment, calculate its real length divided by its pixel length. The metric scale is the arithmetic mean of these ratios, in meters per pixel.

For a non-master source, `coordinate_transform.py` estimates the source-to-master homography from the matched fitting points using RANSAC with a 3-pixel threshold and RNG seed 0. For a master source, the source-to-master transform is the identity. After mapping a pixel point to master coordinates `(u,v)`, the output is:

```text

x = (u - origin_px[0]) * scale

y = (origin_px[1] - v) * scale

```

Image coordinates follow the pixel convention, with y increasing downwards. Metric x follows the aligned road axis and metric y increases upwards. Both output coordinates are in meters. Vehicle centers and all four bounding-box corners use this same transformation.

## Usage

```bash

python coordinate_transform.py --input data/raw/WS3_raw_detection_data_2.csv --calibration calibrations/WS3.json --source video2 --output runs/ws3_video2_metric.csv

python estimate_vehicle_length.py --input data/raw/WS3_raw_detection_data_2.csv --calibration calibrations/WS3.json --source video2 --output runs/ws3_video2_lengths.csv

```

Malformed endpoints, nonpositive reference distances, unmatched point arrays, degenerate homographies and points on a homography horizon produce explicit errors. The supplied scene JSONs provide the fitting values used by the processing commands.