Sunday, 4 October 2015

Bundle adjust and generate model


For sequential reconstruction then this is a fairly simple process.

We:
  • Create a Sequential SfM Reconstruction Engine instance
  • Create a Features Provider for it, from our Features (Regions) information
  • Create a Matches Provider for it, from our Filtered list of matches
  • Set the initial image pair
  • Run the SfM Engine
  • Save the output



We have already made most of the configuration decisions ahead of this step, so we don't have many options.
In the boilerplate example here I use the first two images unconditionally. This is OK for my image sets, but may need adjusting for some source data sets if the first two images don't have a good overlap.

void ImageList::sequentialReconstruct()
{
std::string output_directory = "sequential";
std::string sfm_data = stlplus::create_filespec(output_directory, "sfm_data", ".json");
std::string cloud_data = stlplus::create_filespec(output_directory, "cloud_and_poses", ".ply");
std::string report_name = stlplus::create_filespec(output_directory, "Reconstruction_Report", ".html");

  if (!stlplus::folder_exists(output_directory))
    stlplus::folder_create(output_directory);

  openMVG::sfm::SequentialSfMReconstructionEngine sfmEngine(_sfm_data, output_directory, report_name);
  std::shared_ptr<openMVG::sfm::Features_Provider> feats_provider = std::make_shared<openMVG::sfm::Features_Provider>();
  std::shared_ptr<openMVG::sfm::Matches_Provider> matches_provider = std::make_shared<openMVG::sfm::Matches_Provider>();

  feats_provider->load(_sfm_data, getDirectory(), _regionsType);
  matches_provider->load(_sfm_data, _matches_filtered);


  sfmEngine.SetFeaturesProvider(feats_provider.get());
  sfmEngine.SetMatchesProvider(matches_provider.get());

  openMVG::Pair initialPairIndex;
  openMVG::sfm::Views::const_iterator it;

  it = _sfm_data.GetViews().begin();
  const openMVG::sfm::View *v1 = it->second.get();
  it++;
  const openMVG::sfm::View *v2 = it->second.get();

  initialPairIndex.first = v1->id_view;
  initialPairIndex.second = v2->id_view;

  sfmEngine.setInitialPair(initialPairIndex);

  sfmEngine.Set_bFixedIntrinsics(false);
  sfmEngine.SetUnknownCameraType(openMVG::cameras::EINTRINSIC(openMVG::cameras::PINHOLE_CAMERA_RADIAL3));

  sfmEngine.Process();
  Save(sfmEngine.Get_SfM_Data(), sfm_data, openMVG::sfm::ESfM_Data(openMVG::sfm::ALL));
  Save(sfmEngine.Get_SfM_Data(), cloud_data, openMVG::sfm::ESfM_Data(openMVG::sfm::ALL));
}