Skip to content

Commit

Permalink
Fix scaling in incremental mode
Browse files Browse the repository at this point in the history
  • Loading branch information
umgnunes committed Jan 10, 2022
1 parent 0fd5112 commit 528dde7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
16 changes: 11 additions & 5 deletions include/EventEMin/dispersion/incremental_dispersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class Whitening
typedef typename Model::Vars Vars;

private:
projectEvent<T, Model::NDims> projectEvent_;

Model model_;

Stats<M> istats_;
Expand All @@ -136,20 +138,24 @@ class Whitening
Whitening(void) = default;

void
processEvent(const Ref<const Point>& scale, const Ref<const Point>& c,
Ref<Point> cs) const
processEvent(const Matrix<T, 3, 3>& camParams, const Ref<const Point>& scale,
const Ref<const Point>& c, Ref<Point> cs) const
{
if constexpr (W)
{
Point cw;
whitenPoints(c - istats_.mean, istats_.w, cw);
cs = scale.array() *
(istats_.singularValues.array() * cw.array() + istats_.mean.array());
projectEvent_(
camParams,
((istats_.singularValues.array() * cw.array() + istats_.mean.array())
.matrix()),
cs);
}
else
{
cs = scale.array() * c.array();
projectEvent_(camParams, c, cs);
}
cs.array() *= scale.array();
}

void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class Dispersion
DMatrix dcm, dcml;
PMatrix per, perl;
model_(varse.vars, c, tsDiffRef, cm, dcm, cg, per);
whitening_.processEvent(scale_, cm, cms);
whitening_.processEvent(camParams_, scale_, cm, cms);

varse.val = T(0.0);
varse.vNum.setZero();
Expand All @@ -229,7 +229,7 @@ class Dispersion
for (int i = 0; i < static_cast<int>(inds.size()); ++i)
{
model_(varse.vars, c_[inds[i]], tsDiffRef_[i], cml, dcml, cgl, perl);
whitening_.processEvent(scale_, cml, cmsl);
whitening_.processEvent(camParams_, scale_, cml, cmsl);
cmDiff = cms - cmsl;

dispersionImpl_(cmDiff, dcm - dcml, cm - cml - cg + cgl, per - perl,
Expand Down
10 changes: 6 additions & 4 deletions include/EventEMin/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ struct TestIncrementalParams
int wSize;
// number of events to maintain
int nEvents;
// depth scaling factor
// only used when the number of dimensions is higher than 2
float depthScale;
};

template <typename Dispersion>
Expand Down Expand Up @@ -164,11 +167,10 @@ testIncrementalExample(const TestIncrementalParams& testIncrementalParams)
Matrix<T> ct(NDims, nEvents);
unprojectEvents<T, NDims>()(camParams, c, ct);

Vector<T, NDims> scale;
scale.template head<NDims>() = camParams.diagonal().template head<NDims>();
if (NDims == 3)
Vector<T, NDims> scale(Vector<T, NDims>::Ones());
if constexpr (NDims == 3)
{
scale(2) = T(100.0);
scale(2) = testIncrementalParams.depthScale;
}

Dispersion dispersion(
Expand Down
2 changes: 2 additions & 0 deletions test/main_incremental_6dof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ main(void)
testIncrementalParams.wSize = 4;
// number of events to maintain
testIncrementalParams.nEvents = 15000;
// depth scaling factor
testIncrementalParams.depthScale = T(100.0);

return testIncrementalExample<Dispersion>(testIncrementalParams);
}
2 changes: 1 addition & 1 deletion test/main_incremental_test_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ main(int argc, char* argv[])
cv::Mat undistortionMap;
initUndistort<T>(width, height, camParamsCV, distCoeffs, undistortionMap);

const Vector<T, NDims> scale(camParams.diagonal().template head<NDims>());
const Vector<T, NDims> scale(Vector<T, NDims>::Ones());

// tolerance that indicates a minimum has been reached
const T minStep = T(1.0e-6);
Expand Down

0 comments on commit 528dde7

Please sign in to comment.