colmap / glomap

GLOMAP - Global Structured-from-Motion Revisited
BSD 3-Clause "New" or "Revised" License
1.3k stars 77 forks source link

fix: vector out of bounds in ViewGraph::KeepLargestConnectedComponents #99

Closed lnexenl closed 5 days ago

lnexenl commented 1 week ago

In the most extreme condition, all image pairs could be invalid and there are no connected_components. This will crash the program with a SIGSEGV signal like:

*** SIGSEGV (@0x29) received by PID 301534 (TID 0x7cbe1f456540) from PID 41; stack trace: ***
    @     0x7cbe2355b046 (unknown)
    @     0x7cbe20a42520 (unknown)
    @     0x58497c373f83 std::_Hashtable<>::_M_assign<>()
    @     0x58497c372b17 glomap::ViewGraph::KeepLargestConnectedComponents()
    @     0x58497c28cbfa glomap::GlobalMapper::Solve()
    @     0x58497c2882ac glomap::RunMapper()
    @     0x58497c28688f main
    @     0x7cbe20a29d90 (unknown)
    @     0x7cbe20a29e40 __libc_start_main
    @     0x58497c2864b5 _start

I think some conditional statements should be added here to avoid crash. And the GlobalMapper::Solve function should return when no connected components are found.

After adding this statement, the program doesn't crash and the log looks like:

-------------------------------------
Running rotation averaging ...
-------------------------------------
I0910 16:29:13.657310 423892 relpose_filter.cc:31] Filtered 4 relative rotation with angle > 10 degrees
E0910 16:29:13.657315 423892 global_mapper.cc:90] no connected components are found
I0910 16:29:13.657357 423892 global_mapper.cc:86] Reconstruction done in 0.299914 seconds
I0910 16:29:13.657366 423892 colmap_io.cc:27] Extracting colors ...
........
I0910 16:29:13.657447 423892 global_mapper.cc:91] Export to COLMAP reconstruction done
lnexenl commented 1 week ago

I am trying to calibrate cameras with only several images (currently 4). If matches between images are not good, image pairs are easily filtered out by RelPoseFilter, and there could be no valid image pairs for KeepLargestConnectedComponents() 😆

lpanaf commented 4 days ago

I am trying to calibrate cameras with only several images (currently 4). If matches between images are not good, image pairs are easily filtered out by RelPoseFilter, and there could be no valid image pairs for KeepLargestConnectedComponents() 😆

Hi, thanks for the info! However, in this case, the view-graph should output that the connected component is every single image, instead of 0. Some other parts may also have bug in this case

lnexenl commented 1 day ago

Hi, thanks for the info! However, in this case, the view-graph should output that the connected component is every single image, instead of 0. Some other parts may also have bug in this case

In this case, all image_pairs are marked invalid from relative pose estimation, and the AdjacencyList is empty from here, and no connected components will be generated. So I think no more bugs