Hackathon submission — live camera pipeline

Genz — traffic-camera event detection & accident anticipation

A two-part solution for the fixed-road-camera challenge: Part A detects and timestamps traffic events (accidents, near-misses, congestion, jaywalking, and more) in a finished video, and Part B watches a video frame-by-frame and outputs a causal, real-time accident-risk score that never looks at the future. Everything ships as a zero-training, zero-GPU, rule-based pipeline that runs on CPU out of the box, with an optional learned-detector upgrade path already wired in.

Rule-based baseline, no training data Runs on CPU Optional YOLO upgrade path 14 challenge classes, 8 implemented automatically
Who built this

Team

Team Genz — three of us, roughly one core pipeline component each.

SA

Sanjar Abduvaitov

Detection & tracking, deployment
src/detector.py, src/tracker.py — motion detector and IoU tracker; also set up the live deployment (genzwiut.com)
KE

Kamola Esheva

Rules engine & road model
src/rules.py, src/road_model.py — per-track and pairwise event rules, self-calibrating road/flow model
SE

Sogdiana Erkabaeva

Risk engine & website/demo
src/risk.py, website/ — causal accident-risk scoring, team site and live demo
What we're solving

Problem & approach

The challenge has two parts, both over the same fixed, non-moving road-camera footage:

Part A -- event detection. Given a finished video, return every interesting event as [start_sec, end_sec, label], where the label is one of 14 fixed classes (accidents, near-misses, wrong-way driving, jaywalking, congestion, and so on). This is scored after the fact, so the whole video is available at once.

Part B -- accident anticipation. Given the same video played frame by frame, output a risk score from 0 to 1 at every frame, before anything bad has necessarily happened -- and it must be causal: at frame t the model may only use frames up to and including t, never later ones. The scoring rewards catching danger a few seconds early.

Part A pipeline (offline, sees the whole video)
Video.mp4 file
→
MotionDetectorMOG2 background subtraction (default)
or optional YOLO
→
IoU Trackergreedy per-frame box matching
→
Road Modelconvex-hull road mask +
dominant flow direction
→
Rules Engineper-track & pairwise heuristics
→
Events list[start, end, label]
Part B pipeline (causal, one frame at a time)
Video framesdelivered one at a time,
in order
→
CausalRiskEngineits own detector + tracker,
rebuilt frame by frame
→
TTC / braking /
pedestrian signalscombined with max(), then
smoothed with EMA
→
Risk score0.0–1.0 per frame
causal — never sees future frames
What's learned vs. what's rules: by default, 100% of this pipeline is hand-written rules on top of classical computer vision (OpenCV MOG2 background subtraction + contour geometry + an IoU tracker). There is no trained model and no learned weights anywhere in the default path. src/detector.py also defines an optional YoloDetector that swaps in automatically if the ultralytics package and a weights/yolov8n.pt file are both present -- a learned-detector upgrade path that's wired but not required to run.

8 classes detected automatically

Each has a concrete, per-camera-agnostic signal derived from track geometry.

  • stopped_vehicle — stationary ≥10s
  • congestion — ≥3 vehicle tracks mostly stationary across the road for ≥8s
  • wrong_way — heading ≥135° opposed to dominant flow
  • near_miss — close approach + high closing speed, then divergence, no overlap
  • accident — bounding-box overlap between two tracks
  • road_obstacle — static "unknown"-class blob on the road for ≥10s
  • jaywalking — person-classified blob inside the road-mask polygon
  • failure_to_yield — vehicle–person bounding-box overlap

6 classes not yet implemented

Documented extension points — each needs per-camera calibration data (a calibration.json) we don't have without real sample footage. They never appear in detect_events output today.

  • red_light — needs a calibrated signal-state ROI
  • stop_line — needs a calibrated stop-line geometry
  • illegal_u_turn — needs no-U-turn zone geometry
  • illegal_turn — needs lane/turn geometry
  • solid_line_crossing — needs lane-marking geometry
  • fire_smoke — a MOG2 motion blob carries no reliable color/texture cue for smoke
Exploratory data analysis

EDA of sample videos

Real analysis from src/eda.py run against 2 of the 4 real camera samples (C3896.MP4, C3897.MP4) -- the other 2 (C3902.MP4, C3905.MP4) weren't re-analyzed before the deadline (they were already verified through the full detection pipeline, see Results/Report; this section specifically covers the lighter EDA pass). Numbers below are computed directly from the video files, not invented.

Resolution / FPS / duration / object counts

VideoResolutionFPSDurationMean vehiclesMean people
C3896.MP43840×216029.97340.3s6.500.96
C3897.MP43840×216029.97317.8s7.401.48

