{"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":8143495,"sourceType":"competition"}],"dockerImageVersionId":30698,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Image Matching Data View\n### in case of church 00111.png","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport cv2\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom matplotlib import animation, rc\nrc('animation', html='jshtml')","metadata":{"execution":{"iopub.status.busy":"2024-05-05T05:08:28.134331Z","iopub.execute_input":"2024-05-05T05:08:28.134826Z","iopub.status.idle":"2024-05-05T05:08:28.141330Z","shell.execute_reply.started":"2024-05-05T05:08:28.134784Z","shell.execute_reply":"2024-05-05T05:08:28.140004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# sfm data\n---","metadata":{}},{"cell_type":"markdown","source":"# Camera list with one line of data per camera:\n####   CAMERA_ID, MODEL, WIDTH, HEIGHT, PARAMS[]\n#### Number of cameras: 110","metadata":{}},{"cell_type":"code","source":"cameras=pd.read_csv('/kaggle/input/image-matching-challenge-2024/train/church/sfm/cameras.txt',skiprows=3, header=None)\nprint(len(cameras))\ndisplay(cameras[0:3])\n\nfor i in range(1):\n    text=cameras.iloc[i,0].split(' ')\n    print(len(text),text[0:20])\n    print()","metadata":{"execution":{"iopub.status.busy":"2024-05-05T05:08:28.143417Z","iopub.execute_input":"2024-05-05T05:08:28.143841Z","iopub.status.idle":"2024-05-05T05:08:28.163375Z","shell.execute_reply.started":"2024-05-05T05:08:28.143809Z","shell.execute_reply":"2024-05-05T05:08:28.162229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Image list with two lines of data per image:\n####   IMAGE_ID, QW, QX, QY, QZ, TX, TY, TZ, CAMERA_ID, NAME\n####   POINTS2D[] as (X, Y, POINT3D_ID)\n#### Number of images: 110, mean observations per image: 5381.9636363636364","metadata":{}},{"cell_type":"code","source":"imagestxt=pd.read_csv('/kaggle/input/image-matching-challenge-2024/train/church/sfm/images.txt',skiprows=4, header=None)\nprint(len(imagestxt))\ndisplay(imagestxt[0:4])\n\nfor i in range(2):\n    text=imagestxt.iloc[i,0].split(' ')\n    print(len(text),text[0:20])\n    print()","metadata":{"execution":{"iopub.status.busy":"2024-05-05T05:08:28.164831Z","iopub.execute_input":"2024-05-05T05:08:28.165293Z","iopub.status.idle":"2024-05-05T05:08:28.501348Z","shell.execute_reply.started":"2024-05-05T05:08:28.165218Z","shell.execute_reply":"2024-05-05T05:08:28.500289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3D point list with one line of data per point:\n####   POINT3D_ID, X, Y, Z, R, G, B, ERROR, TRACK[] as (IMAGE_ID, POINT2D_IDX)\n#### Number of points: 117048, mean track length: 5.0578907798510011","metadata":{}},{"cell_type":"code","source":"points=pd.read_csv('/kaggle/input/image-matching-challenge-2024/train/church/sfm/points3D.txt',skiprows=3, header=None)\nprint(len(points))\ndisplay(points[0:2])\n\nfor i in range(4):\n    text=points.iloc[i,0].split(' ')\n    print(len(text),text[0:20])\n    print()","metadata":{"execution":{"iopub.status.busy":"2024-05-05T05:11:58.631142Z","iopub.execute_input":"2024-05-05T05:11:58.631551Z","iopub.status.idle":"2024-05-05T05:11:58.950092Z","shell.execute_reply.started":"2024-05-05T05:11:58.631518Z","shell.execute_reply":"2024-05-05T05:11:58.948988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categories=pd.read_csv('/kaggle/input/image-matching-challenge-2024/train/categories.csv')\ndisplay(categories.iloc[0])","metadata":{"execution":{"iopub.status.busy":"2024-05-05T05:09:52.315456Z","iopub.execute_input":"2024-05-05T05:09:52.316495Z","iopub.status.idle":"2024-05-05T05:09:52.328314Z","shell.execute_reply.started":"2024-05-05T05:09:52.316457Z","shell.execute_reply":"2024-05-05T05:09:52.327143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels=pd.read_csv('/kaggle/input/image-matching-challenge-2024/train/train_labels.csv')\ntrain_labels2=train_labels[train_labels['scene']=='church']\ndisplay(train_labels2.iloc[-1].tolist())","metadata":{"execution":{"iopub.status.busy":"2024-05-05T05:09:39.102695Z","iopub.execute_input":"2024-05-05T05:09:39.103139Z","iopub.status.idle":"2024-05-05T05:09:39.127371Z","shell.execute_reply.started":"2024-05-05T05:09:39.103105Z","shell.execute_reply":"2024-05-05T05:09:39.126099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# images\n---","metadata":{}},{"cell_type":"code","source":"paths=[]\nfor dirname, _, filenames in os.walk('/kaggle/input/image-matching-challenge-2024/train/church/images'):\n    for filename in filenames:\n        if filename[-4:]=='.png':\n            paths+=[os.path.join(dirname, filename)]\npaths=sorted(paths)\nprint(paths[0:3])\nprint(len(paths))\n\nimages=[]\nfor path in paths:\n    image = cv2.imread(path)\n    image = cv2.resize(image,dsize=(200,200))\n    images+=[image]\n","metadata":{"execution":{"iopub.status.busy":"2024-05-05T05:08:28.884621Z","iopub.execute_input":"2024-05-05T05:08:28.885037Z","iopub.status.idle":"2024-05-05T05:08:33.062214Z","shell.execute_reply.started":"2024-05-05T05:08:28.885000Z","shell.execute_reply":"2024-05-05T05:08:33.061212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 00111.png\n\nimage = cv2.imread('/kaggle/input/image-matching-challenge-2024/train/church/images/00111.png')\nplt.imshow(image)\nplt.show()\nprint(image.shape)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndef create_animation(ims):\n    fig=plt.figure(figsize=(16,8))\n    im=plt.imshow(cv2.cvtColor(ims[0],cv2.COLOR_BGR2RGB))\n    text = plt.text(0.05, 0.05, f'Slide {0}', transform=fig.transFigure, fontsize=14, color='blue')\n    plt.axis('off')\n    plt.close()\n\n    def animate_func(i):\n        im.set_array(cv2.cvtColor(ims[i],cv2.COLOR_BGR2RGB))\n        text.set_text(f'Slide {i}')        \n        return [im]    \n    \n    return animation.FuncAnimation(fig, animate_func, frames=len(ims), interval=1000//3)\n\ncreate_animation(np.array(images))","metadata":{"execution":{"iopub.status.busy":"2024-05-05T05:08:33.123679Z","iopub.status.idle":"2024-05-05T05:08:33.124253Z","shell.execute_reply.started":"2024-05-05T05:08:33.123947Z","shell.execute_reply":"2024-05-05T05:08:33.123971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}