Skip to content

Commit

Permalink
[imageMatching] Extract more code from main() in main_imageMatching.cpp
Browse files Browse the repository at this point in the history
This allows the code to be reused by other components.
  • Loading branch information
mokibit authored and p12tic committed Oct 8, 2022
1 parent 4d840a1 commit 1607b34
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 47 deletions.
56 changes: 56 additions & 0 deletions src/aliceVision/imageMatching/ImageMatching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,5 +454,61 @@ void conditionVocTree(const std::string& treeName, bool withWeights,
}
}

EImageMatchingMethod selectImageMatchingMethod(EImageMatchingMethod method,
const sfmData::SfMData& sfmDataA,
const sfmData::SfMData& sfmDataB,
std::size_t minNbImages)
{
if (method == EImageMatchingMethod::FRUSTUM_OR_VOCABULARYTREE)
{
// Frustum intersection is only implemented for pinhole cameras
bool onlyPinhole = true;
for (auto& cam : sfmDataA.getIntrinsics())
{
if(!camera::isPinhole(cam.second->getType()))
{
onlyPinhole = false;
break;
}
}

const std::size_t reconstructedViews = sfmDataA.getValidViews().size();
if (reconstructedViews == 0)
{
ALICEVISION_LOG_INFO("FRUSTUM_OR_VOCABULARYTREE: Use VOCABULARYTREE matching, as there is no known pose.");
method = EImageMatchingMethod::VOCABULARYTREE;
}
else if (!onlyPinhole)
{
ALICEVISION_LOG_INFO(
"FRUSTUM_OR_VOCABULARYTREE: Use VOCABULARYTREE matching, as the scene contains non-pinhole cameras.");
method = EImageMatchingMethod::VOCABULARYTREE;
}
else if (reconstructedViews == sfmDataA.getViews().size())
{
ALICEVISION_LOG_INFO("FRUSTUM_OR_VOCABULARYTREE: Use FRUSTUM intersection from known poses.");
method = EImageMatchingMethod::FRUSTUM;
}
else
{
ALICEVISION_LOG_ERROR(reconstructedViews << " reconstructed views for " << sfmDataA.getViews().size()
<< " views.");
throw std::runtime_error("FRUSTUM_OR_VOCABULARYTREE: Mixing reconstructed and unreconstructed Views.");
}
}

// if not enough images to use the VOCABULARYTREE use the EXHAUSTIVE method
if (method == EImageMatchingMethod::VOCABULARYTREE ||
method == EImageMatchingMethod::SEQUENTIAL_AND_VOCABULARYTREE)
{
if ((sfmDataA.getViews().size() + sfmDataB.getViews().size()) < minNbImages)
{
ALICEVISION_LOG_DEBUG("Use EXHAUSTIVE method instead of VOCABULARYTREE (less images than minNbImages).");
method = EImageMatchingMethod::EXHAUSTIVE;
}
}
return method;
}

} // namespace imageMatching
} // namespace aliceVision
5 changes: 5 additions & 0 deletions src/aliceVision/imageMatching/ImageMatching.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,10 @@ void conditionVocTree(const std::string& treeName, bool withWeights,
std::size_t numImageQuery,
OrderedPairList& selectedPairs);

EImageMatchingMethod selectImageMatchingMethod(EImageMatchingMethod method,
const sfmData::SfMData& sfmDataA,
const sfmData::SfMData& sfmDataB,
std::size_t minNbImages);

} // namespace imageMatching
} // namespace aliceVision
48 changes: 1 addition & 47 deletions src/software/pipeline/main_imageMatching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,53 +206,7 @@ int aliceVision_main(int argc, char** argv)
}
}

if(method == EImageMatchingMethod::FRUSTUM_OR_VOCABULARYTREE)
{
// Frustum intersection is only implemented for pinhole cameras
bool onlyPinhole = true;
for(auto& cam : sfmDataA.getIntrinsics())
{
if(!camera::isPinhole(cam.second->getType()))
{
onlyPinhole = false;
break;
}
}

const std::size_t reconstructedViews = sfmDataA.getValidViews().size();
if(reconstructedViews == 0)
{
ALICEVISION_LOG_INFO("FRUSTUM_OR_VOCABULARYTREE: Use VOCABULARYTREE matching, as there is no known pose.");
method = EImageMatchingMethod::VOCABULARYTREE;
}
else if(!onlyPinhole)
{
ALICEVISION_LOG_INFO(
"FRUSTUM_OR_VOCABULARYTREE: Use VOCABULARYTREE matching, as the scene contains non-pinhole cameras.");
method = EImageMatchingMethod::VOCABULARYTREE;
}
else if(reconstructedViews == sfmDataA.getViews().size())
{
ALICEVISION_LOG_INFO("FRUSTUM_OR_VOCABULARYTREE: Use FRUSTUM intersection from known poses.");
method = EImageMatchingMethod::FRUSTUM;
}
else
{
ALICEVISION_LOG_ERROR(reconstructedViews << " reconstructed views for " << sfmDataA.getViews().size()
<< " views.");
throw std::runtime_error("FRUSTUM_OR_VOCABULARYTREE: Mixing reconstructed and unreconstructed Views.");
}
}

// if not enough images to use the VOCABULARYTREE use the EXHAUSTIVE method
if(method == EImageMatchingMethod::VOCABULARYTREE || method == EImageMatchingMethod::SEQUENTIAL_AND_VOCABULARYTREE)
{
if((sfmDataA.getViews().size() + sfmDataB.getViews().size()) < minNbImages)
{
ALICEVISION_LOG_DEBUG("Use EXHAUSTIVE method instead of VOCABULARYTREE (less images than minNbImages).");
method = EImageMatchingMethod::EXHAUSTIVE;
}
}
method = selectImageMatchingMethod(method, sfmDataA, sfmDataB, minNbImages);

std::map<IndexT, std::string> descriptorsFilesA, descriptorsFilesB;

Expand Down

0 comments on commit 1607b34

Please sign in to comment.