{"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":"from glob import glob\nimport pandas as pd","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-05-07T07:28:54.600705Z","iopub.execute_input":"2023-05-07T07:28:54.601087Z","iopub.status.idle":"2023-05-07T07:28:54.611307Z","shell.execute_reply.started":"2023-05-07T07:28:54.601054Z","shell.execute_reply":"2023-05-07T07:28:54.610282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Helper ","metadata":{}},{"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","metadata":{"execution":{"iopub.status.busy":"2023-05-07T07:45:29.978942Z","iopub.execute_input":"2023-05-07T07:45:29.979885Z","iopub.status.idle":"2023-05-07T07:45:29.987104Z","shell.execute_reply.started":"2023-05-07T07:45:29.979845Z","shell.execute_reply":"2023-05-07T07:45:29.986033Z"},"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","metadata":{"execution":{"iopub.status.busy":"2023-05-07T07:45:30.455601Z","iopub.execute_input":"2023-05-07T07:45:30.456231Z","iopub.status.idle":"2023-05-07T07:45:30.464444Z","shell.execute_reply.started":"2023-05-07T07:45:30.456195Z","shell.execute_reply":"2023-05-07T07:45:30.463273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# main\nGet the camera parameters corresponding to each image.","metadata":{}},{"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-07T07:45:32.027792Z","iopub.execute_input":"2023-05-07T07:45:32.028146Z","iopub.status.idle":"2023-05-07T07:45:34.649763Z","shell.execute_reply.started":"2023-05-07T07:45:32.028118Z","shell.execute_reply":"2023-05-07T07:45:34.648839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* We can see there is 2 different number of columns in camera_data and we don't know what the int number columns is.\n* If anyone knows, please let me know (^W^)","metadata":{}},{"cell_type":"markdown","source":"# Check function","metadata":{}},{"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-07T07:47:17.377899Z","iopub.execute_input":"2023-05-07T07:47:17.378445Z"},"trusted":true},"execution_count":null,"outputs":[]}]}