Skip to content
Snippets Groups Projects
Commit 8be40171 authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

fix RMS error calculation

parent 0eac7dfe
No related branches found
No related tags found
No related merge requests found
Pipeline #21554 canceled
...@@ -83,6 +83,7 @@ void Speaker::_open(int fsize, int sample, int channels) { ...@@ -83,6 +83,7 @@ void Speaker::_open(int fsize, int sample, int channels) {
buffer_ = new ftl::audio::MonoBuffer16<2000>(sample); buffer_ = new ftl::audio::MonoBuffer16<2000>(sample);
} }
#ifdef HAVE_PORTAUDIO
auto err = Pa_OpenDefaultStream( auto err = Pa_OpenDefaultStream(
&stream_, &stream_,
0, 0,
...@@ -111,6 +112,10 @@ void Speaker::_open(int fsize, int sample, int channels) { ...@@ -111,6 +112,10 @@ void Speaker::_open(int fsize, int sample, int channels) {
} }
LOG(INFO) << "Speaker ready."; LOG(INFO) << "Speaker ready.";
#else
LOG(INFO) << "Built without portaudio (no sound)";
#endif
} }
void Speaker::queue(int64_t ts, ftl::audio::Frame &frame) { void Speaker::queue(int64_t ts, ftl::audio::Frame &frame) {
......
...@@ -119,17 +119,21 @@ public: ...@@ -119,17 +119,21 @@ public:
*/ */
void run(); void run();
/** @brief Calculate MSE error (for one camera) /** @brief Calculate RMS error (for one camera)
*/ */
double reprojectionError(int camera); double reprojectionError(const int camera) const;
/** @brief Calculate MSE error for all cameras /** @brief Calculate RMS error for all cameras
*/ */
double reprojectionError(); double reprojectionError() const;
protected: protected:
double* getCameraPtr(int i) { return cameras_[i]->data; } double* getCameraPtr(int i) { return cameras_[i]->data; }
/** @brief Calculate MSE error
*/
void _reprojectionErrorMSE(const int camera, double &error, double &npoints) const;
void _buildProblem(ceres::Problem& problem, const BundleAdjustment::Options& options); void _buildProblem(ceres::Problem& problem, const BundleAdjustment::Options& options);
void _buildBundleAdjustmentProblem(ceres::Problem& problem, const BundleAdjustment::Options& options); void _buildBundleAdjustmentProblem(ceres::Problem& problem, const BundleAdjustment::Options& options);
void _buildLengthProblem(ceres::Problem& problem, const BundleAdjustment::Options& options); void _buildLengthProblem(ceres::Problem& problem, const BundleAdjustment::Options& options);
......
...@@ -418,7 +418,7 @@ void BundleAdjustment::run() { ...@@ -418,7 +418,7 @@ void BundleAdjustment::run() {
run(options); run(options);
} }
double BundleAdjustment::reprojectionError(int camera) { void BundleAdjustment::_reprojectionErrorMSE(const int camera, double &error, double &npoints) const {
vector<Point2d> observations; vector<Point2d> observations;
vector<Point3d> points; vector<Point3d> points;
...@@ -435,11 +435,24 @@ double BundleAdjustment::reprojectionError(int camera) { ...@@ -435,11 +435,24 @@ double BundleAdjustment::reprojectionError(int camera) {
auto rvec = cameras_[camera]->rvec(); auto rvec = cameras_[camera]->rvec();
auto tvec = cameras_[camera]->tvec(); auto tvec = cameras_[camera]->tvec();
return ftl::calibration::reprojectionError(observations, points, K, Mat::zeros(1, 5, CV_64FC1), rvec, tvec); error = ftl::calibration::reprojectionError(observations, points, K, Mat::zeros(1, 5, CV_64FC1), rvec, tvec);
npoints = points.size();
} }
double BundleAdjustment::reprojectionError() { double BundleAdjustment::reprojectionError(const int camera) const {
double error, ncameras;
_reprojectionErrorMSE(camera, ncameras, error);
return sqrt(error);
}
double BundleAdjustment::reprojectionError() const {
double error = 0.0; double error = 0.0;
for (size_t i = 0; i < cameras_.size(); i++) { error += reprojectionError(i); } double npoints = 0.0;
return error * (1.0 / (double) cameras_.size()); for (size_t i = 0; i < cameras_.size(); i++) {
double e, n;
_reprojectionErrorMSE(i, e, n);
error += e * n;
npoints += n;
}
return sqrt(error / npoints);
} }
#define CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN
#include "catch.hpp" #include "catch.hpp"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment