Skip to content

Commit

Permalink
[mvsUtils] do not fail when meshing an SfM without the source images
Browse files Browse the repository at this point in the history
readImageMetadata throw an error if the path does not exist.
  • Loading branch information
fabiencastan authored and dsmtE committed Jul 28, 2020
1 parent 834a505 commit 5788332
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/aliceVision/mvsUtils/MultiViewParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,24 @@ MultiViewParams::MultiViewParams(const sfmData::SfMData& sfmData,
const ImageParams& imgParams = _imagesParams.at(i);

oiio::ParamValueList metadata;
imageIO::readImageMetadata(imgParams.path, metadata);

const auto scaleIt = metadata.find("AliceVision:downscale");
const auto pIt = metadata.find("AliceVision:P");
oiio::ParamValueList::const_iterator scaleIt = metadata.end();
oiio::ParamValueList::const_iterator pIt = metadata.end();

const bool fileExists = fs::exists(imgParams.path);
if(fileExists)
{
imageIO::readImageMetadata(imgParams.path, metadata);
scaleIt = metadata.find("AliceVision:downscale");
pIt = metadata.find("AliceVision:P");
}

// find image scale information
if(scaleIt != metadata.end() && scaleIt->type() == oiio::TypeDesc::INT)
{
// use aliceVision image metadata
_imagesScale.at(i) = scaleIt->get_int();
}
else
else if(fileExists)
{
// use image dimension
int w, h, channels;
Expand Down Expand Up @@ -172,16 +178,16 @@ MultiViewParams::MultiViewParams(const sfmData::SfMData& sfmData,
const std::string fileNameP = getFileNameFromIndex(this, i, EFileType::P);
const std::string fileNameD = getFileNameFromIndex(this, i, EFileType::D);

if(fs::exists(fileNameP), fs::exists(fileNameD))
if(fs::exists(fileNameP) && fs::exists(fileNameD))
{
ALICEVISION_LOG_DEBUG("Reading view " << getViewId(i) << " projection matrix from file '" << fileNameP << "'.");
ALICEVISION_LOG_DEBUG("Reading view " << getViewId(i) << " projection matrix from file '" << fileNameP << "'.");

loadMatricesFromTxtFile(i, fileNameP, fileNameD);
loadMatricesFromTxtFile(i, fileNameP, fileNameD);
}
else
{
ALICEVISION_LOG_DEBUG("Reading view " << getViewId(i) << " projection matrix from SfMData.");
loadMatricesFromSfM(i);
ALICEVISION_LOG_DEBUG("Reading view " << getViewId(i) << " projection matrix from SfMData.");
loadMatricesFromSfM(i);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/mvsUtils/MultiViewParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class MultiViewParams
CArr.resize(ncams);
iCamArr.resize(ncams);
FocK1K2Arr.resize(ncams);
_imagesScale.resize(ncams);
_imagesScale.resize(ncams, 1);
}
};

Expand Down

0 comments on commit 5788332

Please sign in to comment.