Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconstruction of sparse model from known camera poses gives few 3D points #497

Closed
definability opened this issue Oct 18, 2018 · 9 comments

Comments

@definability
Copy link

definability commented Oct 18, 2018

I use a calibration object to know positions and directions of cameras in my static rig.
Then, I try to follow the instruction Reconstruct sparse/dense model from known camera poses.
My OS is Xubuntu 18.04.

First, I create a sparse model with cameras' positions

  • I convert binary sparse model files to text
colmap model_converter \
    --input_path calibration/sparse/ \
    --output_path calibration/cameras \
    --output_type TXT
  • I make points3D.txt file blank, because the instruction says The points3D.txt file should be empty
  • In images.txt I clean lines that contain information about points; though, it was not clear for me: FAQ says every other line in the images.txt should also be empty without specifying what every other line means (should it be clarified in FAQ?)
  • I leave cameras.txt file untouched

Then, I extract and match features without any problems

colmap feature_extractor \
    --image_path model_images/ \
    --database_path output/db.db \
    --SiftExtraction.max_image_size 4096 \
    --SiftExtraction.max_num_features 16384 \
    --SiftExtraction.estimate_affine_shape 1 \
    --SiftExtraction.domain_size_pooling 1 \
    
colmap exhaustive_matcher \
    --database_path output/db.db \
    --SiftMatching.guided_matching 1

Note that model_images are not the same as were used for camera calibration.

Finally, triangulation fails

colmap point_triangulator \
    --database_path output/db.db \
    --image_path model_images/ \
    --input_path calibration/cameras/ \
    --output_path output/triangulated

I caught an error caused by different identifiers of images between calibration sparse model and new model that I want to reconstruct

==============================================================================
Loading database
==============================================================================

Loading cameras... 24 in 0.000s
Loading matches... 32 in 0.000s
Loading images... 24 in 0.004s (connected 20)
Building correspondence graph... in 0.001s (ignored 0)

Elapsed time: 0.000 [minutes]

F1018 10:55:52.417294   460 reconstruction.cc:81] Check failed: existing_image.Name() == image.second.Name() (17.JPG vs. 16.JPG) 
*** Check failure stack trace: ***
    @     0x7f941eb240cd  google::LogMessage::Fail()
    @     0x7f941eb25f33  google::LogMessage::SendToLog()
    @     0x7f941eb23c28  google::LogMessage::Flush()
    @     0x7f941eb26999  google::LogMessageFatal::~LogMessageFatal()
    @     0x560163359977  (unknown)
    @     0x5601634be763  (unknown)
    @     0x5601632ba0d4  (unknown)
    @     0x5601632ac545  (unknown)
    @     0x7f941a400b97  __libc_start_main
    @     0x5601632b622a  (unknown)
Aborted (core dumped)

I've changed ids by hand and got very few points triangulated

==============================================================================
Loading database                                                                                                                  
==============================================================================                                                           
                                                                                                           
Loading cameras... 24 in 0.000s                                                                            
Loading matches... 26 in 0.000s                                                                            
Loading images... 24 in 0.008s (connected 19)                                                              
Building correspondence graph... in 0.002s (ignored 0)                                                     
                                                                                                           
Elapsed time: 0.000 [minutes]                                                                              
                                                                                                           
                                                                                                           
==============================================================================                                         
Triangulating image #16                                                       
==============================================================================
                                                                              
  => Image has 0 / 526 points                                                 
  => Triangulated 141 points                                                  
                                                                              
==============================================================================
Triangulating image #13                                                       
==============================================================================
                                                                              
  => Image has 0 / 298 points                                                 
  => Triangulated 54 points                                                   
                                                                              
==============================================================================
Triangulating image #15                                                       
==============================================================================
                                                                                                           
  => Image has 0 / 309 points                                                                              
  => Triangulated 26 points                                                                                
                                                                                                           
==============================================================================                             
Triangulating image #14                                                                                    
==============================================================================                             
                                                                                                           
  => Image has 2 / 168 points                                                 
  => Triangulated 5 points                                                    
                                                                              
