Skip to content

Commit

Permalink
updated scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
franioli committed Apr 8, 2024
1 parent 7d8af52 commit d8e2e78
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -27,53 +27,82 @@
")\n",
"from deep_image_matching.utils import (\n",
" OutputCapture,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
")\n",
"\n",
"# Define project directory\n",
"root_path = Path(\"sandbox/dense\")\n",
"root_path = Path(\"/home/francesco/phd/deep-image-matching/datasets/belv_20230725\")\n",
"\n",
"# Path to the images\n",
"image_dir = root_path / \"images\"\n",
"\n",
"# Path to the pre-computed COLMAP reconstuction with the knwon poses\n",
"sfm_path = root_path / \"sfm\"\n",
"sfm_path = root_path / \"results_superpoint+lightglue_bruteforce_quality_high\"\n",
"sfm_db_path = sfm_path / \"database.db\"\n",
"sfm_rec_path = sfm_path / \"reconstruction\"\n",
"\n",
"# Path to the dense matching results to be triangulated\n",
"dense_path = root_path / \"dense\"\n",
"dense_path = root_path / \"results_roma_bruteforce_quality_high.1\"\n",
"features_h5 = dense_path / \"features.h5\"\n",
"matches_h5 = dense_path / \"matches.h5\"\n",
"pair_file = dense_path / \"pairs.txt\"\n",
"\n",
"# Path to the output for the dense matching\n",
"dense_db_path = dense_path / \"database.db\"\n",
"model_path = dense_path / \"model\"\n",
"model_path.mkdir(exist_ok=True)"
"dense_db_path = dense_path / \"database_dense.db\"\n",
"model_path = dense_path / \"dense_model\"\n",
"model_path.mkdir(exist_ok=True, parents=True)\n",
"\n",
"# Do geometric verification of the dense features (with known camera poses)\n",
"do_geometric_verification = True\n",
"max_error = 4"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;33m2024-04-08 15:25:32 | [WARNING ] The database already exists, deleting it.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Importing keypoints: 100%|██████████| 2/2 [00:00<00:00, 96.12it/s]\n",
"Importing matches: 100%|██████████| 1/1 [00:00<00:00, 352.17it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;37m2024-04-08 15:25:33 | [INFO ] Performing geometric verification of the matches...\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:dim:The database already exists, deleting it.\n",
"Importing keypoints: 100%|██████████| 2/2 [00:00<00:00, 118.95it/s]\n",
"Importing matches: 100%|██████████| 1/1 [00:00<00:00, 359.07it/s]\n",
"INFO:dim:Performing geometric verification of the matches...\n",
"Importing verified matches: 100%|██████████| 1/1 [00:00<00:00, 1.22it/s]\n",
"INFO:dim:mean/med/min/max valid matches 68.09/68.09/68.09/68.09%.\n"
"\n",
"Importing verified matches: 100%|██████████| 1/1 [00:00<00:00, 1.17it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;37m2024-04-08 15:25:33 | [INFO ] mean/med/min/max valid matches 70.36/70.36/70.36/70.36%.\u001b[0m\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
Expand All @@ -88,53 +117,69 @@
"import_keypoints(features_h5, image_ids, dense_db_path)\n",
"\n",
"# Add matches to the database, but do not add two-view geometry\n",
"import_matches(matches_h5, image_ids, dense_db_path, pair_file, add_two_view_geometry=False)\n",
"import_matches(\n",
" matches_h5,\n",
" image_ids,\n",
" dense_db_path,\n",
" pair_file,\n",
" add_two_view_geometry=not do_geometric_verification,\n",
")\n",
"\n",
"\n",
"# Run the geometric verification with the knwon camera poses and add the inliers matches to the database in the two-view geometry table\n",
"import_verifed_matches(image_ids, sfm_rec, dense_db_path, features_h5, matches_h5, pair_file, max_error=4.0)"
"if do_geometric_verification:\n",
" # Run the geometric verification with the knwon camera poses and add the inliers matches to the database in the two-view geometry table\n",
" import_verifed_matches(\n",
" image_ids,\n",
" sfm_rec,\n",
" dense_db_path,\n",
" features_h5,\n",
" matches_h5,\n",
" pair_file,\n",
" max_error=max_error,\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"I20240330 16:27:56.156109 4158779 misc.cc:198] \n",
"I20240408 15:25:37.644026 2077708 misc.cc:198] \n",
"==============================================================================\n",
"Loading database\n",
"==============================================================================\n",
"I20240330 16:27:56.157060 4158779 database_cache.cc:54] Loading cameras...\n",
"I20240330 16:27:56.157088 4158779 database_cache.cc:64] 2 in 0.000s\n",
"I20240330 16:27:56.157095 4158779 database_cache.cc:72] Loading matches...\n",
"I20240330 16:27:56.157989 4158779 database_cache.cc:78] 1 in 0.001s\n",
"I20240330 16:27:56.158003 4158779 database_cache.cc:94] Loading images...\n",
"I20240330 16:27:56.196110 4158779 database_cache.cc:143] 2 in 0.038s (connected 2)\n",
"I20240330 16:27:56.196182 4158779 database_cache.cc:154] Building correspondence graph...\n",
"I20240330 16:27:56.239976 4158779 database_cache.cc:190] in 0.044s (ignored 0)\n",
"I20240330 16:27:56.240840 4158779 timer.cc:91] Elapsed time: 0.001 [minutes]\n",
"I20240330 16:27:56.259898 4158779 misc.cc:198] \n",
"I20240408 15:25:37.645126 2077708 database_cache.cc:54] Loading cameras...\n",
"I20240408 15:25:37.645164 2077708 database_cache.cc:64] 2 in 0.000s\n",
"I20240408 15:25:37.645174 2077708 database_cache.cc:72] Loading matches...\n",
"I20240408 15:25:37.646092 2077708 database_cache.cc:78] 1 in 0.001s\n",
"I20240408 15:25:37.646107 2077708 database_cache.cc:94] Loading images...\n",
"I20240408 15:25:37.679128 2077708 database_cache.cc:143] 2 in 0.033s (connected 2)\n",
"I20240408 15:25:37.679203 2077708 database_cache.cc:154] Building correspondence graph...\n",
"I20240408 15:25:37.706593 2077708 database_cache.cc:190] in 0.027s (ignored 0)\n",
"I20240408 15:25:37.707015 2077708 timer.cc:91] Elapsed time: 0.001 [minutes]\n",
"I20240408 15:25:37.717986 2077708 misc.cc:198] \n",
"==============================================================================\n",
"Triangulating image #1 (0)\n",
"==============================================================================\n",
"I20240330 16:27:56.259933 4158779 sfm.cc:473] => Image sees 0 / 127384 points\n",
"I20240330 16:27:56.617060 4158779 sfm.cc:478] => Triangulated 127379 points\n",
"I20240330 16:27:56.617122 4158779 misc.cc:198] \n",
"I20240408 15:25:37.718021 2077708 sfm.cc:473] => Image sees 0 / 131622 points\n",
"I20240408 15:25:38.029822 2077708 sfm.cc:478] => Triangulated 131620 points\n",
"I20240408 15:25:38.029877 2077708 misc.cc:198] \n",
"==============================================================================\n",
"Triangulating image #2 (1)\n",
"==============================================================================\n",
"I20240330 16:27:56.617130 4158779 sfm.cc:473] => Image sees 127379 / 127384 points\n",
"I20240330 16:27:56.628777 4158779 sfm.cc:478] => Triangulated 1 points\n",
"I20240330 16:27:56.628813 4158779 misc.cc:198] \n",
"I20240408 15:25:38.029884 2077708 sfm.cc:473] => Image sees 131620 / 131622 points\n",
"I20240408 15:25:38.041481 2077708 sfm.cc:478] => Triangulated 0 points\n",
"I20240408 15:25:38.041504 2077708 misc.cc:198] \n",
"==============================================================================\n",
"Retriangulation\n",
"==============================================================================\n",
"I20240330 16:27:56.655813 4158779 incremental_mapper.cc:175] => Completed observations: 0\n",
"I20240330 16:27:56.678421 4158779 incremental_mapper.cc:178] => Merged observations: 0\n",
"I20240330 16:27:56.687144 4158779 misc.cc:198] \n",
"I20240408 15:25:38.054045 2077708 incremental_mapper.cc:175] => Completed observations: 0\n",
"I20240408 15:25:38.064352 2077708 incremental_mapper.cc:178] => Merged observations: 0\n",
"I20240408 15:25:38.069828 2077708 misc.cc:198] \n",
"==============================================================================\n",
"Bundle adjustment\n",
"==============================================================================\n"
Expand All @@ -145,31 +190,31 @@
"output_type": "stream",
"text": [
"iter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time\n",
" 0 6.656609e+04 0.00e+00 1.48e+03 0.00e+00 0.00e+00 1.00e+04 0 9.13e-02 3.32e-01\n",
" 1 6.409387e+04 2.47e+03 1.46e-01 2.12e-01 1.00e+00 3.00e+04 0 1.09e-01 4.42e-01\n"
" 0 6.183404e+04 0.00e+00 1.44e+03 0.00e+00 0.00e+00 1.00e+04 0 8.18e-02 3.27e-01\n",
" 1 5.939892e+04 2.44e+03 1.43e-01 2.36e-01 1.00e+00 3.00e+04 0 1.15e-01 4.43e-01\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"I20240330 16:27:57.335784 4158779 misc.cc:205] \n",
"I20240408 15:25:38.691607 2077708 misc.cc:205] \n",
"Bundle adjustment report\n",
"------------------------\n",
"I20240330 16:27:57.335851 4158779 bundle_adjustment.cc:942] \n",
" Residuals : 509520\n",
" Parameters : 382140\n",
"I20240408 15:25:38.691670 2077708 bundle_adjustment.cc:942] \n",
" Residuals : 526480\n",
" Parameters : 394860\n",
" Iterations : 2\n",
" Time : 0.471104 [s]\n",
" Initial cost : 0.361448 [px]\n",
" Final cost : 0.354673 [px]\n",
" Time : 0.46784 [s]\n",
" Initial cost : 0.342707 [px]\n",
" Final cost : 0.335891 [px]\n",
" Termination : Convergence\n",
"\n",
"I20240330 16:27:57.367061 4158779 incremental_mapper.cc:175] => Completed observations: 0\n",
"I20240330 16:27:57.386754 4158779 incremental_mapper.cc:178] => Merged observations: 0\n",
"I20240330 16:27:57.429034 4158779 incremental_mapper.cc:160] => Filtered observations: 0\n",
"I20240330 16:27:57.429075 4158779 sfm.cc:521] => Changed observations: 0.000000\n",
"I20240330 16:27:57.546033 4158779 misc.cc:198] \n",
"I20240408 15:25:38.706387 2077708 incremental_mapper.cc:175] => Completed observations: 0\n",
"I20240408 15:25:38.717056 2077708 incremental_mapper.cc:178] => Merged observations: 0\n",
"I20240408 15:25:38.741540 2077708 incremental_mapper.cc:160] => Filtered observations: 0\n",
"I20240408 15:25:38.741565 2077708 sfm.cc:521] => Changed observations: 0.000000\n",
"I20240408 15:25:38.834072 2077708 misc.cc:198] \n",
"==============================================================================\n",
"Extracting colors\n",
"==============================================================================\n"
Expand All @@ -194,6 +239,17 @@
" options=opt,\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# Export the model in ply and bundler format\n",
"reconstruction.export_PLY(model_path / \"dense_model.ply\")\n",
"reconstruction.export_bundler(model_path / \"bundler.out\", model_path / \"bunlder_list.txt\", skip_distortion=True)"
]
}
],
"metadata": {
Expand Down
13 changes: 13 additions & 0 deletions scripts/reconstruction_to_bunlder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pathlib import Path

import pycolmap

rec_dir = Path(
"/home/francesco/phd/deep-image-matching/datasets/belv_20230725/results_superpoint+lightglue_bruteforce_quality_high/reconstruction"
)
rec = pycolmap.Reconstruction(rec_dir)
rec.export_bundler(
rec_dir / "bunlder.out",
rec_dir / "bundler_list.txt",
skip_distortion=True,
)

0 comments on commit d8e2e78

Please sign in to comment.