dnt 0.2.1__py3-none-any.whl → 0.3.1.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dnt/__init__.py +4 -1
- dnt/analysis/__init__.py +3 -1
- dnt/analysis/count.py +107 -0
- dnt/analysis/interaction2.py +518 -0
- dnt/analysis/position.py +12 -0
- dnt/analysis/stop.py +92 -33
- dnt/analysis/stop2.py +289 -0
- dnt/analysis/stop3.py +758 -0
- dnt/detect/__init__.py +1 -1
- dnt/detect/signal/detector.py +326 -0
- dnt/detect/timestamp.py +105 -0
- dnt/detect/yolov8/detector.py +182 -35
- dnt/detect/yolov8/segmentor.py +171 -0
- dnt/engine/__init__.py +8 -0
- dnt/engine/bbox_interp.py +83 -0
- dnt/engine/bbox_iou.py +20 -0
- dnt/engine/cluster.py +31 -0
- dnt/engine/iob.py +66 -0
- dnt/filter/__init__.py +4 -0
- dnt/filter/filter.py +450 -21
- dnt/label/__init__.py +1 -1
- dnt/label/labeler.py +215 -14
- dnt/label/labeler2.py +631 -0
- dnt/shared/__init__.py +2 -1
- dnt/shared/data/coco.names +0 -0
- dnt/shared/data/openimages.names +0 -0
- dnt/shared/data/voc.names +0 -0
- dnt/shared/download.py +12 -0
- dnt/shared/synhcro.py +150 -0
- dnt/shared/util.py +17 -4
- dnt/third_party/fast-reid/__init__.py +1 -0
- dnt/third_party/fast-reid/configs/Base-AGW.yml +19 -0
- dnt/third_party/fast-reid/configs/Base-MGN.yml +12 -0
- dnt/third_party/fast-reid/configs/Base-SBS.yml +63 -0
- dnt/third_party/fast-reid/configs/Base-bagtricks.yml +76 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/AGW_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/mgn_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/sbs_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/AGW_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT17/AGW_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/AGW_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT17/AGW_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/bagtricks_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT17/bagtricks_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/mgn_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/sbs_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT17/sbs_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/sbs_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT17/sbs_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/AGW_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT20/AGW_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/AGW_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT20/AGW_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/bagtricks_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT20/bagtricks_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/mgn_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/sbs_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT20/sbs_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/sbs_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT20/sbs_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MSMT17/AGW_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MSMT17/AGW_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MSMT17/AGW_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MSMT17/AGW_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R101-ibn.yml +13 -0
- dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MSMT17/bagtricks_S50.yml +12 -0
- dnt/third_party/fast-reid/configs/MSMT17/mgn_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MSMT17/sbs_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MSMT17/sbs_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MSMT17/sbs_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MSMT17/sbs_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/AGW_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/Market1501/AGW_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/AGW_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/Market1501/AGW_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/bagtricks_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/Market1501/bagtricks_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/bagtricks_vit.yml +88 -0
- dnt/third_party/fast-reid/configs/Market1501/mgn_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/sbs_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/Market1501/sbs_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/sbs_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/Market1501/sbs_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/VERIWild/bagtricks_R50-ibn.yml +35 -0
- dnt/third_party/fast-reid/configs/VeRi/sbs_R50-ibn.yml +35 -0
- dnt/third_party/fast-reid/configs/VehicleID/bagtricks_R50-ibn.yml +36 -0
- dnt/third_party/fast-reid/configs/__init__.py +0 -0
- dnt/third_party/fast-reid/fast_reid_interfece.py +175 -0
- dnt/third_party/fast-reid/fastreid/__init__.py +6 -0
- dnt/third_party/fast-reid/fastreid/config/__init__.py +15 -0
- dnt/third_party/fast-reid/fastreid/config/config.py +319 -0
- dnt/third_party/fast-reid/fastreid/config/defaults.py +329 -0
- dnt/third_party/fast-reid/fastreid/data/__init__.py +17 -0
- dnt/third_party/fast-reid/fastreid/data/build.py +194 -0
- dnt/third_party/fast-reid/fastreid/data/common.py +58 -0
- dnt/third_party/fast-reid/fastreid/data/data_utils.py +202 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/AirportALERT.py +50 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/__init__.py +43 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/bases.py +183 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/caviara.py +44 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/cuhk03.py +274 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/cuhk_sysu.py +58 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/dukemtmcreid.py +70 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/grid.py +44 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/iLIDS.py +45 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/lpw.py +49 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/market1501.py +89 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/msmt17.py +114 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/pes3d.py +44 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/pku.py +44 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/prai.py +43 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/prid.py +41 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/saivt.py +47 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/sensereid.py +47 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/shinpuhkan.py +48 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/sysu_mm.py +47 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/thermalworld.py +43 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/vehicleid.py +126 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/veri.py +69 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/veriwild.py +140 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/viper.py +45 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/wildtracker.py +59 -0
- dnt/third_party/fast-reid/fastreid/data/samplers/__init__.py +18 -0
- dnt/third_party/fast-reid/fastreid/data/samplers/data_sampler.py +85 -0
- dnt/third_party/fast-reid/fastreid/data/samplers/imbalance_sampler.py +67 -0
- dnt/third_party/fast-reid/fastreid/data/samplers/triplet_sampler.py +260 -0
- dnt/third_party/fast-reid/fastreid/data/transforms/__init__.py +11 -0
- dnt/third_party/fast-reid/fastreid/data/transforms/autoaugment.py +806 -0
- dnt/third_party/fast-reid/fastreid/data/transforms/build.py +100 -0
- dnt/third_party/fast-reid/fastreid/data/transforms/functional.py +180 -0
- dnt/third_party/fast-reid/fastreid/data/transforms/transforms.py +161 -0
- dnt/third_party/fast-reid/fastreid/engine/__init__.py +15 -0
- dnt/third_party/fast-reid/fastreid/engine/defaults.py +490 -0
- dnt/third_party/fast-reid/fastreid/engine/hooks.py +534 -0
- dnt/third_party/fast-reid/fastreid/engine/launch.py +103 -0
- dnt/third_party/fast-reid/fastreid/engine/train_loop.py +357 -0
- dnt/third_party/fast-reid/fastreid/evaluation/__init__.py +6 -0
- dnt/third_party/fast-reid/fastreid/evaluation/clas_evaluator.py +81 -0
- dnt/third_party/fast-reid/fastreid/evaluation/evaluator.py +176 -0
- dnt/third_party/fast-reid/fastreid/evaluation/query_expansion.py +46 -0
- dnt/third_party/fast-reid/fastreid/evaluation/rank.py +200 -0
- dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/__init__.py +20 -0
- dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/setup.py +32 -0
- dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/test_cython.py +106 -0
- dnt/third_party/fast-reid/fastreid/evaluation/reid_evaluation.py +143 -0
- dnt/third_party/fast-reid/fastreid/evaluation/rerank.py +73 -0
- dnt/third_party/fast-reid/fastreid/evaluation/roc.py +90 -0
- dnt/third_party/fast-reid/fastreid/evaluation/testing.py +88 -0
- dnt/third_party/fast-reid/fastreid/layers/__init__.py +19 -0
- dnt/third_party/fast-reid/fastreid/layers/activation.py +59 -0
- dnt/third_party/fast-reid/fastreid/layers/any_softmax.py +80 -0
- dnt/third_party/fast-reid/fastreid/layers/batch_norm.py +205 -0
- dnt/third_party/fast-reid/fastreid/layers/context_block.py +113 -0
- dnt/third_party/fast-reid/fastreid/layers/drop.py +161 -0
- dnt/third_party/fast-reid/fastreid/layers/frn.py +199 -0
- dnt/third_party/fast-reid/fastreid/layers/gather_layer.py +30 -0
- dnt/third_party/fast-reid/fastreid/layers/helpers.py +31 -0
- dnt/third_party/fast-reid/fastreid/layers/non_local.py +54 -0
- dnt/third_party/fast-reid/fastreid/layers/pooling.py +124 -0
- dnt/third_party/fast-reid/fastreid/layers/se_layer.py +25 -0
- dnt/third_party/fast-reid/fastreid/layers/splat.py +109 -0
- dnt/third_party/fast-reid/fastreid/layers/weight_init.py +122 -0
- dnt/third_party/fast-reid/fastreid/modeling/__init__.py +23 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/__init__.py +18 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/build.py +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenet.py +195 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenetv3.py +283 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/osnet.py +525 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/__init__.py +4 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/config.py +396 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B0_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B1_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B2_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B3_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B4_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B5_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet.py +281 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnet.py +596 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-1.6GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-12GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-16GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-200MF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-3.2GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-32GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-4.0GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-400MF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-6.4GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-600MF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-8.0GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-800MF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-1.6GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-12GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-16GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-200MF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-3.2GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-32GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-4.0GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-400MF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-6.4GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-600MF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-8.0GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-800MF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/repvgg.py +309 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/resnest.py +365 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/resnet.py +364 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/resnext.py +335 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/shufflenet.py +203 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/vision_transformer.py +399 -0
- dnt/third_party/fast-reid/fastreid/modeling/heads/__init__.py +11 -0
- dnt/third_party/fast-reid/fastreid/modeling/heads/build.py +25 -0
- dnt/third_party/fast-reid/fastreid/modeling/heads/clas_head.py +36 -0
- dnt/third_party/fast-reid/fastreid/modeling/heads/embedding_head.py +151 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/__init__.py +12 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/circle_loss.py +71 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/cross_entroy_loss.py +54 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/focal_loss.py +92 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/triplet_loss.py +113 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/utils.py +48 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/__init__.py +14 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/baseline.py +188 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/build.py +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/distiller.py +140 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/mgn.py +394 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/moco.py +126 -0
- dnt/third_party/fast-reid/fastreid/solver/__init__.py +8 -0
- dnt/third_party/fast-reid/fastreid/solver/build.py +348 -0
- dnt/third_party/fast-reid/fastreid/solver/lr_scheduler.py +66 -0
- dnt/third_party/fast-reid/fastreid/solver/optim/__init__.py +10 -0
- dnt/third_party/fast-reid/fastreid/solver/optim/lamb.py +123 -0
- dnt/third_party/fast-reid/fastreid/solver/optim/radam.py +149 -0
- dnt/third_party/fast-reid/fastreid/solver/optim/swa.py +246 -0
- dnt/third_party/fast-reid/fastreid/utils/__init__.py +6 -0
- dnt/third_party/fast-reid/fastreid/utils/checkpoint.py +503 -0
- dnt/third_party/fast-reid/fastreid/utils/collect_env.py +158 -0
- dnt/third_party/fast-reid/fastreid/utils/comm.py +255 -0
- dnt/third_party/fast-reid/fastreid/utils/compute_dist.py +200 -0
- dnt/third_party/fast-reid/fastreid/utils/env.py +119 -0
- dnt/third_party/fast-reid/fastreid/utils/events.py +461 -0
- dnt/third_party/fast-reid/fastreid/utils/faiss_utils.py +127 -0
- dnt/third_party/fast-reid/fastreid/utils/file_io.py +520 -0
- dnt/third_party/fast-reid/fastreid/utils/history_buffer.py +71 -0
- dnt/third_party/fast-reid/fastreid/utils/logger.py +211 -0
- dnt/third_party/fast-reid/fastreid/utils/params.py +103 -0
- dnt/third_party/fast-reid/fastreid/utils/precision_bn.py +94 -0
- dnt/third_party/fast-reid/fastreid/utils/registry.py +66 -0
- dnt/third_party/fast-reid/fastreid/utils/summary.py +120 -0
- dnt/third_party/fast-reid/fastreid/utils/timer.py +68 -0
- dnt/third_party/fast-reid/fastreid/utils/visualizer.py +278 -0
- dnt/track/__init__.py +3 -1
- dnt/track/botsort/__init__.py +4 -0
- dnt/track/botsort/bot_tracker/__init__.py +3 -0
- dnt/track/botsort/bot_tracker/basetrack.py +60 -0
- dnt/track/botsort/bot_tracker/bot_sort.py +473 -0
- dnt/track/botsort/bot_tracker/gmc.py +316 -0
- dnt/track/botsort/bot_tracker/kalman_filter.py +269 -0
- dnt/track/botsort/bot_tracker/matching.py +194 -0
- dnt/track/botsort/bot_tracker/mc_bot_sort.py +505 -0
- dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/evaluation.py +14 -4
- dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/io.py +19 -36
- dnt/track/botsort/bot_tracker/tracking_utils/timer.py +37 -0
- dnt/track/botsort/inference.py +96 -0
- dnt/track/config.py +120 -0
- dnt/track/dsort/configs/bagtricks_R50.yml +7 -0
- dnt/track/dsort/configs/deep_sort.yaml +0 -0
- dnt/track/dsort/configs/fastreid.yaml +1 -1
- dnt/track/dsort/deep_sort/deep/checkpoint/ckpt.t7 +0 -0
- dnt/track/dsort/deep_sort/deep/feature_extractor.py +87 -8
- dnt/track/dsort/deep_sort/deep_sort.py +31 -21
- dnt/track/dsort/deep_sort/sort/detection.py +2 -1
- dnt/track/dsort/deep_sort/sort/iou_matching.py +0 -2
- dnt/track/dsort/deep_sort/sort/linear_assignment.py +0 -3
- dnt/track/dsort/deep_sort/sort/nn_matching.py +5 -5
- dnt/track/dsort/deep_sort/sort/preprocessing.py +1 -2
- dnt/track/dsort/deep_sort/sort/track.py +2 -1
- dnt/track/dsort/deep_sort/sort/tracker.py +1 -1
- dnt/track/dsort/dsort.py +44 -27
- dnt/track/re_class.py +117 -0
- dnt/track/sort/sort.py +9 -7
- dnt/track/tracker.py +225 -20
- dnt-0.3.1.8.dist-info/METADATA +117 -0
- dnt-0.3.1.8.dist-info/RECORD +315 -0
- {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info}/WHEEL +1 -1
- dnt/track/dsort/deep_sort/deep/evaluate.py +0 -15
- dnt/track/dsort/deep_sort/deep/original_model.py +0 -106
- dnt/track/dsort/deep_sort/deep/test.py +0 -77
- dnt/track/dsort/deep_sort/deep/train.py +0 -189
- dnt/track/dsort/utils/asserts.py +0 -13
- dnt/track/dsort/utils/draw.py +0 -36
- dnt/track/dsort/utils/json_logger.py +0 -383
- dnt/track/dsort/utils/log.py +0 -17
- dnt/track/dsort/utils/parser.py +0 -35
- dnt/track/dsort/utils/tools.py +0 -39
- dnt-0.2.1.dist-info/METADATA +0 -35
- dnt-0.2.1.dist-info/RECORD +0 -60
- /dnt/{track/dsort/utils → third_party/fast-reid/checkpoint}/__init__.py +0 -0
- {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info/licenses}/LICENSE +0 -0
- {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info}/top_level.txt +0 -0
dnt/detect/__init__.py
CHANGED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import cv2, os
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import numpy as np
|
|
5
|
+
from tqdm import tqdm
|
|
6
|
+
from PIL import Image
|
|
7
|
+
from typing import List
|
|
8
|
+
import torch
|
|
9
|
+
import torch.nn as nn
|
|
10
|
+
import torchvision.models as models
|
|
11
|
+
import torchvision.transforms as transforms
|
|
12
|
+
from torchvision.models.resnet import ResNet18_Weights
|
|
13
|
+
from shared.download import download_file
|
|
14
|
+
from matplotlib import pyplot as plt
|
|
15
|
+
from ultralytics import YOLO
|
|
16
|
+
|
|
17
|
+
class Model(nn.Module):
|
|
18
|
+
def __init__(self, num_class=2):
|
|
19
|
+
super(Model, self).__init__()
|
|
20
|
+
|
|
21
|
+
self.resnet18 = models.resnet18(weights=ResNet18_Weights.DEFAULT)
|
|
22
|
+
self.resnet18.fc = nn.Linear(512, num_class)
|
|
23
|
+
|
|
24
|
+
def forward(self, x):
|
|
25
|
+
return self.resnet18(x)
|
|
26
|
+
|
|
27
|
+
class SignalDetector:
|
|
28
|
+
def __init__(self,
|
|
29
|
+
det_zones:list,
|
|
30
|
+
model:str='ped',
|
|
31
|
+
weights:str=None,
|
|
32
|
+
batchsz:int=64,
|
|
33
|
+
num_class:int=2,
|
|
34
|
+
threshold:float=0.98,
|
|
35
|
+
device='auto'):
|
|
36
|
+
'''
|
|
37
|
+
Detect traffic signal status
|
|
38
|
+
|
|
39
|
+
Parameters:
|
|
40
|
+
- det_zones: cropped zones for detection list[(x, y, w, h)]
|
|
41
|
+
- model: detection model, default is 'ped', 'custom'
|
|
42
|
+
- weights: path of weights, default is None
|
|
43
|
+
- batchsz: the batch size for prediction, default is 64
|
|
44
|
+
- num_class: the number of classes, default is 2
|
|
45
|
+
- threshold: the threshold for detection, default is 0.98
|
|
46
|
+
'''
|
|
47
|
+
|
|
48
|
+
self.det_zones = det_zones
|
|
49
|
+
|
|
50
|
+
cwd = Path(__file__).parent.absolute()
|
|
51
|
+
if not weights:
|
|
52
|
+
if (model == 'ped'):
|
|
53
|
+
weights = os.path.join(cwd, 'weights', 'ped_signal.pt')
|
|
54
|
+
|
|
55
|
+
if not os.path.exists(weights):
|
|
56
|
+
url = 'https://its.cutr.usf.edu/alms/downloads/ped_signal.pt'
|
|
57
|
+
download_file(url, weights)
|
|
58
|
+
|
|
59
|
+
self.model = Model(num_class)
|
|
60
|
+
if device == 'auto':
|
|
61
|
+
self.device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'
|
|
62
|
+
elif device == 'cuda' and torch.cuda.is_available():
|
|
63
|
+
self.device = 'cuda'
|
|
64
|
+
elif device == 'mps' and torch.backends.mps.is_available():
|
|
65
|
+
self.device = 'mps'
|
|
66
|
+
else:
|
|
67
|
+
self.device = 'cpu'
|
|
68
|
+
|
|
69
|
+
self.model.load_state_dict(torch.load(weights))
|
|
70
|
+
self.model.to(self.device)
|
|
71
|
+
|
|
72
|
+
self.batchsz = batchsz
|
|
73
|
+
self.threshold = threshold
|
|
74
|
+
|
|
75
|
+
def detect(self, input_video:str, det_file:str=None,
|
|
76
|
+
video_index:int=None, video_tot:int=None):
|
|
77
|
+
'''
|
|
78
|
+
Parameters:
|
|
79
|
+
- input_video: the video path
|
|
80
|
+
- det_file: the file name for output
|
|
81
|
+
- video_index: the index of video
|
|
82
|
+
- video_tot: the total number of videos
|
|
83
|
+
|
|
84
|
+
Return:
|
|
85
|
+
- a dataframe with prediction results, ['frame', 'zone0', 'zone1', ...]
|
|
86
|
+
'''
|
|
87
|
+
|
|
88
|
+
# initialize the result array
|
|
89
|
+
results = np.array([]) #np.full((0, len(self.det_zones)), -1)
|
|
90
|
+
frames = np.array([])
|
|
91
|
+
zones = np.array([])
|
|
92
|
+
batch = []
|
|
93
|
+
temp_frames=[]
|
|
94
|
+
|
|
95
|
+
# open input video
|
|
96
|
+
cap = cv2.VideoCapture(input_video)
|
|
97
|
+
if not cap.isOpened():
|
|
98
|
+
print('Failed to open the video!')
|
|
99
|
+
|
|
100
|
+
tot_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
101
|
+
pbar = tqdm(total=tot_frames, unit=' frame')
|
|
102
|
+
if video_index and video_tot:
|
|
103
|
+
pbar.set_description_str("Detecting signals {} of {}".format(video_index, video_tot))
|
|
104
|
+
else:
|
|
105
|
+
pbar.set_description_str("Detecting signals ")
|
|
106
|
+
|
|
107
|
+
while cap.isOpened():
|
|
108
|
+
pos_frame = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
|
|
109
|
+
ret, frame = cap.read()
|
|
110
|
+
if not ret:
|
|
111
|
+
break
|
|
112
|
+
|
|
113
|
+
crop_img = self.crop_zone(frame)
|
|
114
|
+
batch.append(crop_img)
|
|
115
|
+
temp_frames.append(pos_frame)
|
|
116
|
+
|
|
117
|
+
if ((pos_frame+1) % self.batchsz == 0) or (pos_frame >= tot_frames-1):
|
|
118
|
+
#batch_pred = self.predict(batch).reshape(-1, len(self.det_zones))
|
|
119
|
+
#results = np.append(results, batch_pred, axis=0)
|
|
120
|
+
|
|
121
|
+
batch_pred = self.predict(batch).flatten()
|
|
122
|
+
results = np.append(results, batch_pred, axis=0)
|
|
123
|
+
zones = np.append(zones, np.tile(np.array(list(range(len(self.det_zones)))), self.batchsz), axis=0)
|
|
124
|
+
frames = np.append(frames, np.repeat(np.array(temp_frames), len(self.det_zones)), axis=0)
|
|
125
|
+
|
|
126
|
+
batch=[]
|
|
127
|
+
temp_frames = []
|
|
128
|
+
|
|
129
|
+
pbar.update()
|
|
130
|
+
|
|
131
|
+
pbar.close()
|
|
132
|
+
cap.release()
|
|
133
|
+
|
|
134
|
+
df = pd.DataFrame(list(zip(frames, zones, results)), columns=['frame', 'signal', 'detection'])
|
|
135
|
+
|
|
136
|
+
if det_file:
|
|
137
|
+
df.to_csv(det_file, index=False)
|
|
138
|
+
|
|
139
|
+
return df
|
|
140
|
+
|
|
141
|
+
def gen_ped_interval(self, dets:pd.DataFrame, input_video:str, walk_interval:int, countdown_interval:int,
|
|
142
|
+
out_file:str, factor:float=0.75, video_index:int=None, video_tot:int=None):
|
|
143
|
+
'''
|
|
144
|
+
Parameters:
|
|
145
|
+
- dets: the dataframe for signal detections
|
|
146
|
+
- input_video: the video path
|
|
147
|
+
- walk_interval: the pedestrian walking interval 4s to 7s
|
|
148
|
+
- countdown_interval: the pedestrian countdown interval, cross-length(ft)/4(ft/s)
|
|
149
|
+
- factor: the factor to identify a walking signal (0, 1),
|
|
150
|
+
default is 0.75 (75% of frames in a sliding window is walking, then walking is identified)
|
|
151
|
+
|
|
152
|
+
Return:
|
|
153
|
+
- a dataframe of ped sigal intervals ['signal', 'walk_beg', 'walk_end', 'countdown_beg', 'countdown_end']
|
|
154
|
+
'''
|
|
155
|
+
|
|
156
|
+
# open input video
|
|
157
|
+
cap = cv2.VideoCapture(input_video)
|
|
158
|
+
if not cap.isOpened():
|
|
159
|
+
print('Failed to open the video!')
|
|
160
|
+
fps = cap.get(cv2.CAP_PROP_FPS)
|
|
161
|
+
cap.release()
|
|
162
|
+
|
|
163
|
+
results = []
|
|
164
|
+
for i in range(len(self.det_zones)):
|
|
165
|
+
dets_i = dets[dets['signal']==i]
|
|
166
|
+
results.append(self.scan_walk_interval(dets_i, int(fps*walk_interval), factor, i, fps))
|
|
167
|
+
|
|
168
|
+
df = pd.concat(results, axis=0)
|
|
169
|
+
if out_file:
|
|
170
|
+
df.to_csv(out_file, index=False)
|
|
171
|
+
|
|
172
|
+
return df
|
|
173
|
+
|
|
174
|
+
def scan_walk_interval(self, dets:pd.DataFrame, window:int, factor:float, zone:int, fps:int=30,
|
|
175
|
+
video_index:int=None, video_tot:int=None) -> pd.DataFrame:
|
|
176
|
+
|
|
177
|
+
sequence = dets['detection'].to_numpy()
|
|
178
|
+
|
|
179
|
+
if len(sequence) == 0:
|
|
180
|
+
return []
|
|
181
|
+
|
|
182
|
+
frame_intervals = []
|
|
183
|
+
pre_walk = False
|
|
184
|
+
tmp_cnt = 0
|
|
185
|
+
|
|
186
|
+
pbar = tqdm(total=len(sequence)-window, unit=' frame')
|
|
187
|
+
if video_index and video_tot:
|
|
188
|
+
pbar.set_description_str("Scanning intervals for signal {}, {} of {}".format(zone, video_index, video_tot))
|
|
189
|
+
else:
|
|
190
|
+
pbar.set_description_str("Scanning intervals for signal {}".format(zone))
|
|
191
|
+
|
|
192
|
+
for i in range(len(sequence) - window):
|
|
193
|
+
count = sum(sequence[i:i+window])
|
|
194
|
+
|
|
195
|
+
# check if the current frame can be a start of green light
|
|
196
|
+
if count >= factor * window:
|
|
197
|
+
is_walking = True
|
|
198
|
+
else:
|
|
199
|
+
is_walking = False
|
|
200
|
+
|
|
201
|
+
# if the current is green
|
|
202
|
+
# 1) if prev status is green, update the latest interval
|
|
203
|
+
# 2) if prev status is not green, append a new interval
|
|
204
|
+
if is_walking:
|
|
205
|
+
if not pre_walk:
|
|
206
|
+
frame_intervals.append([i, i + window])
|
|
207
|
+
tmp_cnt = 0
|
|
208
|
+
else:
|
|
209
|
+
if count > tmp_cnt:
|
|
210
|
+
tmp_cnt = count
|
|
211
|
+
frame_intervals[-1] = [i, i + window]
|
|
212
|
+
|
|
213
|
+
pre_walk = is_walking
|
|
214
|
+
|
|
215
|
+
pbar.update()
|
|
216
|
+
pbar.close()
|
|
217
|
+
|
|
218
|
+
results = []
|
|
219
|
+
for start, end in frame_intervals:
|
|
220
|
+
results.append([zone, 1, int(dets['frame'].iloc[start]), int(dets['frame'].iloc[end])])
|
|
221
|
+
results.append([zone, 2, int(dets['frame'].iloc[end])+1, int(dets['frame'].iloc[end]+int(10*fps))])
|
|
222
|
+
|
|
223
|
+
df = pd.DataFrame(results, columns=['signal', 'status', 'beg_frame', 'end_frame'])
|
|
224
|
+
return df
|
|
225
|
+
|
|
226
|
+
def crop_zone(self, frame:np.ndarray)->list[np.ndarray]:
|
|
227
|
+
'''
|
|
228
|
+
Parameters:
|
|
229
|
+
- frame: frame of the video
|
|
230
|
+
|
|
231
|
+
Return:
|
|
232
|
+
- list of cropped zones
|
|
233
|
+
'''
|
|
234
|
+
crop_regions = []
|
|
235
|
+
for i, region in enumerate(self.det_zones):
|
|
236
|
+
x, y, w, h = region
|
|
237
|
+
cropped = frame[y:y + h, x:x + w]
|
|
238
|
+
cropped = Image.fromarray(cropped)
|
|
239
|
+
crop_regions.append(cropped)
|
|
240
|
+
return crop_regions
|
|
241
|
+
|
|
242
|
+
def predict(self, batch:list):
|
|
243
|
+
"""
|
|
244
|
+
Parameters:
|
|
245
|
+
batch: the cropped batch of images
|
|
246
|
+
Returns:
|
|
247
|
+
pred_array: the corresponding traffic signal predictions with format (zone0_pred, zone1_pred, ...)
|
|
248
|
+
"""
|
|
249
|
+
self.model.eval()
|
|
250
|
+
sf = nn.Softmax(dim=1)
|
|
251
|
+
batchsz = len(batch)
|
|
252
|
+
num_group = len(batch[0])
|
|
253
|
+
|
|
254
|
+
# define the image transform
|
|
255
|
+
transform = transforms.Compose([
|
|
256
|
+
transforms.Resize((64, 64)),
|
|
257
|
+
transforms.ToTensor(),
|
|
258
|
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
|
259
|
+
])
|
|
260
|
+
|
|
261
|
+
# Transform all images and stack to different groups(corresponding light)
|
|
262
|
+
transformed_crops = [[transform(image) for image in crop] for crop in batch]
|
|
263
|
+
transformed_batch = [torch.stack([transformed_crops[j][i] for j in range(batchsz)]) for i in range(num_group)]
|
|
264
|
+
|
|
265
|
+
# send to model and make predictions zone by zone
|
|
266
|
+
batch_pred = []
|
|
267
|
+
for group in transformed_batch:
|
|
268
|
+
# compute the probability of the detections
|
|
269
|
+
outputs = self.model(group.to(self.device))
|
|
270
|
+
sf_output = sf(outputs)
|
|
271
|
+
|
|
272
|
+
# predict green only if the probability > threshold
|
|
273
|
+
y_pred = (sf_output[:, 1] > self.threshold).int()
|
|
274
|
+
batch_pred.append(y_pred.data.cpu().numpy())
|
|
275
|
+
|
|
276
|
+
pred_array = np.array(batch_pred).T
|
|
277
|
+
# prob_array = np.array(batch_prob).T
|
|
278
|
+
|
|
279
|
+
return pred_array
|
|
280
|
+
|
|
281
|
+
def generate_labels(self, signals:pd.DataFrame, input_video:str, label_file:str,
|
|
282
|
+
size_factor:float=1.5, thick:int=1, video_index:int=None, video_tot:int=None)->pd.DataFrame:
|
|
283
|
+
|
|
284
|
+
# open input video
|
|
285
|
+
cap = cv2.VideoCapture(input_video)
|
|
286
|
+
if not cap.isOpened():
|
|
287
|
+
print('Failed to open the video!')
|
|
288
|
+
tot_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
289
|
+
cap.release()
|
|
290
|
+
|
|
291
|
+
pbar = tqdm(total= tot_frames)
|
|
292
|
+
if video_index and video_tot:
|
|
293
|
+
pbar.set_description_str("Generating signal labeles for {} of {}".format(video_index, video_tot))
|
|
294
|
+
else:
|
|
295
|
+
pbar.set_description_str("Generating signal labels")
|
|
296
|
+
|
|
297
|
+
results = []
|
|
298
|
+
for i in range(tot_frames):
|
|
299
|
+
for j in range(len(self.det_zones)):
|
|
300
|
+
status = 0 # no walking
|
|
301
|
+
selected = signals[(signals['beg_frame']<=i) & (signals['end_frame']>=i) & (signals['signal']==j)]
|
|
302
|
+
if len(selected) > 0:
|
|
303
|
+
status = selected['status'].iloc[0]
|
|
304
|
+
|
|
305
|
+
x, y, w, h = self.det_zones[j]
|
|
306
|
+
cx = int(x + w/2)
|
|
307
|
+
cy = int(y + h/2)
|
|
308
|
+
r = int(max(w, h) * size_factor)
|
|
309
|
+
|
|
310
|
+
if status == 0:
|
|
311
|
+
results.append([i, 'circle', [(cx, cy)], (0, 0, 255), r, thick, ''])
|
|
312
|
+
elif status == 1:
|
|
313
|
+
results.append([i, 'circle', [(cx, cy)], (0, 255, 0), r, thick, ''])
|
|
314
|
+
elif status == 2:
|
|
315
|
+
results.append([i, 'circle', [(cx, cy)], (0, 255, 255), r, thick, ''])
|
|
316
|
+
|
|
317
|
+
pbar.update()
|
|
318
|
+
|
|
319
|
+
df = pd.DataFrame(results, columns=['frame','type','coords','color','size','thick','desc'])
|
|
320
|
+
df.sort_values(by='frame')
|
|
321
|
+
|
|
322
|
+
if label_file:
|
|
323
|
+
df.to_csv(label_file, index=False)
|
|
324
|
+
|
|
325
|
+
return df
|
|
326
|
+
|
dnt/detect/timestamp.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import easyocr
|
|
2
|
+
import cv2
|
|
3
|
+
import numpy as np
|
|
4
|
+
import dateparser
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
class TimestampExtractor:
|
|
8
|
+
def __init__(self,
|
|
9
|
+
zone:np.ndarray=None,
|
|
10
|
+
allowlist='0123456789-:/'):
|
|
11
|
+
"""
|
|
12
|
+
args:
|
|
13
|
+
zone (np.ndarray): The coordinates of the timestamp area in the image.
|
|
14
|
+
allowlist (str): Characters to allow in the OCR process.
|
|
15
|
+
"""
|
|
16
|
+
self.zone = zone
|
|
17
|
+
self.reader = easyocr.Reader(['en'])
|
|
18
|
+
self.allowlist = allowlist
|
|
19
|
+
|
|
20
|
+
def extract_timestamp(self,
|
|
21
|
+
img:np.ndarray,
|
|
22
|
+
gray:bool=False,
|
|
23
|
+
) -> datetime:
|
|
24
|
+
"""
|
|
25
|
+
Extract timestamp from the image using OCR.
|
|
26
|
+
args:
|
|
27
|
+
img (np.ndarray): The input image from which to extract the timestamp.
|
|
28
|
+
returns:
|
|
29
|
+
datetime: The extracted timestamp.
|
|
30
|
+
"""
|
|
31
|
+
# Ensure the zone is a numpy array
|
|
32
|
+
if self.zone is None:
|
|
33
|
+
crop_img = img
|
|
34
|
+
else:
|
|
35
|
+
x1, y1, x2, y2 = self.zone[0][0], self.zone[0][1], self.zone[2][0], self.zone[2][1]
|
|
36
|
+
crop_img = img[y1:y2, x1:x2]
|
|
37
|
+
|
|
38
|
+
if gray:
|
|
39
|
+
crop_img = cv2.cvtColor(crop_img, cv2.COLOR_BGR2GRAY)
|
|
40
|
+
else:
|
|
41
|
+
crop_img = crop_img
|
|
42
|
+
|
|
43
|
+
result = self.reader.readtext(crop_img, detail=0, allowlist='0123456789-:/')
|
|
44
|
+
dt = dateparser.parse(" ".join(result))
|
|
45
|
+
return dt
|
|
46
|
+
|
|
47
|
+
def extract_timestamp_video(self,
|
|
48
|
+
video_path:str,
|
|
49
|
+
frame:int=0,
|
|
50
|
+
gray:bool=False,
|
|
51
|
+
) -> datetime:
|
|
52
|
+
"""
|
|
53
|
+
Extract timestamp from a video file using OCR.
|
|
54
|
+
args:
|
|
55
|
+
video_path (str): The path to the video file.
|
|
56
|
+
frame (int): The frame index to extract the timestamp from.
|
|
57
|
+
gray (bool): Whether to convert the image to grayscale before OCR.
|
|
58
|
+
returns:
|
|
59
|
+
datetime: The extracted timestamp.
|
|
60
|
+
"""
|
|
61
|
+
cap = cv2.VideoCapture(video_path)
|
|
62
|
+
cap.set(cv2.CAP_PROP_POS_FRAMES, frame)
|
|
63
|
+
ret, img = cap.read()
|
|
64
|
+
cap.release()
|
|
65
|
+
|
|
66
|
+
if not ret:
|
|
67
|
+
raise ValueError("Could not read video file")
|
|
68
|
+
|
|
69
|
+
return self.extract_timestamp(img, gray=gray)
|
|
70
|
+
|
|
71
|
+
def extract_timestamp_video_auto(self,
|
|
72
|
+
video_path:str,
|
|
73
|
+
gray:bool=False,
|
|
74
|
+
) -> tuple:
|
|
75
|
+
"""
|
|
76
|
+
Extract the initial timestamp from the first readable frame in a video file using OCR.
|
|
77
|
+
args:
|
|
78
|
+
video_path (str): The path to the video file.
|
|
79
|
+
gray (bool): Whether to convert the image to grayscale before OCR.
|
|
80
|
+
returns:
|
|
81
|
+
dt, frame: The extracted timestamp and the frame index.
|
|
82
|
+
"""
|
|
83
|
+
cap = cv2.VideoCapture(video_path)
|
|
84
|
+
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
|
|
85
|
+
tot = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
86
|
+
|
|
87
|
+
for frame in range(0, tot-1):
|
|
88
|
+
ret, img = cap.read()
|
|
89
|
+
if not ret:
|
|
90
|
+
break
|
|
91
|
+
dt = self.extract_timestamp(img, gray=gray)
|
|
92
|
+
if dt:
|
|
93
|
+
cap.release()
|
|
94
|
+
return dt, frame
|
|
95
|
+
|
|
96
|
+
cap.release()
|
|
97
|
+
return None, None
|
|
98
|
+
|
|
99
|
+
if __name__ == "__main__":
|
|
100
|
+
img = cv2.imread('/mnt/d/videos/sample/frames/007_day.png')
|
|
101
|
+
zone = np.array([[62, 1003], [543, 1000], [547, 1059], [67, 1061]])
|
|
102
|
+
extractor = TimestampExtractor(zone=zone)
|
|
103
|
+
timestamp = extractor.extract_timestamp(img)
|
|
104
|
+
print("Extracted Timestamp:")
|
|
105
|
+
print(timestamp)
|