==============================================================================
Triangulating image #12                                                       
==============================================================================
                                                                              
  => Image has 0 / 835 points                                                 
  => Triangulated 209 points                                                  
                                                                              
==============================================================================                                                    
Triangulating image #11                                                                                                                  
==============================================================================                             
                                                                                                           
  => Image has 0 / 0 points                                                                                
  => Triangulated 0 points                                                                                 

==============================================================================
Triangulating image #10
==============================================================================

  => Image has 0 / 0 points
  => Triangulated 0 points

==============================================================================
Triangulating image #9
==============================================================================

  => Image has 0 / 394 points
  => Triangulated 118 points

==============================================================================
Triangulating image #18
==============================================================================

  => Image has 13 / 118 points
  => Triangulated 19 points

==============================================================================
Triangulating image #4
==============================================================================

  => Image has 102 / 859 points
  => Triangulated 75 points

==============================================================================
Triangulating image #20
==============================================================================

  => Image has 0 / 0 points
  => Triangulated 0 points

==============================================================================
Triangulating image #1
==============================================================================

  => Image has 0 / 233 points
  => Triangulated 0 points

==============================================================================
Triangulating image #22
==============================================================================

  => Image has 0 / 0 points
  => Triangulated 0 points

==============================================================================
Triangulating image #3
==============================================================================

  => Image has 113 / 933 points
  => Triangulated 79 points

==============================================================================
Triangulating image #21
==============================================================================

  => Image has 0 / 146 points
  => Triangulated 20 points

==============================================================================
Triangulating image #5
==============================================================================

  => Image has 90 / 669 points
  => Triangulated 74 points

==============================================================================
Triangulating image #23
==============================================================================

  => Image has 0 / 99 points
  => Triangulated 12 points

==============================================================================
Triangulating image #6
==============================================================================

  => Image has 173 / 971 points
  => Triangulated 88 points

==============================================================================
Triangulating image #24
==============================================================================

  => Image has 0 / 233 points
  => Triangulated 0 points

==============================================================================
Triangulating image #8
==============================================================================

  => Image has 175 / 780 points
  => Triangulated 14 points

==============================================================================
Triangulating image #19
==============================================================================

  => Image has 104 / 707 points
  => Triangulated 89 points

==============================================================================
Triangulating image #2
==============================================================================

  => Image has 25 / 463 points
  => Triangulated 9 points

==============================================================================
Triangulating image #17
==============================================================================

  => Image has 0 / 0 points
  => Triangulated 0 points

==============================================================================
Triangulating image #7
==============================================================================

  => Image has 9 / 292 points
  => Triangulated 30 points
  => Merged observations: 0
  => Completed observations: 15

Surface I want to reconstruct has not a lot of SIFT matches, so the procedure provides bad sparse point cloud, and patch match processes only 16 images of 24.

If I avoid triangulation and use result of sparse reconstruction of calibration object in patch match procedure, I have all 24 images processed and dense reconstruction result is much more complete.

colmap image_undistorter \
    --input_path calibration/sparse/ \
    --image_path model_images/ \
    --output_path output/
colmap patch_match_stereo \
    --PatchMatchStereo.geom_consistency 1 \
    --workspace_path output/

Am I doing all right?
I have an assumption that my calibration object is similar to scanned objects in that sense that they have the same neighboring images and direct reconstruction of dense point cloud works fine.
Though, it's strange: I use calibration object just because I cannot match features of another images well, and, according to FAQ, I should use features matching to use calibration object.

@definability definability changed the title Triangulation fails during reconstruction of sparse model from known camera poses Reconstruction of sparse model from known camera poses gives few 3D points Oct 18, 2018
@ahojnnes
Copy link
Contributor

ahojnnes commented Oct 22, 2018 via email

@definability
Copy link
Author

@ahojnnes, got it. Thank you!

@ivanfarevalo
Copy link

