{"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":"# 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","execution":{"iopub.status.busy":"2023-05-08T06:21:16.126305Z","iopub.execute_input":"2023-05-08T06:21:16.126671Z","iopub.status.idle":"2023-05-08T06:21:20.017711Z","shell.execute_reply.started":"2023-05-08T06:21:16.126641Z","shell.execute_reply":"2023-05-08T06:21:20.015905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from glob import glob\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2023-05-08T06:21:45.935628Z","iopub.execute_input":"2023-05-08T06:21:45.936081Z","iopub.status.idle":"2023-05-08T06:21:45.942864Z","shell.execute_reply.started":"2023-05-08T06:21:45.936046Z","shell.execute_reply":"2023-05-08T06:21:45.941833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_cameras_data(path):\n    path=path+\"/cameras.txt\"\n    with open(path) as f:\n        camera_data=f.read().split(\"\\n\")\n        if len(camera_data[-1])<3:\n            camera_data=camera_data[:-1]\n\n    camera_data=pd.DataFrame([x.split(\" \") for x in camera_data if x[0]!=\"#\"])\n    camera_data.columns=[\"camera_id\",\"model\",\"H\",\"W\"]+[f\"p{i}\" for i in range(len(camera_data.columns)-5)]+[\"prior_focal_length\"]#may is H and W \n    #camera_data\n    return camera_data\n","metadata":{"execution":{"iopub.status.busy":"2023-05-08T06:22:01.134153Z","iopub.execute_input":"2023-05-08T06:22:01.134662Z","iopub.status.idle":"2023-05-08T06:22:01.144327Z","shell.execute_reply.started":"2023-05-08T06:22:01.134624Z","shell.execute_reply":"2023-05-08T06:22:01.143202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_images_data(path):\n    path=path+\"/images.txt\"\n    images_data_raw=pd.read_csv(path)\n    images_data_raw=images_data_raw.index\n    images_data_raw=images_data_raw.to_numpy()\n    try:\n        #print(images_data_raw.shape)\n        images_data=[x[0] for x in images_data_raw if x[0][0]!=\"#\"]\n    except:\n        images_data_raw=pd.read_csv(path).to_numpy()[:,0]\n        #images_data_raw=[x.split(\" \") for x in images_data_raw]\n        #print(path)\n        #print(images_data_raw.shape)\n        #input(images_data_raw[0])\n        images_data=[x for x in images_data_raw if x[0]!=\"#\"]#there may be is bug\n\n    images_data=[x for x in images_data if len(x)<1000]\n    images_data=[x.split(\" \") for x in images_data]\n    images_data=pd.DataFrame(images_data)\n    images_data=images_data[[8,9]]\n    images_data.columns=[\"camera_id\",\"image_path\"]\n    #print(images_data)\n    return images_data\n","metadata":{"execution":{"iopub.status.busy":"2023-05-08T06:22:33.338038Z","iopub.execute_input":"2023-05-08T06:22:33.338412Z","iopub.status.idle":"2023-05-08T06:22:33.347184Z","shell.execute_reply.started":"2023-05-08T06:22:33.338382Z","shell.execute_reply":"2023-05-08T06:22:33.346000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"paths=glob(\"/kaggle/input/image-matching-challenge-2023/train/**/**/sfm\",recursive=True)\nfor i,path in enumerate(paths[:2]):\n    images_data=get_images_data(path)\n    camera_data=get_cameras_data(path)\n    data=pd.merge(images_data,camera_data,on=\"camera_id\")\n    print(\"data_shape\",data.shape)\n    print(data)","metadata":{"execution":{"iopub.status.busy":"2023-05-08T06:22:49.498749Z","iopub.execute_input":"2023-05-08T06:22:49.499144Z","iopub.status.idle":"2023-05-08T06:22:57.011176Z","shell.execute_reply.started":"2023-05-08T06:22:49.499115Z","shell.execute_reply":"2023-05-08T06:22:57.009930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(paths))\nfor i,path in enumerate(paths):\n    images_data=get_images_data(path)\n    camera_data=get_cameras_data(path)\n    data=pd.merge(images_data,camera_data,on=\"camera_id\")\n    print(\"data_shape\",data.shape)","metadata":{"execution":{"iopub.status.busy":"2023-05-08T06:23:10.576066Z","iopub.execute_input":"2023-05-08T06:23:10.577358Z","iopub.status.idle":"2023-05-08T06:31:09.411751Z","shell.execute_reply.started":"2023-05-08T06:23:10.577315Z","shell.execute_reply":"2023-05-08T06:31:09.409675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}