-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
268 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
|
||
#include "EventEMin.h" | ||
|
||
using namespace EventEMin; | ||
|
||
int | ||
main(int argc, char* argv[]) | ||
{ | ||
if (argc < 7) | ||
{ | ||
std::cout << "usage: " << argv[0] | ||
<< " [events dir] [number of events] " | ||
"[min depth] [depth scale] [saving dir] [file " | ||
"name]\n"; | ||
return -1; | ||
} | ||
|
||
typedef float T; | ||
|
||
/* you can modify the model used by uncommenting the corresponding line */ | ||
|
||
// model | ||
typedef IncrementalSixDOF<T> Model; | ||
// typedef IncrementalTranslation3D<T> Model; | ||
|
||
constexpr int NDims = Model::NDims; | ||
|
||
/* you can modify the dispersion measure used by uncommenting the | ||
corresponding line */ | ||
|
||
// incremental measures | ||
typedef IncrementalPotential<Model> Dispersion; | ||
// typedef IncrementalTsallis<Model> Dispersion; | ||
|
||
// read undistorted depth-augmented events from file | ||
const std::string fevents(std::string(argv[1]) + "/events.txt"); | ||
std::ifstream fin(fevents.c_str()); | ||
if (!fin.is_open()) | ||
{ | ||
std::cerr << "error reading events from file " << fevents << '\n'; | ||
return -1; | ||
} | ||
|
||
// write estimates to file | ||
const std::string festimates(std::string(argv[5]) + "/" + | ||
std::string(argv[6]) + "_estimates.txt"); | ||
std::ofstream fout(festimates.c_str()); | ||
if (!fout.is_open()) | ||
{ | ||
std::cerr << "error writing estimates to file " << festimates << '\n'; | ||
return -1; | ||
} | ||
|
||
int width, height; | ||
Matrix<T, 3, 3> camParams; | ||
const std::string fcalib(std::string(argv[1]) + "/calib.txt"); | ||
const IO_STATUS ioStatus = loadCamParams<T>(fcalib, width, height, camParams); | ||
if (ioStatus != IO_SUCCESS) | ||
{ | ||
ioStatusMessage(ioStatus, fcalib); | ||
return -1; | ||
} | ||
|
||
Vector<T, NDims> scale; | ||
scale << T(1.0), T(1.0), std::atof(argv[4]); | ||
|
||
// tolerance that indicates a minimum has been reached | ||
const T minStep = T(1.0e-6); | ||
// maximum iterations | ||
const int maxIter = 10; | ||
// neighbouring radius | ||
const int wSize = 4; | ||
// number of events to maintain | ||
const int nEvents = std::atoi(argv[2]); | ||
Dispersion dispersion(camParams, scale, | ||
Dispersion::Params(minStep, maxIter, wSize), nEvents, | ||
{width, height}); | ||
|
||
const T depthThresh = std::atof(argv[3]); | ||
Vector<T, NDims> c, ct; | ||
T ts; | ||
int polarity; | ||
|
||
for (int k = 0; load<T, NDims>(fin, c, ts, polarity) == IO_SUCCESS; ++k) | ||
{ | ||
const int x = std::round(c(0)); | ||
const int y = std::round(c(1)); | ||
|
||
if (!(0 <= x && x < width && 0 <= y && y < height) || c(2) < depthThresh) | ||
{ | ||
--k; | ||
continue; | ||
} | ||
unprojectEvent<T, NDims>()(camParams, c, ct); | ||
|
||
dispersion.run(ct, ts); | ||
|
||
if ((k + 1) % nEvents == 0) | ||
{ | ||
std::cout << "ts: " << ts << ", vars: " << dispersion.vars().transpose() | ||
<< '\n'; | ||
fout << ts << ' ' << dispersion.vars().transpose() << std::endl; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
|
||
#include "EventEMin.h" | ||
|
||
using namespace EventEMin; | ||
|
||
int | ||
main(int argc, char* argv[]) | ||
{ | ||
if (argc < 7) | ||
{ | ||
std::cout << "usage: " << argv[0] | ||
<< " [events dir] [number of events] " | ||
"[min depth] [max depth] [saving dir] " | ||
"[file name]\n"; | ||
return -1; | ||
} | ||
|
||
typedef float T; | ||
|
||
/* you can modify the model used by uncommenting the corresponding line */ | ||
|
||
// model | ||
typedef SixDOF<T> Model; | ||
// typedef Translation3D<T> Model; | ||
|
||
constexpr int NDims = Model::NDims, NVars = Model::NVars; | ||
|
||
// exact measures | ||
// typedef Potential<Model> Dispersion; | ||
// typedef Renyi<Model> Dispersion; | ||
// typedef Shannon<Model> Dispersion; | ||
// typedef SharmaMittal<Model> Dispersion; | ||
// typedef Tsallis<Model> Dispersion; | ||
// approximate measures | ||
// typedef ApproximatePotential<Model> Dispersion; | ||
// typedef ApproximateRenyi<Model> Dispersion; | ||
// typedef ApproximateShannon<Model> Dispersion; | ||
// typedef ApproximateSharmaMittal<Model> Dispersion; | ||
typedef ApproximateTsallis<Model> Dispersion; | ||
|
||
// optimiser | ||
typedef GSLfdfOptimiser<Dispersion> Optimiser; | ||
|
||
// read undistorted depth-augmented events from file | ||
const std::string fevents(std::string(argv[1]) + "/events.txt"); | ||
std::ifstream fin(fevents.c_str()); | ||
if (!fin.is_open()) | ||
{ | ||
std::cerr << "error reading events from file " << fevents << '\n'; | ||
return -1; | ||
} | ||
|
||
// write estimates to file | ||
const std::string festimates(std::string(argv[5]) + "/" + | ||
std::string(argv[6]) + "_estimates.txt"); | ||
std::ofstream fout(festimates.c_str()); | ||
if (!fout.is_open()) | ||
{ | ||
std::cerr << "error writing estimates to file " << festimates << '\n'; | ||
return -1; | ||
} | ||
|
||
int width, height; | ||
Matrix<T, 3, 3> camParams; | ||
const std::string fcalib(std::string(argv[1]) + "/calib.txt"); | ||
const IO_STATUS ioStatus = loadCamParams<T>(fcalib, width, height, camParams); | ||
if (ioStatus != IO_SUCCESS) | ||
{ | ||
ioStatusMessage(ioStatus, fcalib); | ||
return -1; | ||
} | ||
|
||
Dispersion dispersion(width); | ||
|
||
// initial parameters | ||
Vector<T, NVars> vars; | ||
vars.setConstant(1.0e-6); | ||
|
||
// initial step size of the optimisation | ||
const double iniStep = 1.0; | ||
// tolerance that indicates a minimum has been reached | ||
const double tol = 1.0e-16; | ||
// maximum iterations | ||
const int maxIter = 100, maxrIter = 1; | ||
// optimiser status feedback: 0 - no feedback, 1 - feedback at each iteration | ||
const int verbosity = 1; | ||
// apply whitening pre-processing step | ||
const bool whiten = false; | ||
|
||
const int nEvents = std::atoi(argv[2]); | ||
Matrix<T> c; | ||
Vector<T> ts; | ||
Vector<int> polarity; | ||
while (loadDepthThresh<T>(nEvents, std::atof(argv[3]), std::atof(argv[4]), | ||
fin, c, ts, polarity) == IO_SUCCESS) | ||
{ | ||
Matrix<T> ct(NDims, c.cols()); | ||
unprojectEvents<T, NDims>()(camParams, c, ct); | ||
dispersion.assignPoints(ct, ts, polarity, whiten); | ||
|
||
Optimiser optimiser( | ||
dispersion, | ||
Optimiser::OptimiserParams(gsl_multimin_fdfminimizer_conjugate_fr, | ||
iniStep, tol, maxIter, maxrIter, verbosity)); | ||
|
||
optimiser.run(vars); | ||
vars = optimiser.vars(); | ||
std::cout << "ts: " << dispersion.tsEnd() << ", vars: " << vars.transpose() | ||
<< '\n'; | ||
fout << dispersion.tsEnd() << ' ' << vars.transpose() << std::endl; | ||
} | ||
|
||
return 0; | ||
} |