Skip to content
ProfessorSabrePublic

About

Spatial Context and Observation Utility Tool

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

SCOUT — Spatial Context & Observation Utility Tool

This is the main branch: validated against this project's actual NVIDIA workstation + Jetson Orin Nano deployment target. If you're running different GPU hardware (AMD or Apple Silicon), the gpu-agnostic branch auto-detects and supports those instead of assuming NVIDIA.

SCOUT is a computer-vision site-observation system built by the SPACE Lab (Spatial Prediction & Adaptive Contexts Engine), Purdue University Department of Horticulture and Landscape Architecture. It uses fixed, oblique-angle cameras to detect, track, and geolocate pedestrians and micro-mobility users (bicycles, scooters, skateboards, golf carts) in the built environment, producing timestamped, real-world-coordinate movement data for empirical site analysis, GIS, and design-simulation research.

SCOUT is an observation tool, not a simulator. It answers "what actually happened at this site" from real video, as ground truth for downstream analysis (dwell time, route choice, occupancy) or for validating a separate simulation against reality. It does not generate predictions, run simulations, or infer behavior it didn't observe.

What it does

  1. Detect & track (run_inference.py) — the stock COCO-trained YOLOv11m model (downloaded automatically on first use) detects people, bicycles, skateboards, motorcycles and vehicles in video, and Ultralytics' built-in TrackTrack tracker keeps a persistent ID per object within one camera's view. A detection needs 0.35 confidence to start a track, but weaker detections (down to 0.10) may extend an existing one, so a person partly hidden for a few frames isn't split into separate tracks; a lost track is held for 5 s at any frame rate, and the tracker won't start a new track on top of one it already has. The project's own fine-tuned model (weights/best.pt, which also has scooter and golf-cart classes) can be used instead with --weights weights/best.pt; other trackers with --tracker-type. Optionally extracts up to 20 appearance fingerprints per person track (numeric vectors from the clearest views across the track; no image of anyone is ever written to disk). A camera that drifts (a propped phone, a pole in wind) can be aligned, frame by frame, to the still image it was calibrated on (frame_alignment.py).
  2. Calibrate & georeference (homography_middleware.py, scout_calibration.html) — a least-squares homography fit over 6+ real-world reference points converts pixel coordinates to real-world meters and GPS coordinates, reporting each point's leave-one-out error in meters so a bad click is visible. The browser-based calibration tool (scout_calibration.html) is a single self-contained HTML file — no backend, no install — for clicking video-frame (or still-image) points against a choice of aerial imagery. Detections above the ground plane's horizon get no coordinates rather than impossible ones.
  3. Fuse the site (mcmt_fusion.py) — works with one camera or many. Resolves one identity per person across the site: by ground position where camera views overlap, and by appearance plus physical plausibility (nobody moves faster than 15 m/s) elsewhere, solved as a batch assignment problem rather than greedy matching. The appearance threshold is calibrated by every run from pairs of people it knows are different, per hour of footage. Also attributes travel mode (on foot, or riding a bicycle/scooter/skateboard/motorcycle, from co-movement), keeps vehicles as anonymous positions, and counts what's present over time. Every run writes a coverage map and a manifest of its settings.

Repository layout

run_inference.py           Detection + tracking, per-camera CSV + embedding output
homography_middleware.py   Pixel -> real-world coordinate calibration and transform
mcmt_fusion.py              Site fusion: identities, travel modes, vehicles, counts
coverage_map.py            Coverage map (written by every fusion run; also runs standalone)
frame_alignment.py         Camera-motion compensation: picks each camera's reference still, aligns frames to it
clock_sync.py              Time offset between two overlapping cameras, from the people both see
scout_calibration.html     Standalone browser calibration tool (open directly, no server)
train_master_model.py      YOLOv11 training script
reid/                      Person re-identification (embedding model + cross-camera gallery)
weights/                   The project's fine-tuned detection model (best.pt); the default model downloads itself
calibrations/              Per-site calibration registry (includes a real worked example)
datasets/PBED/             Training dataset config (images sourced separately, see its README)
frame_extraction_tools/    Video-to-frames utilities for building/expanding training data
tests/                     Synthetic checks for every stage (python tests/run_all.py)

Getting started

See SETUP.md for environment setup (Python version, PyTorch/CUDA install, dependencies) and a quick smoke test.

Typical workflow, once set up (the same steps for one camera or many):

# 0. (Cameras that may drift) pick each camera's reference still -- the image to calibrate on --
#    and name it as "reference_frame" in that camera's camera_map.json entry
python frame_alignment.py reference --video path/to/cam1.mp4 --output calibrations/reference_frames/your_site/cam1.png

# 1. Detect and track people/objects in each camera's video, extracting appearance fingerprints
python run_inference.py --source path/to/videos/ --camera-map camera_map.json --extract-embeddings --output-dir out/

# 2. Calibrate each camera once (scout_calibration.html -> calibrate-from-points), then apply it
python homography_middleware.py calibrate-from-points --points-json calibration_points.json
python homography_middleware.py transform --tracking-csv out/<camera_id>_tracking.csv --site-id your_site --output out/<camera_id>_movement.csv

# (A recording without a trustworthy start time) find its clock offset against an overlapping camera,
# then set that camera's start_timestamp in camera_map.json
python clock_sync.py --reference-csv out/cam1_movement.csv --csv out/cam2_movement.csv

