{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\n#         print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-11-29T01:00:50.747464Z","iopub.execute_input":"2021-11-29T01:00:50.747737Z","iopub.status.idle":"2021-11-29T01:00:50.752688Z","shell.execute_reply.started":"2021-11-29T01:00:50.74771Z","shell.execute_reply":"2021-11-29T01:00:50.75181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nfrom matplotlib import pyplot as plt\nimport json\nimport ast","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:00:55.306051Z","iopub.execute_input":"2021-11-29T01:00:55.306364Z","iopub.status.idle":"2021-11-29T01:00:55.310061Z","shell.execute_reply.started":"2021-11-29T01:00:55.306327Z","shell.execute_reply":"2021-11-29T01:00:55.309368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_path = \"/kaggle/input/tensorflow-great-barrier-reef/train_images/video_0/17.jpg\"\nimg_name = img_path.split(\"/\")[-1]\nimg = cv2.imread(img_path)\nimg = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:23.833668Z","iopub.execute_input":"2021-11-29T01:07:23.833973Z","iopub.status.idle":"2021-11-29T01:07:23.878572Z","shell.execute_reply.started":"2021-11-29T01:07:23.833919Z","shell.execute_reply":"2021-11-29T01:07:23.877973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_name","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:24.124221Z","iopub.execute_input":"2021-11-29T01:07:24.124823Z","iopub.status.idle":"2021-11-29T01:07:24.129729Z","shell.execute_reply.started":"2021-11-29T01:07:24.12479Z","shell.execute_reply":"2021-11-29T01:07:24.12919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:24.377567Z","iopub.execute_input":"2021-11-29T01:07:24.378544Z","iopub.status.idle":"2021-11-29T01:07:24.772971Z","shell.execute_reply.started":"2021-11-29T01:07:24.378499Z","shell.execute_reply":"2021-11-29T01:07:24.772164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv(\"/kaggle/input/tensorflow-great-barrier-reef/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:24.774336Z","iopub.execute_input":"2021-11-29T01:07:24.774637Z","iopub.status.idle":"2021-11-29T01:07:24.804991Z","shell.execute_reply.started":"2021-11-29T01:07:24.774599Z","shell.execute_reply":"2021-11-29T01:07:24.80428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[data['annotations']!='[]']","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:24.890642Z","iopub.execute_input":"2021-11-29T01:07:24.891379Z","iopub.status.idle":"2021-11-29T01:07:24.912222Z","shell.execute_reply.started":"2021-11-29T01:07:24.891337Z","shell.execute_reply":"2021-11-29T01:07:24.911459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"frame_number = img_name.split('.')[0]\nframe_number","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:25.133512Z","iopub.execute_input":"2021-11-29T01:07:25.134359Z","iopub.status.idle":"2021-11-29T01:07:25.139796Z","shell.execute_reply.started":"2021-11-29T01:07:25.13432Z","shell.execute_reply":"2021-11-29T01:07:25.139006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['sequence_frame'].dtype","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:25.345668Z","iopub.execute_input":"2021-11-29T01:07:25.345947Z","iopub.status.idle":"2021-11-29T01:07:25.351187Z","shell.execute_reply.started":"2021-11-29T01:07:25.3459Z","shell.execute_reply":"2021-11-29T01:07:25.35057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[data['video_frame'] == int(frame_number)]['annotations'].iloc[0]","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:25.579696Z","iopub.execute_input":"2021-11-29T01:07:25.579999Z","iopub.status.idle":"2021-11-29T01:07:25.586418Z","shell.execute_reply.started":"2021-11-29T01:07:25.579964Z","shell.execute_reply":"2021-11-29T01:07:25.585571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Parsing string\nparsed_dict = ast.literal_eval(data[data['video_frame'] == int(frame_number)]['annotations'].iloc[0])\nparsed_dict","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:25.829792Z","iopub.execute_input":"2021-11-29T01:07:25.8307Z","iopub.status.idle":"2021-11-29T01:07:25.838606Z","shell.execute_reply.started":"2021-11-29T01:07:25.830653Z","shell.execute_reply":"2021-11-29T01:07:25.837994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xs = parsed_dict[0]['x']\nys = parsed_dict[0]['y']\nxe = xs + parsed_dict[0]['width']\nye = ys + parsed_dict[0]['height']","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:26.024699Z","iopub.execute_input":"2021-11-29T01:07:26.025142Z","iopub.status.idle":"2021-11-29T01:07:26.029529Z","shell.execute_reply.started":"2021-11-29T01:07:26.025108Z","shell.execute_reply":"2021-11-29T01:07:26.028742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xs, ys, xe, ye","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:26.233038Z","iopub.execute_input":"2021-11-29T01:07:26.233463Z","iopub.status.idle":"2021-11-29T01:07:26.238684Z","shell.execute_reply.started":"2021-11-29T01:07:26.233433Z","shell.execute_reply":"2021-11-29T01:07:26.237866Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imsave('save.jpg', cv2.rectangle(img, (xs,ys), (xe, ye), color = (0,255,0), thickness = 1))","metadata":{"execution":{"iopub.status.busy":"2021-11-29T01:07:26.441699Z","iopub.execute_input":"2021-11-29T01:07:26.442309Z","iopub.status.idle":"2021-11-29T01:07:26.506968Z","shell.execute_reply.started":"2021-11-29T01:07:26.442267Z","shell.execute_reply":"2021-11-29T01:07:26.506226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}