Skip to content

Commit

Permalink
[sfm/pipelines/global] Accuracy improvement. openMVG#384
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoulon authored and simogasp committed Oct 2, 2015
1 parent 1da6e35 commit d340375
Show file tree
Hide file tree
Showing 6 changed files with 970 additions and 765 deletions.
55 changes: 21 additions & 34 deletions src/openMVG/sfm/pipelines/global/GlobalSfM_rotation_averaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,45 +157,33 @@ void GlobalSfM_Rotation_AveragingSolver::TripletRotationRejection(
RelativeRotations_map map_relatives = getMap(relativeRotations);
RelativeRotations_map map_relatives_validated;

// DETECTION OF ROTATION OUTLIERS
//--
// ROTATION OUTLIERS DETECTION
//--

std::vector< graph::Triplet > vec_triplets_validated;
vec_triplets_validated.reserve(vec_triplets.size());

std::vector<float> vec_errToIdentityPerTriplet;
vec_errToIdentityPerTriplet.reserve(vec_triplets.size());
// Compute for each length 3 cycles: the composition error
// Error to identity rotation.
// Compute the composition error for each length 3 cycles
for (size_t i = 0; i < vec_triplets.size(); ++i)
{
const graph::Triplet & triplet = vec_triplets[i];
const IndexT I = triplet.i, J = triplet.j , K = triplet.k;

//-- Find the three rotations
const Pair ij(I,J);
const Pair ji(J,I);

Mat3 RIJ;
if (map_relatives.find(ij) != map_relatives.end())
RIJ = map_relatives.at(ij).Rij;
else
RIJ = map_relatives.at(ji).Rij.transpose();

const Pair jk(J,K);
const Pair kj(K,J);

Mat3 RJK;
if (map_relatives.find(jk) != map_relatives.end())
RJK = map_relatives.at(jk).Rij;
else
RJK = map_relatives.at(kj).Rij.transpose();
//-- Find the three relative rotations
const Pair ij(I,J), ji(J,I);
const Mat3 RIJ = (map_relatives.count(ij)) ?
map_relatives.at(ij).Rij : Mat3(map_relatives.at(ji).Rij.transpose());

const Pair ki(K,I);
const Pair ik(I,K);
const Pair jk(J,K), kj(K,J);
const Mat3 RJK = (map_relatives.count(jk)) ?
map_relatives.at(jk).Rij : Mat3(map_relatives.at(kj).Rij.transpose());

Mat3 RKI;
if (map_relatives.find(ki) != map_relatives.end())
RKI = map_relatives.at(ki).Rij;
else
RKI = map_relatives.at(ik).Rij.transpose();
const Pair ki(K,I), ik(I,K);
const Mat3 RKI = (map_relatives.count(ki)) ?
map_relatives.at(ki).Rij : Mat3(map_relatives.at(ik).Rij.transpose());

const Mat3 Rot_To_Identity = RIJ * RJK * RKI; // motion composition
const float angularErrorDegree = static_cast<float>(R2D(getRotationMagnitude(Rot_To_Identity)));
Expand All @@ -205,23 +193,23 @@ void GlobalSfM_Rotation_AveragingSolver::TripletRotationRejection(
{
vec_triplets_validated.push_back(triplet);

if (map_relatives.find(ij) != map_relatives.end())
if (map_relatives.count(ij))
map_relatives_validated[ij] = map_relatives.at(ij);
else
map_relatives_validated[ji] = map_relatives.at(ji);

if (map_relatives.find(jk) != map_relatives.end())
if (map_relatives.count(jk))
map_relatives_validated[jk] = map_relatives.at(jk);
else
map_relatives_validated[kj] = map_relatives.at(kj);

if (map_relatives.find(ki) != map_relatives.end())
if (map_relatives.count(ki))
map_relatives_validated[ki] = map_relatives.at(ki);
else
map_relatives_validated[ik] = map_relatives.at(ik);
}
}
map_relatives.swap(map_relatives_validated);
map_relatives = std::move(map_relatives_validated);

// update to keep only useful triplets
relativeRotations.clear();
Expand All @@ -245,8 +233,7 @@ void GlobalSfM_Rotation_AveragingSolver::TripletRotationRejection(
<< "#Triplets after: " << vec_triplets_validated.size() << std::endl;
}

vec_triplets.clear();
vec_triplets = vec_triplets_validated;
vec_triplets = std::move(vec_triplets_validated);

const size_t edges_end_count = relativeRotations.size();
std::cout << "\n #Edges removed by triplet inference: " << edges_start_count - edges_end_count << std::endl;
Expand Down
Loading

0 comments on commit d340375

Please sign in to comment.