ivanfarevalo commented Nov 10, 2018

Hello!
I have been trying to do exactly this but I haven't been able to. I get the same error as char-lie. Hopefully one of you is able to help me.
This is the steps I have taken.

  1. Make sparse model of calibration item
  2. Convert model to TXT format just like mentioned above.
  3. Copy images.txt, cameras.txt, and 3Dpoints.txt to my new model folder (DATASET_PATH)
  4. Leave cameras.txt untouched, erase all data in 3Dpoint.txt, and erase every other line in images.txt so only
    # IMAGE_ID, QW, QX, QY, QZ, TX, TY, TZ, CAMERA_ID, NAME
    lines are left, with a blank line in between as such:
# Image list with two lines of data per image:
#   IMAGE_ID, QW, QX, QY, QZ, TX, TY, TZ, CAMERA_ID, NAME
#   POINTS2D[] as (X, Y, POINT3D_ID)
# Number of images: 100, mean observations per image: 952.95
100 0.989123 0.0712152 -0.114599 -0.0585765 -0.0102577 -1.16044 3.1816 100 image99.jpg

99 0.984757 -0.143058 -0.0987996 -0.0052357 0.19831 -2.07697 4.13605 98 image97.jpg

98 0.990242 -0.055276 -0.120138 -0.0439669 -0.131827 -1.82626 3.39713 99 image98.jpg

97 0.949651 0.308238 -0.00655007 0.0557715 0.10588 -1.0627 2.41078 97 image96.jpg

96 0.997251 0.0739932 -0.00246529 -0.0029146 -0.0276835 -1.16819 3.17813 96 image95.jpg
  1. Run feature extractor and exhaustive matcher in new model folder which creates its new its own database.
DATASET_PATH=$(pwd)
colmap feature_extractor \
--database_path $DATASET_PATH/database.db \
--image_path $DATASET_PATH/images \
--SiftExtraction.max_image_size 3280 \
--SiftExtraction.estimate_affine_shape 1 \
--SiftExtraction.domain_size_pooling 1
colmap exhaustive_matcher \
--database_path $DATASET_PATH/database.db \
--SiftMatching.multiple_models 1 \
--SiftMatching.guided_matching 1 \
--ExhaustiveMatching.block_size 20
mkdir $DATASET_PATH/sparse
  1. Finally run mapper command
colmap mapper \
--database_path $DATASET_PATH/database.db \
--image_path $DATASET_PATH/images \
--input_path $DATASET_PATH
--output_path $DATASET_PATH/sparse

But I end up getting this error

Loading cameras... 100 in 0.000s
Loading matches... 1868 in 0.010s
Loading images... 100 in 0.017s (connected 100)
Building correspondence graph... in 0.112s (ignored 0)

Elapsed time: 0.002 [minutes]

F1109 16:23:19.704193 37228544 reconstruction.cc:81] Check failed: existing_image.Name() == image.second.Name() (image98.jpg vs. image95.jpg) 
*** Check failure stack trace: ***
    @        0x10bb19efd  google::LogMessage::SendToLog()
    @        0x10bb1a677  google::LogMessage::Flush()
    @        0x10bb1dbf7  google::LogMessageFatal::~LogMessageFatal()
    @        0x10bb1af89  google::LogMessageFatal::~LogMessageFatal()
    @        0x10b06bb05  colmap::Reconstruction::Load()
    @        0x10b28e324  colmap::IncrementalMapper::BeginReconstruction()
    @        0x10b0b9dfb  colmap::IncrementalMapperController::Reconstruct()
    @        0x10b0b9634  colmap::IncrementalMapperController::Run()
    @        0x10b3a9d3d  colmap::Thread::RunFunc()
    @        0x10b3abb3e  _ZNSt3__114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN6colmap6ThreadEFvvEPS8_EEEEEPvSD_
    @     0x7fff6c76b6c1  _pthread_body
    @     0x7fff6c76b56d  _pthread_start
Abort trap: 6