Mean counts are per-frame averages of MotionDetector's blob classifications, sampled every 0.5s across the full video (680 / 635 samples respectively) -- a coarse proxy for traffic volume, not a precise vehicle census.

Vehicle count over time (C3896.MP4)

11 0 0s 340s

Real per-frame vehicle counts from MotionDetector, sampled every 0.5s. The intersection is never empty and swings from roughly 1 to 11 concurrently-tracked vehicles as signal cycles queue and release traffic.

Motion heatmap — C3896.MP4

Motion heatmap of C3896.MP4 showing where detected motion concentrates in the frame

Real heatmap from accumulated detection boxes over the full video -- brighter regions are where vehicles/pedestrians were detected most often (the traffic lanes and crosswalk are clearly visible without any manual annotation).

Motion heatmap — C3897.MP4

Motion heatmap of C3897.MP4 showing where detected motion concentrates in the frame

Same method, second video -- the lane structure and crosswalk again emerge directly from where motion was actually detected, with no manual ROI drawn.

Model output

Results on sample videos

No sample results yet either. This section will show annotated playback, a per-video event timeline, and a per-video risk curve once real files exist under samples/*.mp4 and have been run through run_submission.py. The block below is a synthetic mockup of the intended layout only.
Illustrative mockup — not real output

sample_01.mp4 — event timeline + risk curve (synthetic example)

risk 1.0 risk 0.0
stopped_vehicle congestion accident near_miss — risk score (Part B), synthetic
Try it yourself

Live demo

Runs the real solution.detect_events() from this repo's solution.py against a video you upload, live on this server. This is a genuine model run, not a canned animation.

Limits: .mp4 only, up to 150 seconds (150s) and 200MB. Processing runs in the background, so a longer clip just takes longer to finish rather than timing out. Longer or larger files are rejected with an error rather than silently truncated. This demo currently shows Part A events only — risk-curve visualization: coming soon.

Pick an .mp4 file and click run.
ClassStartEndDuration
This page is served by website/demo_server.py (a small Flask app), publicly hosted at genzwiut.com via cPanel's Python App (Passenger WSGI) on the team's own domain. You can also run it yourself locally — see website/README.md for the two commands. Opening this file directly from disk (rather than via a server) will render the page fine, but the "Run" button will fail to reach a backend, since there isn't one at a bare file:// URL.
Honest self-assessment

Report

What we built

  • A zero-dependency motion detector (OpenCV MOG2 + contour classification) with an optional YOLOv8 swap-in when weights are present.
  • A minimal greedy IoU multi-object tracker with full per-track position history.
  • A self-calibrating road model (convex hull of observed vehicle positions + circular-mean dominant flow direction), usable both offline and causally.
  • A rules engine that turns finished tracks into 8 of the 14 required event classes.
  • A causal risk engine (Part B) combining time-to-collision, hard-braking, and pedestrian-proximity signals with max() + EMA smoothing, calibrated so a 5s time-to-collision maps to a 0.5 score.
  • This website, including a working live-demo server, publicly hosted at genzwiut.com.

What worked

  • The zero-dependency motion detector runs entirely on CPU with no training data and no GPU.
  • The causal risk engine genuinely respects the no-future-frames rule: RiskEstimator.step() only ever sees the current frame and its own running state.
  • run_submission.py / evaluate.py match the challenge's own harness and metric spec (macro F1 across IoU 0.3/0.5/0.7 for Part A; AP + alarm-F1 + mean-time-to-accident for Part B; M = 0.7*ScoreA + 0.3*ScoreB) exactly, so scoring behaves as the organizers intend.

What didn't / limitations

  • No labeled data exists yet, so every threshold (stationary speed, wrong-way angle, near-miss closing speed, etc.) is hand-picked from first principles, not tuned against real ground truth.
  • 6 of 14 classes (red_light, stop_line, illegal_u_turn, illegal_turn, solid_line_crossing, fire_smoke) need per-camera calibration data we don't have and are left as documented extension points rather than guessed.
  • Classifying "vehicle" vs. "person" from blob size/aspect ratio alone is weak and will misclassify unusual shapes; a real detector would help a lot — the YOLO hook is already wired for exactly this upgrade.
  • accident / near_miss detection relies on 2D bounding-box overlap with no depth cue, so a vehicle that merely passes close to the camera's line of sight can look like an overlap and false-positive.

Next steps

  • Get real sample videos into samples/ and generate real EDA and results.
  • Hand-annotate a small dev set and tune thresholds against evaluate.py instead of by hand.
  • Drop in real YOLO weights (weights/yolov8n.pt, see weights/download.sh) for cleaner class labels.
  • Calibrate stop-line / signal-state ROIs / lane geometry per camera to unlock the remaining 6 classes.