{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "07bdc0da", "metadata": {}, "outputs": [], "source": [ "import os\n", "import json\n", "import numpy as np\n", "from tqdm.notebook import tqdm\n", "path_dataset = r'D:\\GrandPrix\\Grand-Prix'" ] }, { "cell_type": "code", "execution_count": 2, "id": "ca890aa0", "metadata": {}, "outputs": [], "source": [ "def find_image(id):\n", " for row in coco['images']:\n", " if row['id'] == id:\n", " return row" ] }, { "cell_type": "code", "execution_count": 3, "id": "b8135031", "metadata": {}, "outputs": [], "source": [ "def ltrb_from_cloud(cloud_2d, imgSize, expansion=0.1):\n", " height, width = imgSize\n", " ltrb = np.round((cloud_2d[:, 0].min(), cloud_2d[:, 1].min(),\n", " cloud_2d[:, 0].max(), cloud_2d[:, 1].max())).astype(int)\n", " \n", " if expansion > 0:\n", " dx = np.round((ltrb[2]-ltrb[0])*expansion/2)\n", " dy = np.round((ltrb[3]-ltrb[1])*expansion/2)\n", " ltrb += np.array([-dx, -2*dy, dx, dy], dtype=int)\n", " \n", " ltrb[[0,2]] = np.clip(ltrb[[0,2]], 0, width)\n", " ltrb[[1,3]] = np.clip(ltrb[[1,3]], 0, height)\n", " \n", " return ltrb\n", "\n", "def ltrb2ltwh(ltrb):\n", " return np.array([ltrb[0], ltrb[1], ltrb[2]-ltrb[0], ltrb[3]-ltrb[1]], dtype=int)" ] }, { "cell_type": "code", "execution_count": 4, "id": "79762c08", "metadata": {}, "outputs": [], "source": [ "with open(os.path.join(path_dataset, 'GrandPrix_COCO.json'), 'r') as file:\n", " coco = json.load(file)" ] }, { "cell_type": "markdown", "id": "a1cfe0e2", "metadata": {}, "source": [ "### Bboxes from pose" ] }, { "cell_type": "code", "execution_count": 5, "id": "f9440b54", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "758138a872a9485885387a5ffe5a9696", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/148 [00:00