I have tried this with a different set of images (same quantity and name) as well as with a copy of the original calibration model folder, (same pictures) but have not had success.

I would greatly appreciate it I could get some feedback on what I'm doing incorrectly.
Also wondering :

  1. Is it correct to create a new data base with the new set of pictures or should I be using the database from the calibration model and modifying it somehow?
  2. Am I modifying images.txt correctly?
  3. Why would I be getting an error even when performing these steps on the same calibration model images?

Thanks in Advance !

@definability
Copy link
Author

@pilafniev, have you opened a database with features fetched on step 6 (resulting database $DATASET_PATH/database.db after mapper command run) and checked ids of all images?
You can do this by running colmap gui, there you create a new project and Open an existing database

Steps to open database

Then, you select directory with images in usual way and click Save.

Finally, you click Database management button (located to the right from Feature extraction and Feature matching) and see names of images and their identifiers

image

In this case ids are the same as names, but they may differ like in your case.
For example, in your images.txt file you have an image image97.
Its id is 99 (the first number in the row).

99 0.984757 -0.143058 -0.0987996 -0.0052357 0.19831 -2.07697 4.13605 98 image97.jpg

If you had few images (in my case 7), you could edit the images.txt file manually and specify the same ids like in database.db.
Though, if you have a lot of them, you should probably write a script that loads the database using SQLite driver and change identifiers automatically.

Though, for the start I'd recommend to use 5-10 images to reconstruct a part of the object and check whether it works.

@ivanfarevalo
Copy link

Thanks for the quick response Char-lie!
I did have some mismatched image id's.. which were causing the error. While on the subject, what other tools or advise would you recommend for modeling differences between objects? I want to model 2 very similar objects with a very small variation between them, but when transitioning from one model to the other I would like for only the differences to be noticeable in the transition and keep everything else static. I'd appreciate any feedback on the subject, thanks again!

@definability
Copy link
Author

@pilafniev, let's chat under the gist https://gist.github.com/char-lie/61d74885eaf4d62fcf1b959f7f7947d5 to not add noise to this topic. Add a comment there for me to know that you're there.

@HareshKarnan
Copy link

i had the same issue, and figured out that the images need to saved as 001.png and not 1.png

If you're using python, you can use the zfill inbuilt function to solve this

@chenhao2015
Copy link

chenhao2015 commented Nov 11, 2022

Hi, @ahojnnes , @Char-lie

May I inquire what does it mean "make sure that the images.txt contains exactly the same image observations as listed in the keypoints table in the database." I also meet the problem "Reconstruction of sparse model from known camera poses gives few 3D points". I only got 50 points.

The images.txt is as follow:

IMAGE_ID, QW, QX, QY, QZ, TX, TY, TZ, CAMERA_ID, NAME

17 -0.50659437247277972 0.55052513676466619 -0.45108488725187412 0.48662782499783158 -608.04364158215401 7978.9498298370399 94.003846592845406 1 st_2423083900_v.JPG

15 -0.4497561703953718 0.5969986891298632 -0.38752224897079829 0.53957247791295748 -2346.0030574711 7648.31798122905 92.371038992067895 1 st_2423034734_v.JPG

9 -0.45956632164037281 0.5895321758506763 -0.39843648277114785 0.5315063300165499 -2063.2478187449001 7729.7733057866099 92.642837708446294 1 st_2423042925_v.JPG

8 -0.46924565599851153 0.58239497385672245 -0.40920897652013133 0.52265918368311559 -1777.6716047806599 7800.7683387683301 92.914347934454995 1 st_2423051150_v.JPG

12 -0.47881288267613653 0.57472086727237326 -0.41998485828289062 0.51385490843054116 -1486.2603659445399 7861.8535223339204 93.188756560923807 1 st_2423059309_v.JPG

11 -0.4972975087138265 0.55880975957656775 -0.44090479827627949 0.49601391037545867 -904.46557818347105 7950.4853809752403 93.730320296270605 1 st_2423075725_v.JPG

