{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5e46d2e1-d240-4e0f-bf12-d5dd67cd0c56",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/anaconda3/envs/mmyolo/lib/python3.8/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "import argparse\n",
    "import os\n",
    "import os.path as osp\n",
    "import time\n",
    "import cv2\n",
    "import torch\n",
    "import numpy as np\n",
    "from loguru import logger\n",
    "from collections import defaultdict, Counter\n",
    "\n",
    "from mmdet.apis import async_inference_detector, inference_detector\n",
    "from mmdet.apis.inference import init_detector\n",
    "\n",
    "\n",
    "from yolox.utils.visualize import plot_tracking, _COLORS\n",
    "from yolox.tracker.byte_tracker import BYTETracker\n",
    "from yolox.tracking_utils.timer import Timer\n",
    "\n",
    "IMAGE_EXT = [\".jpg\", \".jpeg\", \".webp\", \".bmp\", \".png\"]\n",
    "\n",
    "from IPython.display import clear_output\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "# clear_output(wait=False)\n",
    "\n",
    "from IPython.display import display, Javascript\n",
    "\n",
    "def clear_all_output():\n",
    "    display(Javascript('IPython.notebook.clear_all_output()'))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49a53d22-2616-4d9b-b67c-e044eb09c8a4",
   "metadata": {},
   "source": [
    "# 1. Single-Cam Trajectory Prediction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "07a05393-5d44-4d46-af3c-f4865c01eced",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def make_parser():\n",
    "    parser = argparse.ArgumentParser(\"Trajectory-Prediction Track Demo!\")\n",
    "    parser.add_argument(\n",
    "        \"demo\", default=\"video\", help=\"demo type, eg. image, video and webcam\"\n",
    "    )\n",
    "    \n",
    "    ########### mmdet bbox detector ##############\n",
    "    parser.add_argument('video', help='Video file path')\n",
    "    # parser.add_argument('config', help='Config file')\n",
    "    # parser.add_argument('checkpoint', help='Checkpoint file')\n",
    "    parser.add_argument(\n",
    "        '--device', default='cuda:0', help='Device used for inference')\n",
    "    ##############################################\n",
    "\n",
    "    parser.add_argument('--save_result', type=str, help='Output video file')\n",
    "    parser.add_argument('--save_vid', default=False, help='Output video file')\n",
    "    \n",
    "    # tracking args\n",
    "    parser.add_argument(\"--track_thresh\", type=float, default=0.8, help=\"tracking confidence threshold\")\n",
    "    parser.add_argument(\"--track_buffer\", type=int, default=150, help=\"the frames for keep lost tracks\")\n",
    "    parser.add_argument(\"--match_thresh\", type=float, default=0.8, help=\"matching threshold for tracking\")\n",
    "    # parser.add_argument(\n",
    "    #     \"--aspect_ratio_thresh\", type=float, default=1.6,\n",
    "    #     help=\"threshold for filtering out boxes of which aspect ratio are above the given value.\"\n",
    "    # )\n",
    "    # parser.add_argument('--min_box_area', type=float, default=10, help='filter out tiny boxes')\n",
    "    # parser.add_argument(\"--mot20\", dest=\"mot20\", default=False, action=\"store_true\", help=\"test mot20.\")\n",
    "    return parser\n",
    "\n",
    "args_list = [\n",
    "    'video',\n",
    "    '/data/autocon/hd_dataset/site1_093448',  # replace with actual path\n",
    "    # './weights/yolox_x.py',  # replace with actual path\n",
    "    # './weights/epoch_250.pth',  # replace with actual path\n",
    "    '--device', 'cuda:0',\n",
    "    '--save_result', './site1_093448-result',  # replace with actual path\n",
    "    '--save_vid', 'False',  # or 'False'\n",
    "    '--track_thresh', '0.8',\n",
    "    '--track_buffer', '30',\n",
    "    '--match_thresh', '0.8',\n",
    "    # '--min_box_area', '10',\n",
    "    # Add any other argument values you want to set\n",
    "]\n",
    "\n",
    "args = make_parser().parse_args(args_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "fd5700b3-41ee-476b-aef5-81efc8bc7d2b",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def mmdet3x_convert(results, threshold):\n",
    "    det_result_list = []\n",
    "   \n",
    "    confidence_score = results.pred_instances.scores.tolist()\n",
    "    for i, conf in enumerate(confidence_score):\n",
    "        if conf >= threshold:\n",
    "            # print(conf)\n",
    "            \n",
    "            extracted_box = results.pred_instances.bboxes[i].cpu().tolist()\n",
    "            extracted_label = results.pred_instances.labels[i].cpu().tolist()\n",
    "            \n",
    "            class_name = 0\n",
    "            \n",
    "            temp = [float(extracted_box[0]),\n",
    "                     float(extracted_box[1]),\n",
    "                     float(extracted_box[2]),\n",
    "                     float(extracted_box[3]), float(0.9), class_name]\n",
    "            \n",
    "            det_result_list.append(temp)\n",
    "            \n",
    "    return np.array(det_result_list)\n",
    "\n",
    "def mmdet3x_convert_pretrain(results, threshold):\n",
    "    det_result_list = []\n",
    "\n",
    "    # permit_class_list = [0, 7]\n",
    "    permit_class_list = [0]\n",
    "    class_labels = results.pred_instances.labels.tolist()\n",
    "    \n",
    "    confidence_score = results.pred_instances.scores.tolist()\n",
    "    for i, conf in enumerate(confidence_score):\n",
    "        if conf >= threshold and class_labels[i] in permit_class_list:\n",
    "            # print(conf)\n",
    "            \n",
    "            extracted_box = results.pred_instances.bboxes[i].cpu().tolist()\n",
    "            extracted_label = results.pred_instances.labels[i].cpu().tolist()\n",
    "            \n",
    "            class_name = 0\n",
    "            \n",
    "            temp = [float(extracted_box[0]),\n",
    "                     float(extracted_box[1]),\n",
    "                     float(extracted_box[2]),\n",
    "                     float(extracted_box[3]), float(0.9), class_name]\n",
    "            \n",
    "            det_result_list.append(temp)\n",
    "            \n",
    "    return np.array(det_result_list)\n",
    "\n",
    "def compute_iou(boxA, boxB):\n",
    "    # Compute the coordinates of the intersection rectangle\n",
    "    xA = max(boxA[0], boxB[0])\n",
    "    yA = max(boxA[1], boxB[1])\n",
    "    xB = min(boxA[2], boxB[2])\n",
    "    yB = min(boxA[3], boxB[3])\n",
    "    \n",
    "    # Compute the area of intersection\n",
    "    interArea = max(0, xB - xA) * max(0, yB - yA)\n",
    "    \n",
    "    # Compute the area of both boxes\n",
    "    boxAArea = (boxA[2] - boxA[0]) * (boxA[3] - boxA[1])\n",
    "    boxBArea = (boxB[2] - boxB[0]) * (boxB[3] - boxB[1])\n",
    "    \n",
    "    # Compute IoU\n",
    "    iou = interArea / float(boxAArea + boxBArea - interArea)\n",
    "    \n",
    "    return iou\n",
    "\n",
    "def nms(boxes, overlap_threshold=0.5):\n",
    "    if len(boxes) == 0:\n",
    "        return []\n",
    "    \n",
    "    pick = []\n",
    "    \n",
    "    # Extract coordinates and scores from the boxes\n",
    "    x1 = boxes[:,0]\n",
    "    y1 = boxes[:,1]\n",
    "    x2 = boxes[:,2]\n",
    "    y2 = boxes[:,3]\n",
    "    scores = boxes[:,4]\n",
    "    \n",
    "    # Compute the area of each box and sort the scores in descending order\n",
    "    area = (x2 - x1) * (y2 - y1)\n",
    "    indices = np.argsort(scores)[::-1]\n",
    "    \n",
    "    while len(indices) > 0:\n",
    "        # Take the index of the box with the highest score\n",
    "        current = indices[0]\n",
    "        pick.append(current)\n",
    "        \n",
    "        # Compute IoU between the box with the highest score and the other boxes\n",
    "        ious = np.array([compute_iou(boxes[current], boxes[i]) for i in indices[1:]])\n",
    "        \n",
    "        # Get the indices of boxes that are overlapping less than the threshold with the current box\n",
    "        remove_indices = np.where(ious > overlap_threshold)[0] + 1\n",
    "        \n",
    "        # Remove the current box and the overlapping boxes\n",
    "        indices = np.delete(indices, remove_indices)\n",
    "        indices = np.delete(indices, 0)\n",
    "        \n",
    "    return boxes[pick]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b0d3ed36-7b75-4495-a26e-9dccfeb1d2bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "frame_img_list = []\n",
    "\n",
    "# only worker\n",
    "\n",
    "def imageflow_demo(det_model, vis_folder, current_time, args):\n",
    "    \n",
    "    tracker_list = []\n",
    "    \n",
    "    temp = []\n",
    "    channel_list = [file for file in os.listdir(args.video)]\n",
    "    for channel in channel_list:\n",
    "        d = os.path.join(args.video, channel)\n",
    "        if os.path.isdir(d) and not channel.startswith('.'):\n",
    "            temp.append(channel)\n",
    "    \n",
    "    for channel in temp:\n",
    "        video_path = os.path.join(os.path.join(args.video, channel, 'video.mp4'))\n",
    "    \n",
    "        cap = cv2.VideoCapture(video_path)\n",
    "        width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)  # float\n",
    "        height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)  # float\n",
    "        fps = cap.get(cv2.CAP_PROP_FPS)\n",
    "        timestamp = time.strftime(\"%Y_%m_%d_%H_%M_%S\", current_time)\n",
    "        \n",
    "        if args.save_vid:\n",
    "            save_folder = osp.join(vis_folder, channel)\n",
    "            os.makedirs(save_folder, exist_ok=True)\n",
    "            save_path = osp.join(save_folder,\"inference_vid.mp4\")\n",
    "\n",
    "            logger.info(f\"video save_path is {save_path}\")\n",
    "            vid_writer = cv2.VideoWriter(\n",
    "                save_path, cv2.VideoWriter_fourcc(*\"mp4v\"), fps, (int(width), int(height))\n",
    "            )\n",
    "        \n",
    "        tracker = BYTETracker(args, frame_rate=30)\n",
    "        timer = Timer()\n",
    "        frame_id = 0\n",
    "        results = []\n",
    "        \n",
    "        while True:\n",
    "            if frame_id % 30 == 0:\n",
    "                logger.info('Processing frame {} ({:.2f} fps)'.format(frame_id, 1. / max(1e-5, timer.average_time)))\n",
    "            ret_val, frame = cap.read()\n",
    "            if ret_val:\n",
    "                \n",
    "                timer.tic()\n",
    "                worker_det_results = inference_detector(det_model[0], frame)\n",
    "                vehicle_det_results = inference_detector(det_model[1], frame)\n",
    "                pretrained_det_results = inference_detector(det_model[2], frame)\n",
    "                \n",
    "                threshold = 0.15\n",
    "                worker_class_dic = {0: 8, 1: 9}\n",
    "                # vehicle_class_dic = {0 : 0, 1 : 1, 2 : 2, 3 : 3, 4 : 4, 5 : 5, 6 : 6, 7 : 7}\n",
    "                \n",
    "                worker_results = mmdet3x_convert(worker_det_results, threshold)\n",
    "                # vehicle_results = mmdet3x_convert(vehicle_det_results, threshold)\n",
    "                pretrained_results = mmdet3x_convert_pretrain(pretrained_det_results, threshold)\n",
    "\n",
    "                print(pretrained_results)\n",
    "                \n",
    "                # *** dets format [x1,y1,x2,y2,score,class_id]\n",
    "                all_results = [result for result in [worker_results, pretrained_results] if result.size > 0]\n",
    "\n",
    "                if len(all_results) == 0:\n",
    "                    final_boxes = np.array([], dtype=float64)\n",
    "                else:\n",
    "                    combined_boxes = np.concatenate(all_results, axis=0)\n",
    "                    final_boxes = nms(combined_boxes)\n",
    "\n",
    "                dets_arr = np.array(final_boxes)\n",
    "\n",
    "                # ##############\n",
    "                # print(\"frame # : \", frame_id)\n",
    "                # print(dets_arr)\n",
    "                # ##############\n",
    "              \n",
    "                if dets_arr is not None:\n",
    "                    # Run tracker\n",
    "                    online_targets = tracker.update(dets_arr, frame)\n",
    "                    \n",
    "                    online_tlwhs = []\n",
    "                    online_ids = []\n",
    "                    online_scores = []\n",
    "                    for t in online_targets:\n",
    "                        tlwh = t.tlwh\n",
    "                        tid = t.track_id\n",
    "                        # vertical = tlwh[2] / tlwh[3] > args.aspect_ratio_thresh\n",
    "                        online_tlwhs.append(tlwh)\n",
    "                        online_ids.append(tid)\n",
    "                        online_scores.append(t.score)\n",
    "                        results.append(\n",
    "                            f\"{frame_id},{tid},{tlwh[0]:.2f},{tlwh[1]:.2f},{tlwh[2]:.2f},{tlwh[3]:.2f},{t.score:.2f},-1,-1,-1\\n\"\n",
    "                        )\n",
    "                    timer.toc()\n",
    "                    \n",
    "                    online_im = plot_tracking(\n",
    "                        frame, online_tlwhs, online_ids, frame_id=frame_id + 1, fps=1. / timer.average_time\n",
    "                    )\n",
    "                else:\n",
    "                    timer.toc()\n",
    "                    online_im = frame\n",
    "                if args.save_vid:\n",
    "                    vid_writer.write(online_im)\n",
    "                ch = cv2.waitKey(1)\n",
    "                if ch == 27 or ch == ord(\"q\") or ch == ord(\"Q\"):\n",
    "                    break\n",
    "            else:\n",
    "                break\n",
    "                \n",
    "            if frame_id == 51:\n",
    "                frame_img_list.append(online_im) \n",
    "                break    \n",
    "            \n",
    "            frame_id += 1\n",
    "\n",
    "        if args.save_result:\n",
    "            res_file = osp.join(save_folder, f\"{timestamp}.txt\")\n",
    "            with open(res_file, 'w') as f:\n",
    "                f.writelines(results)\n",
    "            logger.info(f\"save results to {res_file}\")\n",
    "            \n",
    "        tracker_list.append(tracker)\n",
    "        \n",
    "    return tracker_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bb5199b5-c0b0-4b5b-92e5-d421c160a149",
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2023-12-28 18:36:15.915\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36m<module>\u001b[0m:\u001b[36m23\u001b[0m - \u001b[1mArgs: Namespace(demo='video', device='cuda:0', match_thresh=0.8, save_result='./site1_093448-result', save_vid='False', track_buffer=30, track_thresh=0.8, video='/data/autocon/hd_dataset/site1_093448')\u001b[0m\n",
      "\u001b[32m2023-12-28 18:36:15.991\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36mimageflow_demo\u001b[0m:\u001b[36m30\u001b[0m - \u001b[1mvideo save_path is ./site1_093448-result/track_vis/c5/inference_vid.mp4\u001b[0m\n",
      "\u001b[32m2023-12-28 18:36:15.994\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36mimageflow_demo\u001b[0m:\u001b[36m42\u001b[0m - \u001b[1mProcessing frame 0 (100000.00 fps)\u001b[0m\n",
      "/opt/anaconda3/envs/mmyolo/lib/python3.8/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  /opt/conda/conda-bld/pytorch_1639180588308/work/aten/src/ATen/native/TensorShape.cpp:2157.)\n",
      "  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2023-12-28 18:36:22.764\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36m__main__\u001b[0m:\u001b[36mimageflow_demo\u001b[0m:\u001b[36m42\u001b[0m - \u001b[1mProcessing frame 30 (4.88 fps)\u001b[0m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "KeyboardInterrupt\n",
      "\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "if args.save_result:\n",
    "    output_dir = osp.join(args.save_result)\n",
    "    os.makedirs(output_dir, exist_ok=True)\n",
    "    vis_folder = osp.join(output_dir, \"track_vis\")\n",
    "    os.makedirs(vis_folder, exist_ok=True)\n",
    "\n",
    "vehicle_config = \"/data/autocon/detection/weights/yolov8x_vehicle.py\"\n",
    "vehicle_checkpoint = '/data/autocon/detection/weights/yolov8x_vehicle.pth'\n",
    "vehicle_model = init_detector(vehicle_config, vehicle_checkpoint, device='cuda:0')\n",
    "\n",
    "worker_config = \"/data/autocon/detection/weights/yolov8x_signalman.py\"\n",
    "worker_checkpoint = '/data/autocon/detection/weights/yolov8x_signalman.pth'\n",
    "worker_model = init_detector(worker_config, worker_checkpoint, device='cuda:0')\n",
    "\n",
    "pretrained_config = \"/data/autocon/detection/weights/yolov8-x-worker.py\"\n",
    "pretrained_checkpoint = '/data/autocon/detection/weights/epoch_10.pth'\n",
    "pretrained_model = init_detector(pretrained_config, pretrained_checkpoint, device='cuda:0')\n",
    "\n",
    "det_model = (worker_model, vehicle_model, pretrained_model)\n",
    "\n",
    "clear_output(wait=False)\n",
    "\n",
    "logger.info(\"Args: {}\".format(args))\n",
    "\n",
    "current_time = time.localtime()\n",
    "\n",
    "if args.demo == \"video\":\n",
    "    tracker_list = imageflow_demo(det_model, vis_folder, current_time, args)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e1fc4bd8-e3f0-4c2b-b675-22ced8d2b4c8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc914a30-a8dc-49dd-aa17-d90999401c63",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7cc51a8b-1c27-4a72-80b6-fafa46495c94",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6733a11-6ba4-4ed7-a4ea-c78f562c2e9e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "3eea22d8-ed95-4082-b13f-5668db56964b",
   "metadata": {},
   "source": [
    "# Tracklet Visualization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f621bb58-1864-4424-82d0-057d1f650486",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def give_color(tracking_id):\n",
    "    return [int(item) for item in 255*_COLORS[tracking_id]]\n",
    "\n",
    "def draw_tracklet(img, tracklets):\n",
    "    result_img = img.copy()\n",
    "\n",
    "    interpolated_tracklets = {}\n",
    "    \n",
    "    for idx,tracklet in enumerate(tracklets):\n",
    "        interpolated_tracklet = inf_interpolated_coor(tracklet.tlwh_log)\n",
    "    \n",
    "        x_coords = []\n",
    "        y_coords = []\n",
    "        for item in interpolated_tracklet:\n",
    "            c_x, b_y= item[0],item[1]\n",
    "            x_coords.append(int(c_x))\n",
    "            y_coords.append(int(b_y))\n",
    "\n",
    "        interpolated_tracklets[tracklet.track_id] = [x_coords,y_coords]\n",
    "\n",
    "        now_c_x = int(tracklet._tlwh[0] + (tracklet._tlwh[2]/2))\n",
    "        now_b_y = int(tracklet._tlwh[1] + tracklet._tlwh[3])\n",
    "        x_coords.append(now_c_x)\n",
    "        y_coords.append(now_b_y)\n",
    "        \n",
    "        # color = (255,0,0)\n",
    "        color = give_color(tracklet.track_id%100)\n",
    "        \n",
    "        # Draw the points and connect them with a line\n",
    "        for i in range(len(x_coords)-1):\n",
    "            # Draw point\n",
    "            result_img = cv2.circle(result_img, (x_coords[i], y_coords[i]), 4, color, -1)\n",
    "            # Draw line\n",
    "            result_img = cv2.line(result_img, (x_coords[i], y_coords[i]), (x_coords[i+1], y_coords[i+1]), color, 3)\n",
    "        # Draw the last point\n",
    "        result_img = cv2.circle(result_img, (x_coords[-1], y_coords[-1]), 4, color, -1)\n",
    "    \n",
    "    return result_img, interpolated_tracklets\n",
    "\n",
    "cmap = ['red', 'green', 'blue', 'cyan', 'magenta', 'yellow']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1218eb1-f466-48bd-9213-53a5e8f2bbd5",
   "metadata": {},
   "source": [
    "#### 1. 경로 보간\n",
    "#### 2. 보간 경로 점 중심으로 그리기 (색상은 ID기반)\n",
    "#### 3. 보간경로 점을 input(8개) 으로 주고 경로 예측(12개)\n",
    "#### 4. 예측경로 그리기 (색상은 빨간색)\n",
    "#### 5. ADE/FDE 평가 (**실제 트래킹 된 결과값으로 평가하기)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b3574182-521b-4e51-836f-02ac3b4f0bb2",
   "metadata": {},
   "source": [
    "### VIS for cam#1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "35192abe-1e1f-4f48-8f9d-2de7628a2533",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. 경로 보간 및\n",
    "# 2. 보간 경로 그리기\n",
    "cam1_result_img, interpolated_tracklets1 = draw_tracklet(frame_img_list[0], tracker_list[0].tracked_stracks) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7fd6a684-f58b-4b92-b5ab-8ce2fa5471b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3. 경로 예측\n",
    "# 4. 예측 경로 그리기"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "79b1f20b-7cdb-4869-8d9d-a6872c0b07cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 5. 예측 경로 평가"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f8f9ee92-6ecd-4d5f-a319-007f7829472e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cv2.imwrite('result1.png',cam1_result_img)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aff1388c-b6d9-4d0f-b6e8-2a6a815982c4",
   "metadata": {},
   "source": [
    "### VIS for cam#2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "4955cb43-588d-4e59-99e3-d1c55741ca44",
   "metadata": {},
   "outputs": [],
   "source": [
    "cam2_result_img, interpolated_tracklets2 = draw_tracklet(frame_img_list[1], tracker_list[1].tracked_stracks)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1b012840-ee2d-4018-be6d-1c1fe1196c37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cv2.imwrite('result2.png',cam2_result_img)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "72ba3a47-6d93-43e5-8497-99d1cc69df5f",
   "metadata": {},
   "source": [
    "### Vis for cam#3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "e8dd0b67-4761-4d1b-a03a-6812c8e474e8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "cam3_result_img, interpolated_tracklets3 = draw_tracklet(frame_img_list[2], tracker_list[2].tracked_stracks)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "6c731ccb-706a-4d1c-bf97-6b6151a5e387",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cv2.imwrite('result3.png',cam3_result_img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2028ba16-d5db-4a90-89f8-9d56e2f27e8d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de012a3d-cc0e-4859-8e51-1b59d5798e89",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mmyolo",
   "language": "python",
   "name": "mmyolo"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
