#!/usr/bin/env bash
# 对 DL_KPI_SCENE 下的所有 case 批量进行 GT 可视化
# 用法:
#   bash tools/scripts_for_gt/visualization/visualize_batch.sh [SAMPLE_INTERVAL]
# 例:
#   bash tools/scripts_for_gt/visualization/visualize_batch.sh 5   # 每隔5帧处理一帧

set -euo pipefail

SCENE_ROOT="/data1/dongying/Mono3d/G1Q3/dataset_for_evaluation/DL_KPI_SCENE"
SAMPLE_INTERVAL="${1:-20}"   # 第一个位置参数为采样间隔，默认为20
FILE_EXTENSION=".png"

# 收集所有 case 目录（含 images/ 子目录的）
mapfile -t CASE_DIRS < <(find "$SCENE_ROOT" -mindepth 1 -maxdepth 1 -type d | sort)

echo "共找到 ${#CASE_DIRS[@]} 个 case，采样间隔=${SAMPLE_INTERVAL}"
echo "======================================================"

SUCCESS=0
SKIP=0
FAIL=0

for CASE_DIR in "${CASE_DIRS[@]}"; do
    IMAGE_DIR="${CASE_DIR}/images"
    LABEL_DIR="${CASE_DIR}/labels_json"
    OUTPUT_DIR="${CASE_DIR}/vis_json"

    if [[ ! -d "$IMAGE_DIR" ]]; then
        echo "[SKIP] ${CASE_DIR##*/} — 无 images/ 目录"
        (( SKIP++ )) || true
        continue
    fi
    if [[ ! -d "$LABEL_DIR" ]]; then
        echo "[SKIP] ${CASE_DIR##*/} — 无 labels_json/ 目录"
        (( SKIP++ )) || true
        continue
    fi

    echo ""
    echo ">>> 处理 case: ${CASE_DIR##*/}"
    python tools/scripts_for_gt/visualization/visualize_batch.py \
        --image-dir  "$IMAGE_DIR" \
        --label-dir  "$LABEL_DIR" \
        --output     "$OUTPUT_DIR" \
        --file-extension "$FILE_EXTENSION" \
        --sample-interval "$SAMPLE_INTERVAL" \
    && (( SUCCESS++ )) || (( FAIL++ )) || true
done

echo ""
echo "======================================================"
echo "全部完成：成功=${SUCCESS}  跳过=${SKIP}  失败=${FAIL}" 
    