# 3. Fuse the site
python mcmt_fusion.py --tracking-csvs out/*_movement.csv --embeddings out/*_embeddings.npz --site-id your_site --output-dir out/

Step 3 writes, into --output-dir: full_site_composite.csv (one row per person per half second; the file GIS/Grasshopper/Blender should read), full_site_vehicles.csv, counts_over_time.csv, coverage_map.png, run_manifest.json, and one <camera_id>_fused.csv per camera (the audit layer). Each stage's output feeds the next; see the comments at the top of each script for the full detail on what it reads/writes and why.

Design notes worth knowing before you deploy

  • Real-world coordinates, not pixels. Cross-camera matching and any distance/speed reasoning always happens in real-world meters (post-calibration), never raw pixels or raw lat/long degrees — a degree of longitude isn't a constant real-world distance.
  • Person-only identity. Re-identification is scoped to the person class. Bicycles, vehicles, etc. are kept as anonymous positions over time (a vehicle seen by two overlapping cameras at once is kept once) plus counts per interval, never an identity, and no image content such as license plates is retained. A person's travel mode is attributed to the person: within 2 m of a bicycle/scooter/skateboard and moving with it at matching speed and direction means riding it. There are no speed categories.
  • Zero-PII by construction. Appearance fingerprints are numeric vectors computed in memory; no frame or crop of a person is written to disk.
  • Overlap is where hand-off is reliable. Where camera views overlap, people are handed between cameras by ground position (same spot within 1.5 m for 2+ s), which depends on calibration accuracy, not appearance. Across gaps between views, identity rests on appearance and should be expected to fragment.
  • Stock detector, chosen tracker. On four-camera test footage the general-purpose YOLOv11m gave longer, cleaner tracks than the project's fine-tuned model (which had learned to see people in tree canopy and missed bicycles ridden head-on), and TrackTrack, compared against five other trackers, gave the fewest new IDs for the same person and no identity swaps at crossings. Both cost more processing time than smaller or simpler choices; accuracy of identity comes first.
  • One identity, one place. If merging ever leaves one Global_ID in two cameras at the same moment more than 5 m apart, the track with the lower match confidence loses the identity (with the tracks stitched to it) and gets its own -- unless the higher-confidence track couldn't have been reached from where the identity was last seen, in which case that one loses it.
  • Brief losses are stitched; IDs stay individual. When the tracker loses a person for a moment (a branch, a post, a sun/shade boundary) and gives them a new track ID, the fusion stage joins the two if the new track starts within 1 s where the earlier one was heading (a constant-velocity prediction), one-to-one. In full_site_composite.csv, gaps of up to 1 s within an identity are filled by straight-line interpolation and marked Interpolated=True; per-camera files are never filled. Every Global_ID is one individual -- group behavior is left to analysis of the paths.
  • Confidence is a first-class output. Every appearance match carries a similarity/confidence score in the output CSV, not just a bare identity assignment.
  • Reproducible runs. The appearance threshold is calibrated per run (per hour of footage) from pairs of people known to be different; run_manifest.json records every setting, input and calibrated threshold.
  • Calibrate on a still, align to it. A calibration maps one image's pixels to the ground. With a reference_frame set, every half second of video is matched to that still on static scene features and detections are converted into its pixels (the as-seen point is kept in Raw_Foot_X/Y); stretches that can't be aligned get no position rather than a guessed one. Nothing is cropped, unlike video stabilization.
  • One clock per site. Each camera's start_timestamp places it on a shared session clock. Where recordings have lost their capture time (messaging apps strip it), clock_sync.py recovers the offset from overlap and reports whether the result is reliable; a video joined from several recordings can be given one start time per segments entry, and tracks are split at each join.
  • Camera/site IDs are permanent. Every physical camera gets a site_id + camera_id assigned once and never reused after a physical move — recalibrate under a new camera_id instead. This is the join key between a camera's saved calibration and every tracking run against it, ever.

Known limitations

  • Cross-camera fusion has been tested on two real multi-camera recordings made with phones (three cameras at one site, four at another). Position-based hand-off worked between well-calibrated overlapping cameras; appearance did not reliably distinguish the same person seen from a second camera from a stranger, so identity across gaps between views is not yet reliable. Neither recording had walkers of known identity, so accuracy has not been measured against ground truth.
  • Inside a group whose members keep hiding one another from a single viewpoint, identities can swap when the group separates; group paths and counts are largely unaffected, individual dwell and route measures are where groups split.
  • People less than 60 px tall aren't matched on appearance (there isn't enough pixel information for any embedding model); they're kept and counted in every output, unflagged, but each track gets its own identity.
  • Travel mode needs both the rider and the vehicle detected. The current detector finds bicycles seen side-on well but often misses them ridden straight toward or away from the camera (on one test, a rider's bicycle was detected in 17-49% of the frames where the rider was), so travel mode undercounts riding until the detector is retrained with more head-on and tail-on examples.
  • The wheelchair detection class is known to be weak (confirmed hallucinations and confusion with bicycles) and is being rebuilt from better training data. Until then mcmt_fusion.py leaves it out of travel mode, the vehicles file and the counts (DEFERRED_CLASSES); raw detections stay in the per-camera fused CSVs.
  • No edge-deployment (Jetson-class hardware, live camera feeds, network publishing) code exists yet — this repo is the core detection/tracking/calibration/fusion pipeline, run as batch processing over recorded video.

License

GPL-3.0 — see LICENSE.

About

Spatial Context and Observation Utility Tool

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages