{"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 # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport pickle, glob\nimport cv2\nimport matplotlib.pyplot as plt\nfrom numpy.lib.stride_tricks import sliding_window_view","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-05-25T22:07:08.278538Z","iopub.execute_input":"2023-05-25T22:07:08.278954Z","iopub.status.idle":"2023-05-25T22:07:08.548714Z","shell.execute_reply.started":"2023-05-25T22:07:08.278922Z","shell.execute_reply":"2023-05-25T22:07:08.547365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"boxdf = pd.read_csv(\"/kaggle/input/sodaugresult/box.csv\",index_col=0).reset_index().rename(columns={\"index\":\"unique_id\"})\nboxdf[\"filename_id\"] = boxdf[\"unique_id\"].apply(lambda x: x.split(\"_\")[0])\nboxdf[\"time_id\"] = boxdf[\"unique_id\"].apply(lambda x: x.split(\"_\")[1])\nboxdf[\"box_id\"] = boxdf[\"unique_id\"].apply(lambda x: x.split(\"_\")[2])\nboxdf[\"start_x\"] = boxdf[\"time_id\"].astype(int)*500\n\npdf = pd.DataFrame(glob.glob(\"/kaggle/input/sodresult/audio_images/*.jpg\"),columns=[\"spec_path\"])\npdf[\"filename_id\"] = pdf.apply(lambda x: x[\"spec_path\"].split(\"/\")[-1].split(\".\")[0],axis=1)\npdf[\"time_id\"] = pdf.apply(lambda x: x[\"spec_path\"].split(\"/\")[-1].split(\".\")[1].split(\"_\")[-1],axis=1)\n\nboxdf = pd.merge(boxdf,pdf,on=[\"filename_id\",\"time_id\"])\n\n# boxdf[\"x1\"] = boxdf[\"x1\"] + boxdf[\"start_x\"]\n# boxdf[\"y1\"] = boxdf[\"y1\"]\n# boxdf[\"x2\"] = boxdf[\"x2\"] + boxdf[\"start_x\"]\n# boxdf[\"y2\"] = boxdf[\"y2\"]","metadata":{"execution":{"iopub.status.busy":"2023-05-25T22:22:34.695417Z","iopub.execute_input":"2023-05-25T22:22:34.695910Z","iopub.status.idle":"2023-05-25T22:22:42.888769Z","shell.execute_reply.started":"2023-05-25T22:22:34.695867Z","shell.execute_reply":"2023-05-25T22:22:42.887300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"boxdf.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-05-25T22:22:42.890747Z","iopub.execute_input":"2023-05-25T22:22:42.891114Z","iopub.status.idle":"2023-05-25T22:22:42.915730Z","shell.execute_reply.started":"2023-05-25T22:22:42.891083Z","shell.execute_reply":"2023-05-25T22:22:42.914344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#example result\n\nfor idx, (gidx, gdf) in enumerate(boxdf.reset_index(drop=True).groupby([\"filename_id\",\"time_id\"])):\n    gdf = gdf[gdf.conf > 0.2].reset_index(drop=True)\n    image = cv2.imread(gdf.spec_path.values[0])\n    for jdx, row in gdf.iterrows():\n        x1, y1, x2, y2 = row[[\"x1\",\"y1\",\"x2\",\"y2\"]].astype(int)\n        cv2.rectangle(image, (x1, y1), (x2, y2), (255, 0, 0), 2)  # 青色の線で長方形を描く\n    plt.imshow(image)\n    plt.show()\n    if idx==5:\n        break","metadata":{"execution":{"iopub.status.busy":"2023-05-25T22:22:51.137761Z","iopub.execute_input":"2023-05-25T22:22:51.139212Z","iopub.status.idle":"2023-05-25T22:22:54.195736Z","shell.execute_reply.started":"2023-05-25T22:22:51.139171Z","shell.execute_reply":"2023-05-25T22:22:54.194705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}