Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sfmTransform] fix issue on referenceView if some poses are missing #1374

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/software/utils/main_sfmTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,42 @@ static void parseManualTransform(const std::string& manualTransform, double& S,

IndexT getReferenceViewId(const sfmData::SfMData & sfmData, const std::string & transform)
{
IndexT refViewId;
IndexT refViewId;
try
{
refViewId = sfm::getViewIdFromExpression(sfmData, transform);
if (!sfmData.isPoseAndIntrinsicDefined(refViewId))
{
return UndefinedIndexT;
}
}
catch (...)
{
refViewId = UndefinedIndexT;
}

//Default to select the view given timestamp
if (refViewId == UndefinedIndexT)
{
// Sort views per timestamps
// Sort views with poses per timestamps
std::vector<std::pair<int64_t, IndexT>> sorted_views;
for (auto v : sfmData.getViews()) {
if (!sfmData.isPoseAndIntrinsicDefined(v.first))
{
continue;
}

int64_t t = v.second->getMetadataDateTimestamp();
sorted_views.push_back(std::make_pair(t, v.first));
}
std::sort(sorted_views.begin(), sorted_views.end());

if (sorted_views.size() == 0)
{
return UndefinedIndexT;
}


// Get the view which was taken at the middle of the sequence
int median = sorted_views.size() / 2;
refViewId = sorted_views[sorted_views.size() - 1].second;
Expand Down Expand Up @@ -299,6 +315,22 @@ int aliceVision_main(int argc, char **argv)
return EXIT_FAILURE;
}

//Check that at least one view has a defined pose
int count = 0;
for (const auto p : sfmData.getViews())
{
if(sfmData.isPoseAndIntrinsicDefined(p.first))
{
count++;
}
}

if (count == 0)
{
ALICEVISION_LOG_ERROR("The input SfMData file '" << sfmDataFilename << "' has no valid views with estimated poses");
return EXIT_FAILURE;
}

double S = 1.0;
Mat3 R = Mat3::Identity();
Vec3 t = Vec3::Zero();
Expand Down