25 #ifndef INCLUDED_TransformFindingRoutine_h_GUID_A09E7693_04E5_4FA2_C929_F23CBEC12306 26 #define INCLUDED_TransformFindingRoutine_h_GUID_A09E7693_04E5_4FA2_C929_F23CBEC12306 50 TrackedSamples samples;
53 std::cout <<
"Starting processing tracking..." << std::endl;
54 auto optim = OptimData::make(commonData);
58 for (
auto const &rowPtr : data) {
61 mainAlgo(optim, *rowPtr);
62 ransacOneEuro(optim, *rowPtr);
63 if (ransacOneEuro.havePose()) {
65 newSample->videoPose = ransacOneEuro.getPose();
68 samples.emplace_back(std::move(newSample));
72 std::cout <<
"Initial tracking complete: " << samples.size()
73 <<
" valid samples, " << ransacOneEuro.getNumFlips()
74 <<
" flipped." << std::endl;
77 if (samples.empty()) {
79 std::cout <<
"No samples with pose?" << std::endl;
83 const auto numSamples = samples.size();
84 const double numSamplesDouble =
static_cast<double>(numSamples);
88 double angleScale = 1) {
92 auto linearDistance = (a.
translation() - b.translation()).norm();
93 return linearDistance + angleScale * angDistance;
97 std::cout <<
"Starting actual optimization procedures..." << std::endl;
98 Vec<3> baseXlate = -
Vec<3>(-0.316523, -0.740873, -2.0701);
101 std::cout <<
"Optimizing base translation" << std::endl;
103 baseXlate, {1e-6, 1e-1}, 10000,
104 [&](
Vec<3> const &vec) ->
double {
107 return std::accumulate(
108 samples.begin(), samples.end(), 0.0,
109 [&](
double prev, TrackedDataPtr
const &s) {
111 auto cost = simpleCost(s->videoPose,
112 baseXform * s->refPose, 0);
113 return prev + (cost / numSamplesDouble);
117 std::cout <<
"Result: cost " << ret << std::endl;
118 std::cout << baseXlate.format(
getFullFormat()) <<
"\n" << std::endl;
119 std::cout <<
"First sample:\n";
121 Eigen::Isometry3d::Identity(),
125 baseXlateRot.head<3>() = baseXlate;
127 std::cout <<
"\nOptimizing base transform, max runs = " << maxRuns
130 baseXlateRot, {1e-6, 1e-1}, 10000,
131 [&](
Vec<6> const &vec) ->
double {
135 return std::accumulate(
136 samples.begin(), samples.end(), 0.0,
137 [&](
double prev, TrackedDataPtr
const &s) {
138 auto cost = simpleCost(s->videoPose,
139 baseXform * s->refPose);
140 return prev + (cost / numSamplesDouble);
143 std::cout <<
"Result: cost " << ret << std::endl;
146 std::cout <<
"First sample:\n";
147 outputTransformedSample(
149 rot_exp(baseXlateRot.tail<3>())),
150 Eigen::Isometry3d::Identity(), *(samples[0]));
154 using namespace reftracker;
155 TransformParams x = TransformParams::Zero();
156 x.head<3>() = baseXlateRot.head<3>();
157 x.segment<3>(BaseRot) = baseXlateRot.tail<3>();
159 std::cout <<
"Starting optimization procedure for full transform, " 161 << maxRuns << std::endl;
163 x, {1e-6, 1e-1}, maxRuns,
164 [&](TransformParams
const ¶mVec) ->
double {
168 return std::accumulate(
169 samples.begin(), samples.end(), 0.0,
170 [&](
double prev, TrackedDataPtr
const &s) {
172 baseXform * s->refPose *
174 return prev + (cost / numSamplesDouble);
178 std::cout <<
"Optimizer returned " << ret
179 <<
" and these parameter values:" << std::endl;
184 std::cout <<
"The first three samples, transformed for your " 185 "viewing pleasure:\n";
186 for (std::size_t i = 0; i < 3; ++i) {
187 outputTransformedSample(baseXform, innerXform,
195 #endif // INCLUDED_TransformFindingRoutine_h_GUID_A09E7693_04E5_4FA2_C929_F23CBEC12306 Eigen::IOFormat const & getFullFormat()
Use for output of parameters.
Definition: UtilityFunctions.h:61
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
double ei_newuoa_wrapped(long npt, Eigen::MatrixBase< Derived > &x, std::pair< double, double > rho, long maxfun, Function &&f)
Friendlier wrapper around newuoa: takes a vector for x, and the function takes a reference to const v...
Definition: newuoa.h:1943
Algorithm functor, call after either stage-2 functor: obtains a RANSAC pose and feeds it into a 1-eur...
Definition: OptimizationBase.h:142
Definition: UtilityFunctions.h:154
Algorithm functor to be called in a loop that processes measurements rows: all it does is feed in LED...
Definition: OptimizationBase.h:99
Definition: Quaternion.h:47
Isometry3< typename Derived1::Scalar > makeIsometry(Eigen::MatrixBase< Derived1 > const &translation, Eigen::RotationBase< Derived2, 3 > const &rotation)
A simpler, functional-style alternative to .fromPositionOrientationScale when no scaling is performed...
Definition: EigenExtras.h:93
Input from main to the optimization routine (wrapper)
Definition: OptimizationBase.h:47
double costMeasurement(Eigen::Isometry3d const &refPose, Eigen::Isometry3d const &expPose)
Definition: UtilityFunctions.h:137
Quaternion< double > Quaterniond
double precision quaternion type
Definition: Quaternion.h:211
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127