This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MetDetPy is a Python-based meteor detection system that detects meteors from videos and images. It uses frame-differencing and Hough line detection (M3Detector) or deep learning models (MLDetector/DLDet) as the primary detection method, with optional YOLO-based recheck for classification and false-positive reduction.
# Video detection
python MetDetPy.py video.mp4
python MetDetPy.py video.mp4 --cfg config/m3det_normal.json --save-path results.json
# Image detection
python MetDetPhoto.py ./images --save-path results.json
# Clip/stack toolkit (post-processing)
python ClipToolkit.py results.json --mode video --save-path ./output
# Unit tests
python -m pytest tests/ -v
# Evaluation (requires annotation file and test video in test/)
python evaluate.py test/20220413Red.mp4 test/20220413_annotation.json
# Package as executable (requires nuitka)
python make_package.pypip install -r requirements.txtKey deps: numpy, opencv-python, tqdm, onnxruntime, av (PyAV), dacite, pyexiv2, rawpy.
The detection pipeline flows linearly:
VideoFile → VideoLoader → Detector → Collector → Exporter → MDRF JSON
-
VideoLoader (
videoloader.py): Decodes video, applies masks, resizes, estimates exposure time, merges frames. Variants:VanillaVideoLoader(sync),ThreadVideoLoader(threaded). Uses a VideoWrapper (videowrapper.py) abstraction over OpenCV or PyAV backends. -
Detector (
Detector.py): Detects candidate meteor responses within a sliding time window. Hierarchy:BaseDetector(ABC)LineDetector→ClassicDetector,M3Detector(frame-differencing + Hough lines, grayscale)MLDetector(YOLO-based detection, requires color frames)BrightnessDetector(whole-frame brightness events)
-
Collector (
collector.py): Two classes —MeteorCollectoraggregates per-frame "responses" into motion sequences (MeteorSeries), applies motion-based filtering (speed, duration, direction), and immediately exports timed-out sequences toMetExporter.MetExporterruns in a background thread, performs optional YOLO recheck per target, manages apending_confirmedbuffer, and assembles temporally-close confirmed targets into clip-levelSingleMDRecordoutput. The Collector→Exporter protocol carries(flag, data, cur_frame, nearest_active_start)to enable frame-time-based flush decisions without real-time timeouts. -
Model (
model.py): ONNX Runtime inference wrapper for YOLO models. Handles multi-scale prediction, NMS, and provider selection (CPU/CUDA/DirectML/CoreML).
- metstruct (
metstruct.py): All dataclass definitions — config structs (MainDetectCfg,BinaryCfg,ModelCfg, etc.), runtime params, and the output format (MDRF,SingleMDRecord). Usesdacitefor JSON→dataclass deserialization. - metlog (
metlog.py): Async logging system with backend/frontend modes. - metvisu (
metvisu.py): OpenCV-based visualization for debug mode. - utils (
utils.py): Constants (VERSION), path resolution, math helpers, sliding window, EMA, coordinate transforms. - stacker (
stacker.py): Frame stacking algorithms (max, MFNR, denoise). - imgproc (
imgproc.py): Image transform pipeline.
| File | Purpose |
|---|---|
MetDetPy.py |
Video meteor detection (main tool) |
MetDetPhoto.py |
Image/photo meteor detection |
ClipToolkit.py |
Post-detection clipping, stacking, export |
evaluate.py |
Evaluation against ground-truth annotations |
make_package.py |
Nuitka packaging to standalone executable |
JSON config files in config/ define the full pipeline (loader, detector, collector settings). The default is config/m3det_normal.json. Config is deserialized into MainDetectCfg via dacite.
Detection results use the MetDetPy Detection Result Format (MDRF) — a JSON structure containing video metadata, config used, and a list of SingleMDRecord entries with bounding boxes, timestamps, confidence scores, and category labels.
- The project is bilingual (Chinese/English) in comments and docs. Code identifiers are in English.
- Python 3.9+ features are used (type hints with
list[...],tuple[...]). - Unit tests live in
tests/and are run withpython -m pytest tests/ -v. Integration testing is done viaevaluate.pyagainst annotated test videos intest/. - Resource files (weights, class names, clip config) are resolved relative to the project root via
relative2abs_path()in utils, overridable with--resource-dirorMETDET_RESOURCE_DIRenv var. - Class names are defined in
global/class_name.txtand loaded lazily. - ONNX model weights live in
weights/(tracked via Git LFS).