13 -0.48838958980223929 0.56678683271738806 -0.43020307884675268 0.50512731640821684 -1196.1855375164 7911.5244862078898 93.459683206173693 1 st_2423067517_v.JPG

14 -0.439574774950997 0.60414463403607999 -0.37635488497863945 0.5478505991097451 -2628.82222213456 7555.3728232480298 92.095748034546801 1 st_2423026558_v.JPG

10 -0.42920335667870357 0.61088928620139382 -0.36544731777438866 0.55591997315404151 -2904.74547910302 7453.2263306479399 91.823366802318404 1 st_2423018350_v.JPG

16 -0.41915468823294588 0.61737186570053704 -0.35428408332676081 0.56359925042098558 -3176.7070670816202 7340.9980907996396 91.5506949450631 1 st_2423010158_v.JPG

4 -0.47365767413122345 0.57932208897761073 -0.40295487621330417 0.52693613720747767 -1899.5921860780199 8143.5876022913299 -62.046288852337398 1 st_2417467070_v.JPG

7 -0.42660614932218549 0.61193195413991019 -0.35151436874362707 0.56567139350490192 -3283.2491229912298 7718.1074907059901 -62.005701965793101 1 st_2417428662_v.JPG

2 -0.40630252888014495 0.62360516953504219 -0.33038122047090523 0.58041631327429566 -3812.4369487051299 7482.14100189689 -61.985111308764701 1 st_2417413276_v.JPG

3 -0.43560676142711213 0.60553875913312194 -0.36226190251206869 0.55887017685222606 -3013.0987239098399 7822.1459710626596 -62.015056892611803 1 st_2417436347_v.JPG

1 -0.44548926570088909 0.59974982261659326 -0.37250492111360067 0.55052660985895852 -2739.67865548605 7916.7332842431597 -62.023784850428903 1 st_2417444032_v.JPG

6 -0.45530848563867965 0.59264598217603637 -0.3825912880808246 0.54322079212845753 -2459.8477205013501 8002.7697399321196 -62.031983205063298 1 st_2417451717_v.JPG

5 -0.46412311872366369 0.5861834984075629 -0.39312774673920109 0.53519081793753642 -2180.8524531511398 8078.0399461260804 -62.0394494954908 1 st_2417459402_v.JPG

My commands:
colmap feature_extractor --image_path /home/haochen/NeRF/report/images --database_path /home/haochen/NeRF/report/database.db --SiftExtraction.max_image_size 4096 --SiftExtraction.max_num_features 16384 --SiftExtraction.estimate_affine_shape 1 --SiftExtraction.domain_size_pooling 1 --ImageReader.camera_model SIMPLE_PINHOLE --ImageReader.single_camera 1

colmap exhaustive_matcher --database_path /home/haochen/NeRF/report/database.db --SiftMatching.guided_matching 1

colmap point_triangulator --database_path /home/haochen/NeRF/report/database.db --image_path /home/haochen/NeRF/report/images --input_path /home/haochen/NeRF/report/sparse/created/model --output_path /home/haochen/NeRF/report/sparse/model

Please see the following logs of point_triangulator .

==============================================================================
Loading model

==============================================================================
Loading database

Loading cameras... 1 in 0.000s
Loading matches... 136 in 0.001s
Loading images... 17 in 0.001s (connected 17)
Building correspondence graph... in 0.008s (ignored 0)

Elapsed time: 0.000 [minutes]

==============================================================================
Triangulating image #17 (0)

=> Image sees 0 / 1478 points
=> Triangulated 0 points

==============================================================================
Triangulating image #15 (1)

=> Image sees 665 / 1765 points
=> Triangulated 877 points

==============================================================================
Triangulating image #9 (2)

=> Image sees 1235 / 1720 points
=> Triangulated 264 points

==============================================================================
Triangulating image #8 (3)

=> Image sees 1022 / 1684 points
=> Triangulated 110 points

==============================================================================
Triangulating image #12 (4)

