Skip to main content

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.11+.
  • 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,
)

For long videos, pass return_df=False to only write iou_file (rows are streamed to disk batch by batch, and an interrupted run resumes from /path/to/dets.txt.part on the next call).

2) Tracking

from dnt.track import ByteTrackConfig, Tracker

config = ByteTrackConfig()
tracker = Tracker(config=config, device="auto")
tracks = tracker.track(
    det_file="/path/to/dets.txt",
    out_file="/path/to/tracks.txt",
    video_file="/path/to/video.mp4",
)

Tuning trackers. Every tuning field defaults to None, meaning BoxMOT's own default. Set only what you want to change, e.g. ByteTrackConfig(track_thresh=0.5). Settings that a tracker ignores raise ValueError. See BoxMOT's documentation for parameter meanings: https://github.com/mikel-brostrom/boxmot

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.

Metadata

Release files for dnt 0.3.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dnt 0.3.4.2
File Size Uploaded Provenance Actions
dnt-0.3.4.2.tar.gz 52.1 MB Without provenance Details for dnt-0.3.4.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dnt 0.3.4.2
File Interpreter ABI Platform Actions
dnt-0.3.4.2-py3-none-any.whl Python 3 none any Details for dnt-0.3.4.2-py3-none-any.whl

Total release size: 104.2 MB

Release files / dnt-0.3.4.2.tar.gz

Download URL dnt-0.3.4.2.tar.gz
Size 52.1 MB
Tags Source
SHA-256 checksum
How to use checksums
4f7b354d05335c5dcc53dc7e3ca75b1b5b09859a2e95d77df9e1ac50c27de868
BLAKE2b-256 checksum
How to use checksums
527b0461bedd4fb55715bd3ad94037c7e2880943561de90b7b23654384d78fc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / dnt-0.3.4.2-py3-none-any.whl

Download URL dnt-0.3.4.2-py3-none-any.whl
Size 52.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
1507957ee032169fb3a42807794f78e6a31c60773f317e0f38955693844ee2a7
BLAKE2b-256 checksum
How to use checksums
a8d72881088c53686efb5a11a3f29544029d9097d4c4496722383c1316cb6b81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for dnt 0.3.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page