From 8be40171073d6f3960e8453d1b6db5d1bf937aa2 Mon Sep 17 00:00:00 2001 From: Sebastian Hahta <joseha@utu.fi> Date: Mon, 24 Feb 2020 09:24:59 +0200 Subject: [PATCH] fix RMS error calculation --- components/audio/src/speaker.cpp | 5 ++++ .../include/ftl/calibration/optimize.hpp | 12 ++++++---- components/calibration/src/optimize.cpp | 23 +++++++++++++++---- components/calibration/test/tests.cpp | 1 - 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/components/audio/src/speaker.cpp b/components/audio/src/speaker.cpp index 64c333851..f9ebd5d6e 100644 --- a/components/audio/src/speaker.cpp +++ b/components/audio/src/speaker.cpp @@ -83,6 +83,7 @@ void Speaker::_open(int fsize, int sample, int channels) { buffer_ = new ftl::audio::MonoBuffer16<2000>(sample); } + #ifdef HAVE_PORTAUDIO auto err = Pa_OpenDefaultStream( &stream_, 0, @@ -111,6 +112,10 @@ void Speaker::_open(int fsize, int sample, int channels) { } LOG(INFO) << "Speaker ready."; + #else + LOG(INFO) << "Built without portaudio (no sound)"; + #endif + } void Speaker::queue(int64_t ts, ftl::audio::Frame &frame) { diff --git a/components/calibration/include/ftl/calibration/optimize.hpp b/components/calibration/include/ftl/calibration/optimize.hpp index ea5908fce..1009a97b2 100644 --- a/components/calibration/include/ftl/calibration/optimize.hpp +++ b/components/calibration/include/ftl/calibration/optimize.hpp @@ -119,17 +119,21 @@ public: */ 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: 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 _buildBundleAdjustmentProblem(ceres::Problem& problem, const BundleAdjustment::Options& options); void _buildLengthProblem(ceres::Problem& problem, const BundleAdjustment::Options& options); diff --git a/components/calibration/src/optimize.cpp b/components/calibration/src/optimize.cpp index 9ea70c442..e5319e3fc 100644 --- a/components/calibration/src/optimize.cpp +++ b/components/calibration/src/optimize.cpp @@ -418,7 +418,7 @@ void BundleAdjustment::run() { run(options); } -double BundleAdjustment::reprojectionError(int camera) { +void BundleAdjustment::_reprojectionErrorMSE(const int camera, double &error, double &npoints) const { vector<Point2d> observations; vector<Point3d> points; @@ -435,11 +435,24 @@ double BundleAdjustment::reprojectionError(int camera) { auto rvec = cameras_[camera]->rvec(); 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; - for (size_t i = 0; i < cameras_.size(); i++) { error += reprojectionError(i); } - return error * (1.0 / (double) cameras_.size()); + double npoints = 0.0; + 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); } diff --git a/components/calibration/test/tests.cpp b/components/calibration/test/tests.cpp index 178916eab..0c7c351f4 100644 --- a/components/calibration/test/tests.cpp +++ b/components/calibration/test/tests.cpp @@ -1,3 +1,2 @@ #define CATCH_CONFIG_MAIN #include "catch.hpp" - -- GitLab