U-EASWS / Processing_Code /docs /CALIBRATION.md
InterestingITS's picture
Upload 26 files
61c47a0 verified
|
Raw History Blame Contribute Delete
3.18 kB
# 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.