{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":71885,"databundleVersionId":8015523,"sourceType":"competition"}],"dockerImageVersionId":30673,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"Published on March 26, 2024. By Marília Prata, mpwolke.","metadata":{}},{"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\nfor 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","_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-03-26T16:39:55.820938Z","iopub.execute_input":"2024-03-26T16:39:55.822070Z","iopub.status.idle":"2024-03-26T16:39:56.316482Z","shell.execute_reply.started":"2024-03-26T16:39:55.822019Z","shell.execute_reply":"2024-03-26T16:39:56.315197Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Competition Citation\n\n@misc{image-matching-challenge-2024,\n\n    author = {Fabio Bellavia, Jiri Matas, Dmytro Mishkin, Luca Morelli, Fabio Remondino, Weiwei Sun, Amy Tabb, Eduard Trulls, Kwang Moo Yi, Sohier Dane, Ashley Chow},\n    \n    title = {Image Matching Challenge 2024 - Hexathlon},\n    \n    publisher = {Kaggle},\n    year = {2024},\n    url = {https://kaggle.com/competitions/image-matching-challenge-","metadata":{}},{"cell_type":"markdown","source":"#I tried Leonid Kulyk (2023) however SFM (cameras, images, ponits3D) were txt. Now they are bin. \n\nTherefore, I wasn't able to plot Leonid's Kulyk unique 3D. Only the images.\n","metadata":{}},{"cell_type":"code","source":"!pip install mediapy -q","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-03-26T16:40:03.931604Z","iopub.execute_input":"2024-03-26T16:40:03.932887Z","iopub.status.idle":"2024-03-26T16:40:16.749338Z","shell.execute_reply.started":"2024-03-26T16:40:03.932839Z","shell.execute_reply":"2024-03-26T16:40:16.747694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#By Leonid Kulyk https://www.kaggle.com/code/leonidkulyk/eda-imc-3d-plots-interactive-vis#-%F0%9F%8F%9B%EF%B8%8F-Image-Matching-Challenge---%F0%9F%93%8A-Exploratory-Data-Analysis\n\n%cd /kaggle/working/\n!rm -rf /kaggle/working/Hierarchical-Localization\n!git clone --quiet --recursive https://github.com/cvg/Hierarchical-Localization/\n%cd /kaggle/working/Hierarchical-Localization\n!pip install -e .\n\nfrom hloc import extract_features, match_features, reconstruction, visualization, pairs_from_exhaustive\nfrom hloc.visualization import plot_images, read_image\nfrom hloc.utils import viz_3d\n\n%cd /kaggle/working/","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-03-26T16:40:20.952748Z","iopub.execute_input":"2024-03-26T16:40:20.953274Z","iopub.status.idle":"2024-03-26T16:41:05.154852Z","shell.execute_reply.started":"2024-03-26T16:40:20.953233Z","shell.execute_reply":"2024-03-26T16:41:05.153290Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#By Leonid Kulyk https://www.kaggle.com/code/leonidkulyk/eda-imc-3d-plots-interactive-vis#-%F0%9F%8F%9B%EF%B8%8F-Image-Matching-Challenge---%F0%9F%93%8A-Exploratory-Data-Analysis\n\nimport os\nimport cv2\nimport pycolmap\n\nimport numpy as np\nimport mediapy as media\nimport pandas as pd\nimport plotly.express as px\nimport plotly.graph_objects as go\n\nfrom glob import glob\nfrom pathlib import Path\nfrom time import time","metadata":{"execution":{"iopub.status.busy":"2024-03-26T16:41:19.913384Z","iopub.execute_input":"2024-03-26T16:41:19.914096Z","iopub.status.idle":"2024-03-26T16:41:20.169106Z","shell.execute_reply.started":"2024-03-26T16:41:19.914055Z","shell.execute_reply":"2024-03-26T16:41:20.167817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Multi-temporal-temple-baalshamin\n\n\"The Temple of Baalshamin was an ancient temple in the city of Palmyra, Syria, dedicated to the Canaanite sky deity Baalshamin. The temple's earliest phase dates to the late 2nd century BC; its altar was built in 115 AD, and the temple was substantially rebuilt in 131 AD.\"\n\nhttps://en.wikipedia.org/wiki/Temple_of_Baalshamin","metadata":{}},{"cell_type":"code","source":"dataset = 'multi-temporal-temple-baalshamin'","metadata":{"execution":{"iopub.status.busy":"2024-03-26T17:01:44.489545Z","iopub.execute_input":"2024-03-26T17:01:44.490074Z","iopub.status.idle":"2024-03-26T17:01:44.497966Z","shell.execute_reply.started":"2024-03-26T17:01:44.490038Z","shell.execute_reply":"2024-03-26T17:01:44.496551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scene = 'images'\nsrc = f'/kaggle/input/image-matching-challenge-2024/train/{dataset}/{scene}'","metadata":{"execution":{"iopub.status.busy":"2024-03-26T17:01:59.400288Z","iopub.execute_input":"2024-03-26T17:01:59.400967Z","iopub.status.idle":"2024-03-26T17:01:59.408196Z","shell.execute_reply.started":"2024-03-26T17:01:59.400919Z","shell.execute_reply":"2024-03-26T17:01:59.406363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#By Leonid Kulyk https://www.kaggle.com/code/leonidkulyk/eda-imc-3d-plots-interactive-vis#-%F0%9F%8F%9B%EF%B8%8F-Image-Matching-Challenge---%F0%9F%93%8A-Exploratory-Data-Analysis\n\nlimit = 12\nimages = [cv2.cvtColor(cv2.imread(im), cv2.COLOR_BGR2RGB) for im in glob(f'{src}/*')[:limit]]\nmedia.show_images(images, height=300, columns=3)","metadata":{"execution":{"iopub.status.busy":"2024-03-26T17:04:15.124040Z","iopub.execute_input":"2024-03-26T17:04:15.124485Z","iopub.status.idle":"2024-03-26T17:04:18.199372Z","shell.execute_reply.started":"2024-03-26T17:04:15.124451Z","shell.execute_reply":"2024-03-26T17:04:18.196737Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Dioscuri\n\n\"Dioscuri, (Dioscuri from Greek Dioskouroi, “Sons of Zeus”), in Greek and Roman mythology, twin deities who succoured shipwrecked sailors and received sacrifices for favourable winds. They were the children of Leda and either Zeus, the king of the gods, or Tyndareus, Leda's mortal husband and the king of Lacedaemon.\"\n\nhttps://www.britannica.com/topic/Dioscuri","metadata":{}},{"cell_type":"code","source":"#By Leonid Kulyk https://www.kaggle.com/code/leonidkulyk/eda-imc-3d-plots-interactive-vis#-%F0%9F%8F%9B%EF%B8%8F-Image-Matching-Challenge---%F0%9F%93%8A-Exploratory-Data-Analysis\n\ndataset = 'dioscuri'","metadata":{"execution":{"iopub.status.busy":"2024-03-26T16:41:25.263926Z","iopub.execute_input":"2024-03-26T16:41:25.264373Z","iopub.status.idle":"2024-03-26T16:41:25.273502Z","shell.execute_reply.started":"2024-03-26T16:41:25.264340Z","shell.execute_reply":"2024-03-26T16:41:25.271096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scene = 'images'\nsrc = f'/kaggle/input/image-matching-challenge-2024/train/{dataset}/{scene}'","metadata":{"execution":{"iopub.status.busy":"2024-03-26T16:45:08.627542Z","iopub.execute_input":"2024-03-26T16:45:08.628021Z","iopub.status.idle":"2024-03-26T16:45:08.633670Z","shell.execute_reply.started":"2024-03-26T16:45:08.627984Z","shell.execute_reply":"2024-03-26T16:45:08.632152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#By Leonid Kulyk https://www.kaggle.com/code/leonidkulyk/eda-imc-3d-plots-interactive-vis#-%F0%9F%8F%9B%EF%B8%8F-Image-Matching-Challenge---%F0%9F%93%8A-Exploratory-Data-Analysis\n\nlimit = 12\nimages = [cv2.cvtColor(cv2.imread(im), cv2.COLOR_BGR2RGB) for im in glob(f'{src}/*')[:limit]]\nmedia.show_images(images, height=300, columns=3)","metadata":{"execution":{"iopub.status.busy":"2024-03-26T16:45:16.178139Z","iopub.execute_input":"2024-03-26T16:45:16.178594Z","iopub.status.idle":"2024-03-26T16:45:17.456551Z","shell.execute_reply.started":"2024-03-26T16:45:16.178561Z","shell.execute_reply":"2024-03-26T16:45:17.455061Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#That's the snippet to plot 3D when the files where txt. Plot 3D with Bin files?? Better ask Leonid: D","metadata":{}},{"cell_type":"code","source":"#By Leonid Kulyk https://www.kaggle.com/code/leonidkulyk/eda-imc-3d-plots-interactive-vis#-%F0%9F%8F%9B%EF%B8%8F-Image-Matching-Challenge---%F0%9F%93%8A-Exploratory-Data-Analysis\n\nrec_gt = pycolmap.Reconstruction(f'{dataset}/sfm')#Original was (f'{src}/sfm')\n\nfig = viz_3d.init_figure()\n# viz_3d.plot_cameras(fig, rec_gt, color='rgba(50,255,50, 0.5)', name=\"Ground Truth\", size=10)\nviz_3d.plot_reconstruction(fig, rec_gt, cameras = False, color='rgba(201,56,110,0.5)', name=\"Ground Truth\", cs=5)\nfig.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Acknowledgements:\n\nLeonid Kulyk https://www.kaggle.com/code/leonidkulyk/eda-imc-3d-plots-interactive-vis#-%F0%9F%8F%9B%EF%B8%8F-Image-Matching-Challenge---%F0%9F%93%8A-Exploratory-Data-Analysis\n","metadata":{}}]}