Skip to main content

A Python tool for video-based traffic analytiscs

Project description

DNT: Dedection and Tracking

Python package for video-based traffic analysis: detection, tracking, labeling, and post-processing. Surrogate safety measures (SSMs) can be generated using the Traffic Surrogate Safety Analysis (TSSA) package.

Features

  • Object detection (dnt.detect.Detector, YOLO/RT-DETR backend).
  • Multi-object tracking (dnt.track.Tracker, BoxMOT backend).
  • Video labeling/visualization (dnt.label.Labeler).
  • Track post-processing:
    • RTS interpolation for trajectory gaps.
    • Tracklet linking (stitching broken IDs).

Requirements

  • OS: Ubuntu 20.04+ (or compatible Linux).
  • Python: 3.9+.
  • CUDA GPU recommended for detection/tracking speed.

Install dependencies from:

  • requirements.txt
  • pyproject.toml

Installation

python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -r requirements.txt
pip install dnt

API Manual

https://wonstran.github.io/dnt/

Quick Workflow

1) Detection

from dnt.detect import Detector

detector = Detector(device="auto")
dets = detector.detect(
    input_video="/path/to/video.mp4",
    iou_file="/path/to/dets.txt",
    verbose=True,
)

2) Tracking

from dnt.track import ByteTrackConfig, Tracker

cfg = ByteTrackConfig()
tracker = Tracker(cfg=cfg, device="auto")
tracks = tracker.track(
    input_video="/path/to/video.mp4",
    det_file="/path/to/dets.txt",
    output_file="/path/to/tracks.txt",
)

3) RTS interpolation (post-process)

from dnt.track.post_process import interpolate_tracks_rts

tracks_interp = interpolate_tracks_rts(
    track_file="/path/to/tracks.txt",
    output_file="/path/to/tracks_interp.txt",
    max_gap=30,        # max consecutive missing frames to fill
    interp_col="interp",
    verbose=True,
)

Notes:

  • interp == 1 means interpolated frame.
  • Real detections are treated as interp != 1 (supports legacy interp=-1 files).
  • Output file is written in track-file format (no CSV header), compatible with Labeler.draw_tracks.

4) Tracklet linking (ID stitching)

from dnt.track.post_process import link_tracklets

tracks_linked = link_tracklets(
    track_file="/path/to/tracks_interp.txt",
    output_file="/path/to/tracks_linked.txt",
    max_gap=20,        # candidate end-start frame gap
    verbose=True,
)

link_tracklets uses:

  • hard gates (time/class/size/motion/IoU),
  • cost matrix scoring,
  • global 1-to-1 assignment (Hungarian),
  • union-find chain merge and ID remap.

5) Labeling

from dnt.label import Labeler

labeler = Labeler()
labeler.draw_tracks(
    input_video="/path/to/video.mp4",
    output_video="/path/to/output_labeled.mp4",
    track_file="/path/to/tracks_linked.txt",
    verbose=True,
)

Modules

  • dnt.detect
  • dnt.track
  • dnt.label
  • dnt.track.post_process

Author

Zhenyu Wang (wonstran@hotmail.com)

License

MIT License. See LICENSE.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dnt-0.3.2.3.tar.gz (63.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dnt-0.3.2.3-py3-none-any.whl (70.2 kB view details)

Uploaded Python 3

File details

Details for the file dnt-0.3.2.3.tar.gz.

File metadata

  • Download URL: dnt-0.3.2.3.tar.gz
  • Upload date:
  • Size: 63.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for dnt-0.3.2.3.tar.gz
Algorithm Hash digest
SHA256 f12cf84e90b8a9a571b711b326c706673c71ad4667a172bd1296ec20e12d037c
MD5 a3a136622ed25a4741edf05a4f113518
BLAKE2b-256 5cf544d5a694904d024addb3274f3c65685199a5634114f1b7c926135dda3809

See more details on using hashes here.

File details

Details for the file dnt-0.3.2.3-py3-none-any.whl.

File metadata

  • Download URL: dnt-0.3.2.3-py3-none-any.whl
  • Upload date:
  • Size: 70.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for dnt-0.3.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a12e3875a0f2d45832278f128f68726d2bbdbe7b81d9af6e8c6f6ab3a336b5f4
MD5 e4cfdb9d1d4812230dce221f06102207
BLAKE2b-256 5e7f822798aca5c455962f3b7eab5db7ee607564d8b4bcc7d0377e455e08593b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page