{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nimport cv2\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-04T18:08:50.508758Z","iopub.execute_input":"2022-03-04T18:08:50.509101Z","iopub.status.idle":"2022-03-04T18:08:50.513956Z","shell.execute_reply.started":"2022-03-04T18:08:50.509066Z","shell.execute_reply":"2022-03-04T18:08:50.513253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_bbox(image, x1, y1, x2, y2):\n    path = os.path.join(\"../input/happy-whale-and-dolphin/train_images\", image)\n    image = cv2.imread(path)\n    xmin = int(min(x1, x2) * image.shape[1])\n    ymin = int(min(y1, y2) * image.shape[0])\n    xmax = int(max(x1, x2) * image.shape[1])\n    ymax = int(max(y1, y2) * image.shape[0])\n    image = cv2.rectangle(\n        image,\n        (xmin, ymin),\n        (xmax, ymax),\n        (0,255,255),\n        3\n    )\n    plt.imshow(image[:, :, ::-1])\n    \ndef plot_cropped(image, x1, y1, x2, y2):\n    path = os.path.join(\"../input/happy-whale-and-dolphin/train_images\", image)\n    image = cv2.imread(path)\n    xmin = int(min(x1, x2) * image.shape[1])\n    ymin = int(min(y1, y2) * image.shape[0])\n    xmax = int(max(x1, x2) * image.shape[1])\n    ymax = int(max(y1, y2) * image.shape[0])\n    plt.imshow(image[ymin:ymax, xmin:xmax, ::-1])\n    \ndef plot_bbox_dic(x):\n    plot_bbox(\n        x[\"image\"],\n        x[\"x1\"],\n        x[\"y1\"],\n        x[\"x2\"],\n        x[\"y2\"]\n    )\n    \ndef plot_cropped_dic(x):\n    plot_cropped(\n        x[\"image\"],\n        x[\"x1\"],\n        x[\"y1\"],\n        x[\"x2\"],\n        x[\"y2\"]\n    )","metadata":{"execution":{"iopub.status.busy":"2022-03-04T18:08:50.515797Z","iopub.execute_input":"2022-03-04T18:08:50.516237Z","iopub.status.idle":"2022-03-04T18:08:50.529455Z","shell.execute_reply.started":"2022-03-04T18:08:50.516206Z","shell.execute_reply":"2022-03-04T18:08:50.528735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv(\"../input/wandd-crowed-sourced-bounging-boxes/dataset.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-04T18:08:50.531118Z","iopub.execute_input":"2022-03-04T18:08:50.531651Z","iopub.status.idle":"2022-03-04T18:08:50.556241Z","shell.execute_reply.started":"2022-03-04T18:08:50.531613Z","shell.execute_reply":"2022-03-04T18:08:50.555184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"N_SAMPLES = 10","metadata":{"execution":{"iopub.status.busy":"2022-03-04T18:08:50.55766Z","iopub.execute_input":"2022-03-04T18:08:50.558098Z","iopub.status.idle":"2022-03-04T18:08:50.562813Z","shell.execute_reply.started":"2022-03-04T18:08:50.558053Z","shell.execute_reply":"2022-03-04T18:08:50.561914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"col=2\nrow=N_SAMPLES\nplt.figure(figsize=(col*6, row*2))\nsamples = data.sample(N_SAMPLES)\nfor i in range(row*col):\n    plt.subplot(row, col, i+1)\n    \n    x = samples.iloc[i//2]\n    if i%2 == 0:\n        plt.title(x[\"image\"])\n        plot_bbox_dic(x)\n    else:\n        plt.title(x[\"image\"])\n        plot_cropped_dic(x)\n        \n    plt.axis('off')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-04T18:08:50.567832Z","iopub.execute_input":"2022-03-04T18:08:50.568591Z","iopub.status.idle":"2022-03-04T18:08:59.34499Z","shell.execute_reply.started":"2022-03-04T18:08:50.56855Z","shell.execute_reply":"2022-03-04T18:08:59.344038Z"},"trusted":true},"execution_count":null,"outputs":[]}]}