{"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 os\nimport subprocess\n\nimport numpy as np\n\nimport cv2\nfrom PIL import Image","metadata":{"execution":{"iopub.status.busy":"2023-03-05T16:03:03.603534Z","iopub.execute_input":"2023-03-05T16:03:03.603950Z","iopub.status.idle":"2023-03-05T16:03:03.645559Z","shell.execute_reply.started":"2023-03-05T16:03:03.603914Z","shell.execute_reply":"2023-03-05T16:03:03.644075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"video = '58168_003392_Endzone.mp4'\nos.mkdir('/kaggle/work')\nsubprocess.run(f'ffmpeg -i /kaggle/input/nfl-player-contact-detection/test/{video} -q:v 2 -f image2 /kaggle/work/{video}_%04d.jpg -hide_banner -loglevel error', shell=True)","metadata":{"execution":{"iopub.status.busy":"2023-03-05T16:03:57.120125Z","iopub.execute_input":"2023-03-05T16:03:57.120632Z","iopub.status.idle":"2023-03-05T16:04:02.622863Z","shell.execute_reply.started":"2023-03-05T16:03:57.120588Z","shell.execute_reply":"2023-03-05T16:04:02.621234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_name = f'/kaggle/work/{video}_0001.jpg'\nimg_name","metadata":{"execution":{"iopub.status.busy":"2023-03-05T16:05:32.338562Z","iopub.execute_input":"2023-03-05T16:05:32.339001Z","iopub.status.idle":"2023-03-05T16:05:32.347061Z","shell.execute_reply.started":"2023-03-05T16:05:32.338965Z","shell.execute_reply":"2023-03-05T16:05:32.345280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_img1():\n    img = Image.open(img_name)\n    np.array(img)\n    \n%timeit load_img1()","metadata":{"execution":{"iopub.status.busy":"2023-03-05T16:08:13.576769Z","iopub.execute_input":"2023-03-05T16:08:13.577238Z","iopub.status.idle":"2023-03-05T16:08:15.420538Z","shell.execute_reply.started":"2023-03-05T16:08:13.577197Z","shell.execute_reply":"2023-03-05T16:08:15.419140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"left = 100\ntop = 100\nright = 200\nbottom = 200\n\ndef load_img2():\n    for _ in range(1):\n        img = Image.open(img_name)\n        np.array(img.crop((left, top, right, bottom)))\n    \n%timeit load_img2()","metadata":{"execution":{"iopub.status.busy":"2023-03-05T16:09:36.042004Z","iopub.execute_input":"2023-03-05T16:09:36.042509Z","iopub.status.idle":"2023-03-05T16:09:48.616181Z","shell.execute_reply.started":"2023-03-05T16:09:36.042468Z","shell.execute_reply":"2023-03-05T16:09:48.614829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_img_opencv():\n    img = cv2.imread(img_name)\n    np.array(img)\n    \n%timeit load_img_opencv()","metadata":{"execution":{"iopub.status.busy":"2023-03-05T16:10:35.429374Z","iopub.execute_input":"2023-03-05T16:10:35.430010Z","iopub.status.idle":"2023-03-05T16:10:46.279447Z","shell.execute_reply.started":"2023-03-05T16:10:35.429959Z","shell.execute_reply":"2023-03-05T16:10:46.277536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}