forked from openMVG/openMVG
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop_2.0_fixed_extrinsics_in_…
…ba' into develop_2.0
- Loading branch information
Showing
15 changed files
with
624 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// This file is part of OpenMVG, an Open Multiple View Geometry C++ library. | ||
|
||
// Copyright (c) 2019 Pierre MOULON. | ||
|
||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#ifndef OPENMVG_FEATURES_REGIONS_SCALE_SORT_HPP | ||
#define OPENMVG_FEATURES_REGIONS_SCALE_SORT_HPP | ||
|
||
#include <numeric> // std::iota | ||
#include <algorithm> // std::sort | ||
|
||
namespace openMVG { | ||
namespace features { | ||
|
||
/// Get the reordering indexes of the feature according the feature scale | ||
/// reordered by increasing scale. | ||
template <typename T> | ||
std::vector<size_t> sort_indexes_by_scale(const std::vector<T> &v) { | ||
|
||
// initialize original index locations | ||
std::vector<size_t> idx(v.size()); | ||
std::iota(idx.begin(), idx.end(), 0); | ||
|
||
// sort indexes based on comparing scale values of the features in v | ||
std::sort(idx.begin(), idx.end(), | ||
[&v](size_t i1, size_t i2) {return v[i1].scale() < v[i2].scale();}); | ||
|
||
return idx; | ||
} | ||
|
||
/// Sort the features and descriptor according the scale of the feature | ||
/// A `keep_count` filter can be used to select only the feature with the largest scale | ||
template | ||
< | ||
typename FeatT, | ||
typename DescsT | ||
> | ||
bool SortAndSelectByRegionScale | ||
( | ||
std::vector<FeatT> & feats, | ||
DescsT & descs, | ||
int keep_count = -1 | ||
) | ||
{ | ||
return false; | ||
} | ||
|
||
/// SortAndSelectByRegionScale specialization for the SIOPointFeature type. | ||
template | ||
< | ||
typename FeatT, | ||
typename DescsT | ||
> | ||
bool SortAndSelectByRegionScale | ||
( | ||
std::vector<SIOPointFeature> & feats, | ||
DescsT & descs, | ||
int keep_count = -1 | ||
) | ||
{ | ||
// Reorder features and descriptors | ||
// a. get the re-ordering sequence | ||
// b. apply the re-ordering sequence | ||
const std::vector<size_t> re_ordering = sort_indexes_by_scale(feats); | ||
auto feats_reordered = feats; | ||
auto descs_reordered = descs; | ||
for (size_t i = 0; i < re_ordering.size(); ++i) | ||
{ | ||
feats_reordered[i] = feats[re_ordering[i]]; | ||
descs_reordered[i] = descs[re_ordering[i]]; | ||
} | ||
|
||
// Keep only the regions with the largest scale: | ||
{ | ||
const int region_to_keep = | ||
(keep_count == -1) ? | ||
feats_reordered.size() : | ||
std::min(keep_count, static_cast<int>(feats_reordered.size())); | ||
|
||
auto start_feat_it = std::prev(feats_reordered.end(), region_to_keep); | ||
feats.assign(start_feat_it, feats_reordered.end()); | ||
|
||
auto start_desc_it = std::prev(descs_reordered.end(), region_to_keep); | ||
descs.assign(start_desc_it, descs_reordered.end()); | ||
|
||
} | ||
return true; | ||
} | ||
|
||
} // namespace features | ||
} // namespace openMVG | ||
|
||
#endif // OPENMVG_FEATURES_REGIONS_SCALE_SORT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/openMVG/sfm/pipelines/sfm_preemptive_regions_provider.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// This file is part of OpenMVG, an Open Multiple View Geometry C++ library. | ||
|
||
// Copyright (c) 2019 Pierre MOULON. | ||
|
||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#ifndef OPENMVG_SFM_SFM_PREEMPTIVE_REGIONS_PROVIDER_HPP | ||
#define OPENMVG_SFM_SFM_PREEMPTIVE_REGIONS_PROVIDER_HPP | ||
|
||
#include "openMVG/sfm/pipelines/sfm_regions_provider.hpp" | ||
|
||
namespace openMVG { | ||
namespace sfm { | ||
|
||
/// Abstract Regions provider | ||
/// Allow to load and return a subset of regions related to a view | ||
struct Preemptive_Regions_Provider : public Regions_Provider | ||
{ | ||
public: | ||
|
||
/// Set the number of regions to keep per image (largest scale kept first) | ||
explicit Preemptive_Regions_Provider(int kept_regions_count = 100): | ||
Regions_Provider(), kept_regions_count_(kept_regions_count) | ||
{}; | ||
|
||
// Load Regions related to a provided SfM_Data View container | ||
bool load( | ||
const SfM_Data & sfm_data, | ||
const std::string & feat_directory, | ||
std::unique_ptr<features::Regions>& region_type, | ||
system::ProgressInterface * my_progress_bar = nullptr) override | ||
{ | ||
if (!my_progress_bar) | ||
my_progress_bar = &system::ProgressInterface::dummy(); | ||
region_type_.reset(region_type->EmptyClone()); | ||
|
||
my_progress_bar->Restart(sfm_data.GetViews().size(), "- Regions ---- Loading -"); | ||
// Read for each view the corresponding regions and store them | ||
std::atomic<bool> bContinue(true); | ||
#ifdef OPENMVG_USE_OPENMP | ||
#pragma omp parallel | ||
#endif | ||
for (Views::const_iterator iter = sfm_data.GetViews().begin(); | ||
iter != sfm_data.GetViews().end() && bContinue; ++iter) | ||
{ | ||
if (my_progress_bar->hasBeenCanceled()) | ||
{ | ||
bContinue = false; | ||
continue; | ||
} | ||
#ifdef OPENMVG_USE_OPENMP | ||
#pragma omp single nowait | ||
#endif | ||
{ | ||
const std::string sImageName = stlplus::create_filespec(sfm_data.s_root_path, iter->second->s_Img_path); | ||
const std::string basename = stlplus::basename_part(sImageName); | ||
const std::string featFile = stlplus::create_filespec(feat_directory, basename, ".feat"); | ||
const std::string descFile = stlplus::create_filespec(feat_directory, basename, ".desc"); | ||
|
||
std::unique_ptr<features::Regions> regions_ptr(region_type->EmptyClone()); | ||
if (!regions_ptr->Load(featFile, descFile)) | ||
{ | ||
OPENMVG_LOG_ERROR << "Invalid regions files for the view: " << sImageName; | ||
bContinue = false; | ||
} | ||
//else | ||
#ifdef OPENMVG_USE_OPENMP | ||
#pragma omp critical | ||
#endif | ||
{ | ||
// Sort regions by feature scale & keep the desired count | ||
regions_ptr->SortAndSelectByRegionScale(kept_regions_count_); | ||
cache_[iter->second->id_view] = std::move(regions_ptr); | ||
} | ||
++(*my_progress_bar); | ||
} | ||
} | ||
return bContinue; | ||
} | ||
|
||
protected: | ||
int kept_regions_count_ = 100; | ||
}; // Preemptive_Regions_Provider | ||
|
||
} // namespace sfm | ||
} // namespace openMVG | ||
|
||
#endif // OPENMVG_SFM_SFM_PREEMPTIVE_REGIONS_PROVIDER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.