#!/bin/bash

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"

# python "${PROJECT_ROOT}/tools/convert_merge_tracking_bundle/convert_merge_tracking.py" \
#         /data1/dongying/Mono3d/G1M3/cases_regular/model_20260228_test/combined_tracking.json \
#         -o /data1/dongying/Mono3d/G1M3/cases_regular/model_20260228_test/combined_tracking_converted-v2

# # -----------------------------------------------------------------------
# # 配置区：与 track_objects.sh 保持一致
# # -----------------------------------------------------------------------
RESULTS_ROOT="/data1/dongying/Mono3d/G1M3/cases_regular"
MODEL_NAME="model_20260317"
OUTPUT_DIR_NAME="combined_tracking_converted"

echo ""
echo "######################################################################"
echo "# Batch convert combined_tracking.json for all cases"
echo "######################################################################"

while IFS= read -r -d '' combined_tracking_json; do
    case_dir="$(dirname "$combined_tracking_json")"
    output_dir="${case_dir}/${OUTPUT_DIR_NAME}"

    echo ""
    echo "=========================================="
    echo "Input  : ${combined_tracking_json}"
    echo "Output : ${output_dir}"
    echo "=========================================="

    python "${PROJECT_ROOT}/tools/convert_merge_tracking_bundle/convert_merge_tracking.py" \
        "${combined_tracking_json}" \
        -o "${output_dir}"
done < <(find "${RESULTS_ROOT}/${MODEL_NAME}" -name "combined_tracking.json" -print0 | sort -z)