Equivalent to IncrementalPipeline.initialize_reconstruction(...)
(
controller: IncrementalPipeline,
mapper: IncrementalMapper,
mapper_options: IncrementalMapperOptions,
reconstruction: Reconstruction,
)
| 68 | |
| 69 | |
| 70 | def initialize_reconstruction( |
| 71 | controller: IncrementalPipeline, |
| 72 | mapper: IncrementalMapper, |
| 73 | mapper_options: IncrementalMapperOptions, |
| 74 | reconstruction: Reconstruction, |
| 75 | ) -> IncrementalPipelineStatus: |
| 76 | """Equivalent to IncrementalPipeline.initialize_reconstruction(...)""" |
| 77 | options = controller.options |
| 78 | init_pair = (options.init_image_id1, options.init_image_id2) |
| 79 | |
| 80 | # Try to find good initial pair |
| 81 | if not options.is_initial_pair_provided(): |
| 82 | logging.info("Finding good initial image pair") |
| 83 | ret = mapper.find_initial_image_pair(mapper_options, *init_pair) |
| 84 | if ret is None: |
| 85 | logging.info("No good initial image pair found.") |
| 86 | return IncrementalPipelineStatus.NO_INITIAL_PAIR |
| 87 | init_pair, init_cam2_from_cam1 = ret |
| 88 | else: |
| 89 | if not all(reconstruction.exists_image(i) for i in init_pair): |
| 90 | logging.info(f"=> Initial image pair {init_pair} does not exist.") |
| 91 | return IncrementalPipelineStatus.NO_INITIAL_PAIR |
| 92 | maybe_init_cam2_from_cam1 = mapper.estimate_initial_two_view_geometry( |
| 93 | mapper_options, *init_pair |
| 94 | ) |
| 95 | if maybe_init_cam2_from_cam1 is None: |
| 96 | logging.info("Provided pair is unsuitable for initialization") |
| 97 | return IncrementalPipelineStatus.BAD_INITIAL_PAIR |
| 98 | init_cam2_from_cam1 = maybe_init_cam2_from_cam1 |
| 99 | logging.info( |
| 100 | f"Registering initial image pair #{init_pair[0]} and #{init_pair[1]}" |
| 101 | ) |
| 102 | mapper.register_initial_image_pair( |
| 103 | mapper_options, *init_pair, init_cam2_from_cam1 |
| 104 | ) |
| 105 | |
| 106 | tri_options = options.get_triangulation() |
| 107 | tri_options.min_angle = mapper_options.init_min_tri_angle |
| 108 | for image_id in init_pair: |
| 109 | image = reconstruction.images[image_id] |
| 110 | assert image.frame is not None |
| 111 | for data_id in image.frame.image_ids: |
| 112 | mapper.triangulate_image(tri_options, data_id.id) |
| 113 | |
| 114 | logging.info("Global bundle adjustment") |
| 115 | # The following is equivalent to: mapper.adjust_global_bundle(...) |
| 116 | custom_bundle_adjustment.adjust_global_bundle( |
| 117 | mapper, mapper_options, options.get_global_bundle_adjustment() |
| 118 | ) |
| 119 | reconstruction.normalize() |
| 120 | mapper.filter_points(mapper_options) |
| 121 | mapper.filter_frames(mapper_options) |
| 122 | |
| 123 | # Initial image pair failed to register |
| 124 | if ( |
| 125 | reconstruction.num_reg_frames() == 0 |
| 126 | or reconstruction.num_points3D() == 0 |
| 127 | ): |
no outgoing calls
no test coverage detected