Metadata-Version: 2.4
Name: dnt
Version: 0.3.2.3
Summary: A Python tool for video-based traffic analytiscs
Author-email: Zhenyu Wang <wonstran@hotmail.com>
Project-URL: Homepage, https://github.com/wonstran/dnt
Keywords: traffic,vehicle,trajectory,safety
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: torch
Requires-Dist: torchvision
Requires-Dist: torchaudio
Requires-Dist: ultralytics>=8.4.1
Requires-Dist: boxmot
Requires-Dist: cython
Requires-Dist: cython_bbox
Requires-Dist: easydict
Requires-Dist: easyocr
Requires-Dist: faiss-cpu
Requires-Dist: faiss-gpu-cu12
Requires-Dist: filterpy
Requires-Dist: gdown
Requires-Dist: geopandas
Requires-Dist: h5py
Requires-Dist: lapx
Requires-Dist: loguru
Requires-Dist: matplotlib>=3.9
Requires-Dist: motmetrics
Requires-Dist: ninja
Requires-Dist: numpy<3,>=2.2
Requires-Dist: numpy_indexed
Requires-Dist: opencv-contrib-python
Requires-Dist: opencv-python
Requires-Dist: pandas>=2.2
Requires-Dist: Pillow
Requires-Dist: prettytable
Requires-Dist: pycocotools
Requires-Dist: pyyaml
Requires-Dist: requests
Requires-Dist: scikit-image
Requires-Dist: scikit-learn>=1.5
Requires-Dist: scipy>=1.13
Requires-Dist: shapely
Requires-Dist: shapelysmooth
Requires-Dist: sympy
Requires-Dist: tabulate
Requires-Dist: tensorboard
Requires-Dist: termcolor
Requires-Dist: thop
Requires-Dist: tqdm
Requires-Dist: vidgear
Requires-Dist: yacs
Requires-Dist: dateparser
Requires-Dist: openpyxl
Requires-Dist: pytz
Dynamic: license-file

# 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

```bash
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

```python
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

```python
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)

```python
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)

```python
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

```python
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](mailto:wonstran@hotmail.com))

## License

MIT License. See `LICENSE.md`.
