{"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":"markdown","source":"import necessary library","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport matplotlib.pyplot as plt #for reading and plotting images\nimport glob\nfrom PIL import Image\nfrom IPython.display import HTML","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-30T09:06:34.827961Z","iopub.execute_input":"2021-12-30T09:06:34.828293Z","iopub.status.idle":"2021-12-30T09:06:34.833882Z","shell.execute_reply.started":"2021-12-30T09:06:34.828254Z","shell.execute_reply":"2021-12-30T09:06:34.833252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Calculate the total frame and showing the sample image in video","metadata":{}},{"cell_type":"code","source":"#count of total imnage in folder video_0\nprint(len(os.listdir(\"../input/tensorflow-great-barrier-reef/train_images/video_0/\")))\n#sample image\nimg=plt.imread(\"../input/tensorflow-great-barrier-reef/train_images/video_0/\"+os.listdir(\"../input/tensorflow-great-barrier-reef/train_images/video_2/\")[0])\nplt.axis(\"off\")\nplt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2021-12-30T09:06:36.378058Z","iopub.execute_input":"2021-12-30T09:06:36.378367Z","iopub.status.idle":"2021-12-30T09:06:37.101122Z","shell.execute_reply.started":"2021-12-30T09:06:36.378336Z","shell.execute_reply":"2021-12-30T09:06:37.100119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#count of total imnage in folder video_1\nprint(len(os.listdir(\"../input/tensorflow-great-barrier-reef/train_images/video_1/\")))\n#sample image\nimg=plt.imread(\"../input/tensorflow-great-barrier-reef/train_images/video_1/\"+os.listdir(\"../input/tensorflow-great-barrier-reef/train_images/video_1/\")[0])\nplt.axis(\"off\")\nplt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2021-12-30T09:06:38.147841Z","iopub.execute_input":"2021-12-30T09:06:38.148161Z","iopub.status.idle":"2021-12-30T09:06:38.809884Z","shell.execute_reply.started":"2021-12-30T09:06:38.148128Z","shell.execute_reply":"2021-12-30T09:06:38.808837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#count of total image in folder video_2\nprint(len(os.listdir(\"../input/tensorflow-great-barrier-reef/train_images/video_2/\")))\n#sample image \nimg=plt.imread(\"../input/tensorflow-great-barrier-reef/train_images/video_2/\"+os.listdir(\"../input/tensorflow-great-barrier-reef/train_images/video_2/\")[0])\nplt.axis(\"off\")\nplt.imshow(img)","metadata":{"execution":{"iopub.status.busy":"2021-12-30T09:06:41.488051Z","iopub.execute_input":"2021-12-30T09:06:41.488641Z","iopub.status.idle":"2021-12-30T09:06:41.866711Z","shell.execute_reply.started":"2021-12-30T09:06:41.488604Z","shell.execute_reply":"2021-12-30T09:06:41.865619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"making gif ","metadata":{}},{"cell_type":"code","source":"#making gif from video frames\ndef make_gif(frame_folder):\n    frames=[]\n    for i in range(0,450,5):\n        frames.append(Image.open(f\"{frame_folder}/{i}.jpg\"))\n    frames[0].save(\"video_0.gif\", format=\"GIF\", append_images=frames, save_all=True, duration=120, loop=0)\n    \nmake_gif(\"../input/tensorflow-great-barrier-reef/train_images/video_0/\")\n#show the gif\nHTML('<img src=\"video_0.gif\" />')","metadata":{"execution":{"iopub.status.busy":"2021-12-30T09:28:50.169409Z","iopub.execute_input":"2021-12-30T09:28:50.170095Z","iopub.status.idle":"2021-12-30T09:28:56.528072Z","shell.execute_reply.started":"2021-12-30T09:28:50.170043Z","shell.execute_reply":"2021-12-30T09:28:56.527193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#making gif from video frame\ndef make_gif(frame_folder):\n    frames=[]\n    for i in range(0,450,5):\n        frames.append(Image.open(f\"{frame_folder}/{i}.jpg\"))\n    frames[0].save(\"video_1.gif\", format=\"GIF\", append_images=frames, save_all=True, duration=120, loop=0)\n    \nmake_gif(\"../input/tensorflow-great-barrier-reef/train_images/video_1/\")\n#show gif \nHTML('<img src=\"video_1.gif\" />')","metadata":{"execution":{"iopub.status.busy":"2021-12-30T09:28:56.529951Z","iopub.execute_input":"2021-12-30T09:28:56.530428Z","iopub.status.idle":"2021-12-30T09:29:02.440270Z","shell.execute_reply.started":"2021-12-30T09:28:56.530373Z","shell.execute_reply":"2021-12-30T09:29:02.439288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#making gif from video frames\ndef make_gif(frame_folder):\n    frames=[]\n    for i in range(0,450,5):\n        frames.append(Image.open(f\"{frame_folder}/{i}.jpg\"))\n    frames[0].save(\"video_2.gif\", format=\"GIF\", append_images=frames, save_all=True, duration=120, loop=0)\n    \nmake_gif(\"../input/tensorflow-great-barrier-reef/train_images/video_2/\")\n#show gif\nHTML('<img src=\"video_2.gif\" />')","metadata":{"execution":{"iopub.status.busy":"2021-12-30T09:29:02.877955Z","iopub.execute_input":"2021-12-30T09:29:02.878296Z","iopub.status.idle":"2021-12-30T09:29:12.019849Z","shell.execute_reply.started":"2021-12-30T09:29:02.878260Z","shell.execute_reply":"2021-12-30T09:29:12.019002Z"},"trusted":true},"execution_count":null,"outputs":[]}]}