=> Image sees 1171 / 1642 points
=> Triangulated 79 points

==============================================================================
Triangulating image #11 (5)

=> Image sees 246 / 1579 points
=> Triangulated 26 points

==============================================================================
Triangulating image #13 (6)

=> Image sees 845 / 1589 points
=> Triangulated 29 points

==============================================================================
Triangulating image #14 (7)

=> Image sees 1410 / 1799 points
=> Triangulated 153 points

==============================================================================
Triangulating image #10 (8)

=> Image sees 1529 / 1803 points
=> Triangulated 127 points

==============================================================================
Triangulating image #16 (9)

=> Image sees 1419 / 1811 points
=> Triangulated 166 points

==============================================================================
Triangulating image #4 (10)

=> Image sees 1311 / 1518 points
=> Triangulated 38 points

==============================================================================
Triangulating image #7 (11)

=> Image sees 427 / 1634 points
=> Triangulated 52 points

==============================================================================
Triangulating image #2 (12)

=> Image sees 0 / 1529 points
=> Triangulated 0 points

==============================================================================
Triangulating image #3 (13)

=> Image sees 1521 / 1646 points
=> Triangulated 18 points

==============================================================================
Triangulating image #1 (14)

=> Image sees 1451 / 1595 points
=> Triangulated 40 points

==============================================================================
Triangulating image #6 (15)

=> Image sees 1416 / 1559 points
=> Triangulated 27 points

==============================================================================
Triangulating image #5 (16)

=> Image sees 1439 / 1554 points
=> Triangulated 31 points

==============================================================================
Retriangulation

=> Completed observations: 0
=> Merged observations: 0

==============================================================================
Bundle adjustment

iter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time
0 3.794887e+08 0.00e+00 6.95e+02 0.00e+00 0.00e+00 1.00e+04 0 8.84e-03 1.84e-02
1 3.100615e+08 6.94e+07 1.73e+02 4.51e+05 8.19e-01 1.35e+04 0 1.39e-02 3.24e-02
2 2.978513e+08 1.22e+07 4.32e+01 6.78e+05 8.06e-01 1.75e+04 0 1.29e-02 4.53e-02
3 2.954552e+08 2.40e+06 1.07e+01 9.30e+05 8.13e-01 2.33e+04 0 1.30e-02 5.82e-02
4 2.949659e+08 4.89e+05 2.54e+00 1.07e+06 8.35e-01 3.33e+04 0 1.27e-02 7.10e-02
5 2.948598e+08 1.06e+05 5.74e-01 1.10e+06 8.61e-01 5.34e+04 0 1.27e-02 8.37e-02

Bundle adjustment report

Residuals : 38738

Parameters : 20979
Iterations : 6
Time : 0.0844555 [s]
Initial cost : 98.9762 [px]
Final cost : 87.2447 [px]
Termination : Convergence

=> Completed observations: 0
=> Merged observations: 0
=> Filtered observations: 19269
=> Changed observations: 0.994837

==============================================================================
Bundle adjustment

iter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time
0 2.992714e+02 0.00e+00 9.09e-12 0.00e+00 0.00e+00 1.00e+04 0 5.07e-05 1.32e-04

Bundle adjustment report

Residuals : 200

Parameters : 150
Iterations : 1
Time : 0.000152124 [s]
Initial cost : 1.22326 [px]
Final cost : 1.22326 [px]
Termination : Convergence

=> Completed observations: 0
=> Merged observations: 0
=> Filtered observations: 0
=> Changed observations: 0.000000

==============================================================================
Extracting colors

@meyerls
Copy link

meyerls commented Oct 14, 2023

Maybe a little bit late but i found out that if you use

--SiftExtraction.estimate_affine_shape 1 \
 --SiftExtraction.domain_size_pooling 1 \

the order of the image will change and does not match with the order of your original database.db / images.bin file.

If you remove this part the sift feature extraction time will roughly be the same and the images will be loaded in the identical order (mostly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants