From 3ffc10b1208fd7afca500cb3caec25b05f9b446d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 12 Jul 2015 10:46:32 +0200 Subject: accela: introduce constants for scaling's magic numbers --- ftnoir_filter_accela/ftnoir_filter_accela.cpp | 10 +++++----- ftnoir_filter_accela/ftnoir_filter_accela.h | 5 +++++ ftnoir_filter_accela/ftnoir_filter_accela_dialog.cpp | 10 +++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.cpp b/ftnoir_filter_accela/ftnoir_filter_accela.cpp index 4d5f4a28..5d89bc96 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.cpp +++ b/ftnoir_filter_accela/ftnoir_filter_accela.cpp @@ -69,16 +69,16 @@ void FTNoIR_Filter::filter(const double* input, double *output) return; } - const double rot_t = 10. * (1+s.rot_threshold) / 100.; - const double trans_t = 5. * (1+s.trans_threshold) / 100.; + const double rot_t = (1+s.rot_threshold) * s.mult_rot; + const double trans_t = (1+s.trans_threshold) * s.mult_trans; const double dt = t.elapsed() * 1e-9; t.start(); - const double RC = 2 * s.ewma / 1000.; // seconds + const double RC = s.mult_ewma * s.ewma / 1000.; // seconds const double alpha = dt/(dt+RC); - const double rot_dz = s.rot_deadzone * 2. / 100.; - const double trans_dz = s.trans_deadzone * 1. / 100.; + const double rot_dz = s.rot_deadzone * s.mult_rot_dz; + const double trans_dz = s.trans_deadzone * s.mult_trans_dz; for (int i = 0; i < 6; i++) { diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.h b/ftnoir_filter_accela/ftnoir_filter_accela.h index e45af03a..4b0d528f 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.h +++ b/ftnoir_filter_accela/ftnoir_filter_accela.h @@ -12,6 +12,11 @@ using namespace options; struct settings : opts { value rot_threshold, trans_threshold, ewma, rot_deadzone, trans_deadzone; + static constexpr double mult_rot = 10. / 100.; + static constexpr double mult_trans = 5. / 100.; + static constexpr double mult_rot_dz = 2. / 100.; + static constexpr double mult_trans_dz = 1. / 100.; + static constexpr double mult_ewma = 2.; settings() : opts("Accela"), rot_threshold(b, "rotation-threshold", 30), diff --git a/ftnoir_filter_accela/ftnoir_filter_accela_dialog.cpp b/ftnoir_filter_accela/ftnoir_filter_accela_dialog.cpp index 52c8318a..dbac8362 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela_dialog.cpp +++ b/ftnoir_filter_accela/ftnoir_filter_accela_dialog.cpp @@ -62,27 +62,27 @@ void FilterControls::save() { void FilterControls::update_rot_display(int value) { - ui.rot_gain->setText(QString::number((value + 1) * 10 / 100.) + "°"); + ui.rot_gain->setText(QString::number((value + 1) * s.mult_rot) + "°"); } void FilterControls::update_trans_display(int value) { - ui.trans_gain->setText(QString::number((value + 1) * 5 / 100.) + "mm"); + ui.trans_gain->setText(QString::number((value + 1) * s.mult_trans) + "mm"); } void FilterControls::update_ewma_display(int value) { - ui.ewma_label->setText(QString::number(value * 2) + "ms"); + ui.ewma_label->setText(QString::number(value * s.mult_ewma) + "ms"); } void FilterControls::update_rot_dz_display(int value) { - ui.rot_dz->setText(QString::number(value * 2 / 100.) + "°"); + ui.rot_dz->setText(QString::number(value * s.mult_rot_dz) + "°"); } void FilterControls::update_trans_dz_display(int value) { - ui.trans_dz->setText(QString::number(value * 1 / 100.) + "mm"); + ui.trans_dz->setText(QString::number(value * s.mult_trans_dz) + "mm"); } extern "C" OPENTRACK_EXPORT IFilterDialog* GetDialog() -- cgit v1.2.3 From 3faf980973e03b049782027f7aafc9a7f4c9c39e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 12 Jul 2015 11:46:58 +0200 Subject: kalman: add settings support Filter performance still not good though. --- ftnoir_filter_kalman/ftnoir_filter_kalman.h | 19 ++++- .../ftnoir_kalman_filtercontrols.ui | 85 ++++++++++++++-------- ftnoir_filter_kalman/kalman.cpp | 11 ++- 3 files changed, 80 insertions(+), 35 deletions(-) diff --git a/ftnoir_filter_kalman/ftnoir_filter_kalman.h b/ftnoir_filter_kalman/ftnoir_filter_kalman.h index f6224530..1f0b36fd 100755 --- a/ftnoir_filter_kalman/ftnoir_filter_kalman.h +++ b/ftnoir_filter_kalman/ftnoir_filter_kalman.h @@ -19,6 +19,14 @@ #include "opentrack/options.hpp" using namespace options; +struct settings : opts { + value noise_stddev_slider; + // slider goes noise_stdder 0->50 + static constexpr double mult_noise_stddev = .5; + settings() : opts("kalman-filter"), noise_stddev_slider(b, "noise-stddev", 10) + {} +}; + class OPENTRACK_EXPORT FTNoIR_Filter : public IFilter { public: @@ -28,10 +36,12 @@ public: // Set accel_stddev assuming moving 0.0->100.0 in dt=0.2 is 3 stddevs: (100.0*4/dt^2)/3. const double accel_stddev = (100.0*4/(0.2*0.2))/3.0; // TODO(abo): make noise_stddev a UI setting 0.0->10.0 with 0.1 resolution. - const double noise_stddev = 1.0; + //const double noise_stddev = 1.0; cv::KalmanFilter kalman; double last_input[6]; QElapsedTimer timer; + settings s; + int prev_slider_pos; }; class OPENTRACK_EXPORT FTNoIR_FilterDll : public Metadata @@ -47,13 +57,14 @@ class OPENTRACK_EXPORT FilterControls: public IFilterDialog public: FilterControls() { ui.setupUi(this); - connect(ui.btnOk, SIGNAL(clicked()), this, SLOT(doOK())); - connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); - show(); + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); + tie_setting(s.noise_stddev_slider, ui.noise_slider); } Ui::KalmanUICFilterControls ui; void register_filter(IFilter*) override {} void unregister_filter() override {} + settings s; public slots: void doOK(); void doCancel(); diff --git a/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui b/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui index e0c849c9..69297102 100644 --- a/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui +++ b/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui @@ -9,8 +9,8 @@ 0 0 - 334 - 100 + 288 + 132 @@ -23,7 +23,7 @@ Kalman settings - + :/images/filter-16.png:/images/filter-16.png @@ -35,35 +35,60 @@ - - - - 173 - 70 - 73 - 25 - - - - OK - - - - - - 250 - 70 - 73 - 25 - - - - Cancel - - + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + + + Noise standard deviation + + + + + + + 1 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + 10 + + + + + + + + + + Written by Donovan Baarda, 2014 + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + - + diff --git a/ftnoir_filter_kalman/kalman.cpp b/ftnoir_filter_kalman/kalman.cpp index c5a600af..4939610b 100644 --- a/ftnoir_filter_kalman/kalman.cpp +++ b/ftnoir_filter_kalman/kalman.cpp @@ -11,6 +11,7 @@ FTNoIR_Filter::FTNoIR_Filter() { reset(); + prev_slider_pos = s.noise_stddev_slider; } // the following was written by Donovan Baarda @@ -56,7 +57,8 @@ void FTNoIR_Filter::reset() { 0, 0, 0, 0, b, 0, 0, 0, 0, 0, a, 0, 0, 0, 0, 0, 0, b, 0, 0, 0, 0, 0, a); cv::setIdentity(kalman.measurementMatrix); - double noise_variance = noise_stddev * noise_stddev; + const double noise_stddev = s.noise_stddev_slider * s.mult_noise_stddev; + const double noise_variance = noise_stddev * noise_stddev; cv::setIdentity(kalman.measurementNoiseCov, cv::Scalar::all(noise_variance)); cv::setIdentity(kalman.errorCovPost, cv::Scalar::all(accel_variance * 1e4)); for (int i = 0; i < 6; i++) { @@ -67,6 +69,11 @@ void FTNoIR_Filter::reset() { void FTNoIR_Filter::filter(const double* input, double *output) { + if (prev_slider_pos != s.noise_stddev_slider) + { + reset(); + prev_slider_pos = s.noise_stddev_slider; + } // Start the timer if it's not running. if (!timer.isValid()) timer.start(); @@ -108,10 +115,12 @@ void FTNoIR_Filter::filter(const double* input, double *output) } void FilterControls::doOK() { + s.b->save(); close(); } void FilterControls::doCancel() { + s.b->reload(); close(); } -- cgit v1.2.3 From f5e0eff0680cae4aacfbf832b8a11827bfeba8d5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 12 Jul 2015 12:20:56 +0200 Subject: kalman fixes, still not working well --- ftnoir_filter_kalman/ftnoir_filter_kalman.h | 12 ++++++------ ftnoir_filter_kalman/kalman.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ftnoir_filter_kalman/ftnoir_filter_kalman.h b/ftnoir_filter_kalman/ftnoir_filter_kalman.h index 1f0b36fd..e84ef347 100755 --- a/ftnoir_filter_kalman/ftnoir_filter_kalman.h +++ b/ftnoir_filter_kalman/ftnoir_filter_kalman.h @@ -21,9 +21,9 @@ using namespace options; struct settings : opts { value noise_stddev_slider; - // slider goes noise_stdder 0->50 + // slider for noise_stddev goes 0->(mult_noise_stddev * 100) static constexpr double mult_noise_stddev = .5; - settings() : opts("kalman-filter"), noise_stddev_slider(b, "noise-stddev", 10) + settings() : opts("kalman-filter"), noise_stddev_slider(b, "noise-stddev", 40) {} }; @@ -33,10 +33,10 @@ public: FTNoIR_Filter(); void reset(); void filter(const double *input, double *output); - // Set accel_stddev assuming moving 0.0->100.0 in dt=0.2 is 3 stddevs: (100.0*4/dt^2)/3. - const double accel_stddev = (100.0*4/(0.2*0.2))/3.0; - // TODO(abo): make noise_stddev a UI setting 0.0->10.0 with 0.1 resolution. - //const double noise_stddev = 1.0; + // Set accel_stddev assuming moving 0.0->accel in dt_ is 3 stddevs: (accel*4/dt_^2)/3. + static constexpr double dt_ = .4; + static constexpr double accel = 60.; + static constexpr double accel_stddev = (accel*4/(dt_*dt_))/3.0; cv::KalmanFilter kalman; double last_input[6]; QElapsedTimer timer; diff --git a/ftnoir_filter_kalman/kalman.cpp b/ftnoir_filter_kalman/kalman.cpp index 4939610b..08b46f0f 100644 --- a/ftnoir_filter_kalman/kalman.cpp +++ b/ftnoir_filter_kalman/kalman.cpp @@ -57,7 +57,7 @@ void FTNoIR_Filter::reset() { 0, 0, 0, 0, b, 0, 0, 0, 0, 0, a, 0, 0, 0, 0, 0, 0, b, 0, 0, 0, 0, 0, a); cv::setIdentity(kalman.measurementMatrix); - const double noise_stddev = s.noise_stddev_slider * s.mult_noise_stddev; + const double noise_stddev = (1+s.noise_stddev_slider) * s.mult_noise_stddev; const double noise_variance = noise_stddev * noise_stddev; cv::setIdentity(kalman.measurementNoiseCov, cv::Scalar::all(noise_variance)); cv::setIdentity(kalman.errorCovPost, cv::Scalar::all(accel_variance * 1e4)); -- cgit v1.2.3 From f19017548381ab1dabc11e312acc790253d8b07d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 13 Jul 2015 05:44:41 +0200 Subject: cmake: run install-fail-tool on OSX --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b483000d..2c38b4d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -541,3 +541,9 @@ endif() if(WIN32) install(FILES "${CMAKE_SOURCE_DIR}/bin/cleye.config" DESTINATION .) endif() + +if(APPLE) + install(CODE " + execute_process(COMMAND /bin/sh \"${CMAKE_SOURCE_DIR}/install-fail-tool\" \"${CMAKE_INSTALL_PREFIX}\") + ") +endif() -- cgit v1.2.3 From c1503fe8eda914541415ece61e53001060c6e5ae Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 13 Jul 2015 07:07:16 +0200 Subject: reformat only --- ftnoir_tracker_pt/camera.cpp | 74 ++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/ftnoir_tracker_pt/camera.cpp b/ftnoir_tracker_pt/camera.cpp index eaf51e17..9168a3e4 100644 --- a/ftnoir_tracker_pt/camera.cpp +++ b/ftnoir_tracker_pt/camera.cpp @@ -16,39 +16,39 @@ using namespace cv; // ---------------------------------------------------------------------------- void get_camera_device_names(std::vector& device_names) { - videoInput VI; - VI.listDevices(); - std::string device_name; - for(int index = 0; ; ++index) { - device_name = VI.getDeviceName(index); - if (device_name.empty()) break; - device_names.push_back(device_name); - } + videoInput VI; + VI.listDevices(); + std::string device_name; + for(int index = 0; ; ++index) { + device_name = VI.getDeviceName(index); + if (device_name.empty()) break; + device_names.push_back(device_name); + } } #endif // ---------------------------------------------------------------------------- void Camera::set_device_index(int index) { - if (desired_index != index) - { - desired_index = index; - _set_device_index(); + if (desired_index != index) + { + desired_index = index; + _set_device_index(); - // reset fps - dt_valid = 0; - dt_mean = 0; - active_index = index; - } + // reset fps + dt_valid = 0; + dt_mean = 0; + active_index = index; + } } void Camera::set_fps(int fps) { - if (cam_desired.fps != fps) - { - cam_desired.fps = fps; - _set_fps(); - } + if (cam_desired.fps != fps) + { + cam_desired.fps = fps; + _set_fps(); + } } void Camera::set_res(int x_res, int y_res) @@ -63,17 +63,17 @@ void Camera::set_res(int x_res, int y_res) bool Camera::get_frame(float dt, cv::Mat* frame) { - bool new_frame = _get_frame(frame); - // measure fps of valid frames - const float dt_smoothing_const = 0.9; - dt_valid += dt; - if (new_frame) - { - dt_mean = dt_smoothing_const * dt_mean + (1.0 - dt_smoothing_const) * dt_valid; - cam_info.fps = dt_mean > 1e-3 ? 1.0 / dt_mean : 0; - dt_valid = 0; - } - return new_frame; + bool new_frame = _get_frame(frame); + // measure fps of valid frames + const float dt_smoothing_const = 0.9; + dt_valid += dt; + if (new_frame) + { + dt_mean = dt_smoothing_const * dt_mean + (1.0 - dt_smoothing_const) * dt_valid; + cam_info.fps = dt_mean > 1e-3 ? 1.0 / dt_mean : 0; + dt_valid = 0; + } + return new_frame; } void CVCamera::start() @@ -118,10 +118,10 @@ bool CVCamera::_get_frame(Mat* frame) if (img.empty()) return false; - *frame = img; - cam_info.res_x = img.cols; - cam_info.res_y = img.rows; - return true; + *frame = img; + cam_info.res_x = img.cols; + cam_info.res_y = img.rows; + return true; } return false; } -- cgit v1.2.3 From edfde661b2d1ff0b891056b22dc7ca2f92b62206 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 13 Jul 2015 19:04:05 +0200 Subject: ht: move docs --- 3rdparty-notices/HEADTRACKER-LICENSE.txt | 32 ++++++++++++++++++++++++++++++++ bin/tracker-ht/cleye.config | 4 ---- bin/tracker-ht/license.txt | 32 -------------------------------- bin/tracker-ht/thanks.txt | 5 ----- 4 files changed, 32 insertions(+), 41 deletions(-) create mode 100644 3rdparty-notices/HEADTRACKER-LICENSE.txt delete mode 100644 bin/tracker-ht/cleye.config delete mode 100644 bin/tracker-ht/license.txt delete mode 100644 bin/tracker-ht/thanks.txt diff --git a/3rdparty-notices/HEADTRACKER-LICENSE.txt b/3rdparty-notices/HEADTRACKER-LICENSE.txt new file mode 100644 index 00000000..a1a778e6 --- /dev/null +++ b/3rdparty-notices/HEADTRACKER-LICENSE.txt @@ -0,0 +1,32 @@ +Copyright (c) 2012-2013 Stanisław Halik + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +------------------------------------------------------------------------ + +Credit for the head mesh: + +Jed Frechette submitted the mesh as a pull request. +I cannot thank him enough! + +------------------------------------------------------------------------ + +The project links against the flandmark library, written by +Michal Uřičář and Vojtěch Franc. The library is GPL3-licensed. + +More info at: http://cmp.felk.cvut.cz/~uricamic/flandmark +Github repo: https://github.com/uricamic/flandmark + +------------------------------------------------------------------------ + +The projects uses OpenCV, see http://code.opencv.org for more info. \ No newline at end of file diff --git a/bin/tracker-ht/cleye.config b/bin/tracker-ht/cleye.config deleted file mode 100644 index bfb37b47..00000000 --- a/bin/tracker-ht/cleye.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/bin/tracker-ht/license.txt b/bin/tracker-ht/license.txt deleted file mode 100644 index a1a778e6..00000000 --- a/bin/tracker-ht/license.txt +++ /dev/null @@ -1,32 +0,0 @@ -Copyright (c) 2012-2013 Stanisław Halik - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ------------------------------------------------------------------------- - -Credit for the head mesh: - -Jed Frechette submitted the mesh as a pull request. -I cannot thank him enough! - ------------------------------------------------------------------------- - -The project links against the flandmark library, written by -Michal Uřičář and Vojtěch Franc. The library is GPL3-licensed. - -More info at: http://cmp.felk.cvut.cz/~uricamic/flandmark -Github repo: https://github.com/uricamic/flandmark - ------------------------------------------------------------------------- - -The projects uses OpenCV, see http://code.opencv.org for more info. \ No newline at end of file diff --git a/bin/tracker-ht/thanks.txt b/bin/tracker-ht/thanks.txt deleted file mode 100644 index 42612dfa..00000000 --- a/bin/tracker-ht/thanks.txt +++ /dev/null @@ -1,5 +0,0 @@ -The following people deserve thanks for their work on libheadtracker: - -The awesome head mesh, made using a 3D scanner was made by -Jed Frechette. I cannot thank him enough, given how much it -helped improve the program. \ No newline at end of file -- cgit v1.2.3 From 279d6c1b0534edd7c49f2f1fbf56acf9ed1c4a21 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 13 Jul 2015 19:04:22 +0200 Subject: allow for camera calibration --- CMakeLists.txt | 2 ++ bin/camera/Logitech HD Webcam C525.yml | 22 ++++++++++++++++++++++ bin/camera/PS3Eye Camera.yml | 22 ++++++++++++++++++++++ opentrack/opencv-calibration.hpp | 26 ++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 bin/camera/Logitech HD Webcam C525.yml create mode 100644 bin/camera/PS3Eye Camera.yml create mode 100644 opentrack/opencv-calibration.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c38b4d2..8a14b81f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -542,6 +542,8 @@ if(WIN32) install(FILES "${CMAKE_SOURCE_DIR}/bin/cleye.config" DESTINATION .) endif() +install(DIRECTORY "${CMAKE_SOURCE_DIR}/bin/camera" DESTINATION .) + if(APPLE) install(CODE " execute_process(COMMAND /bin/sh \"${CMAKE_SOURCE_DIR}/install-fail-tool\" \"${CMAKE_INSTALL_PREFIX}\") diff --git a/bin/camera/Logitech HD Webcam C525.yml b/bin/camera/Logitech HD Webcam C525.yml new file mode 100644 index 00000000..ac1bc981 --- /dev/null +++ b/bin/camera/Logitech HD Webcam C525.yml @@ -0,0 +1,22 @@ +%YAML:1.0 +calibration_time: "07/13/15 17:32:58" +image_width: 640 +image_height: 480 +board_width: 24 +board_height: 15 +square_size: 1. +flags: 0 +camera_matrix: !!opencv-matrix + rows: 3 + cols: 3 + dt: d + data: [ 7.1195238148354849e+002, 0., 3.4210284784635138e+002, 0., + 7.1302752784110055e+002, 2.2837679451205264e+002, 0., 0., 1. ] +distortion_coefficients: !!opencv-matrix + rows: 5 + cols: 1 + dt: d + data: [ -1.5165615866415242e-003, 3.6806867018034255e-002, + -6.6432394998828278e-004, 1.7782694073348656e-003, + -4.9225052904494471e-001 ] +avg_reprojection_error: 2.5310746466741296e+000 diff --git a/bin/camera/PS3Eye Camera.yml b/bin/camera/PS3Eye Camera.yml new file mode 100644 index 00000000..6859d0fb --- /dev/null +++ b/bin/camera/PS3Eye Camera.yml @@ -0,0 +1,22 @@ +%YAML:1.0 +calibration_time: "07/13/15 17:45:33" +image_width: 640 +image_height: 480 +board_width: 24 +board_height: 15 +square_size: 1. +flags: 0 +camera_matrix: !!opencv-matrix + rows: 3 + cols: 3 + dt: d + data: [ 7.5119574967224673e+002, 0., 3.2806930334341007e+002, 0., + 7.5112907969240291e+002, 2.2681331450818737e+002, 0., 0., 1. ] +distortion_coefficients: !!opencv-matrix + rows: 5 + cols: 1 + dt: d + data: [ -2.2741190107950382e-001, 9.4372681451250684e-001, + -4.0955586655475494e-003, -2.6778551080439902e-003, + -1.7969804313130640e+000 ] +avg_reprojection_error: 1.9233386799903629e+000 diff --git a/opentrack/opencv-calibration.hpp b/opentrack/opencv-calibration.hpp new file mode 100644 index 00000000..6dee9908 --- /dev/null +++ b/opentrack/opencv-calibration.hpp @@ -0,0 +1,26 @@ +#pragma once +#include +#include +#include +#include +#include + +template +bool get_camera_calibration(const QString& camera_name, cv::Mat& intrinsics, cv::Mat& distortion, int w, int h) +{ + QString pathname_ = QCoreApplication::applicationDirPath() + "/camera/" + camera_name + ".yml"; + std::string pathname = pathname_.toStdString(); + cv::FileStorage fs(pathname, cv::FileStorage::READ); + if (!fs.isOpened()) + return false; + cv::Mat intrinsics_, distortion_; + fs["camera_matrix"] >> intrinsics_; + fs["distortion_coefficients"] >> distortion_; + intrinsics_.at(0, 0) *= w / 640.; + intrinsics_.at(2, 0) *= w / 640.; + intrinsics_.at(1, 1) *= h / 480.; + intrinsics_.at(2, 1) *= h / 480.; + intrinsics = intrinsics_; + distortion = distortion_; + return true; +} -- cgit v1.2.3 From 513d3d0f71670493f8cb95eda80ad55e041680df Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 13 Jul 2015 19:04:59 +0200 Subject: pt, ht, aruco: use calibration data. rename fov to diagonal in UI --- ftnoir_tracker_aruco/aruco-trackercontrols.ui | 4 ++-- ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 33 ++++++++++++++++++++------- ftnoir_tracker_ht/ftnoir_tracker_ht.cpp | 1 + ftnoir_tracker_ht/ht-trackercontrols.ui | 2 +- ftnoir_tracker_pt/FTNoIR_PT_Controls.ui | 2 +- ftnoir_tracker_pt/ftnoir_tracker_pt.cpp | 9 +++++--- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/ftnoir_tracker_aruco/aruco-trackercontrols.ui b/ftnoir_tracker_aruco/aruco-trackercontrols.ui index 4433c47c..bc384f39 100644 --- a/ftnoir_tracker_aruco/aruco-trackercontrols.ui +++ b/ftnoir_tracker_aruco/aruco-trackercontrols.ui @@ -9,7 +9,7 @@ 0 0 - 586 + 485 202 @@ -109,7 +109,7 @@ - Horizontal FOV + Diagonal FOV diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp index 70af379d..6d87503f 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp @@ -18,6 +18,7 @@ #include #include "opentrack/camera-names.hpp" #include "opentrack/thread.hpp" +#include "opentrack/opencv-calibration.hpp" typedef struct { int width; @@ -134,6 +135,9 @@ void Tracker::run() double failed = 0; const double max_failed = 1.25; cv::Vec3d rvec, tvec; + double last_fov = -1; + cv::Mat intrinsics = cv::Mat::eye(3, 3, CV_32FC1); + cv::Mat dist_coeffs = cv::Mat::zeros(5, 1, CV_32FC1); while (!stop) { @@ -150,15 +154,28 @@ void Tracker::run() const int scale = grayscale.cols > 480 ? 2 : 1; detector.setThresholdParams(box_sizes[box_idx], 5); - const float focal_length_w = 0.5 * grayscale.cols / tan(0.5 * s.fov * HT_PI / 180); - const float focal_length_h = 0.5 * grayscale.rows / tan(0.5 * s.fov * grayscale.rows / grayscale.cols * HT_PI / 180.0); - cv::Mat intrinsics = cv::Mat::eye(3, 3, CV_32FC1); - intrinsics.at (0, 0) = focal_length_w; - intrinsics.at (1, 1) = focal_length_h; - intrinsics.at (0, 2) = grayscale.cols/2; - intrinsics.at (1, 2) = grayscale.rows/2; + static constexpr double pi = 3.1415926f; + const int w = grayscale.cols, h = grayscale.rows; + const double diag = sqrt(w * w + h * h)/w, diag_fov = static_cast(s.fov) * pi / 180.; + const double fov = 2.*atan(tan(diag_fov/2.)/sqrt(1. + diag*diag)); + const float focal_length_w = .5 * w / tan(.5 * fov); + const float focal_length_h = focal_length_w; - cv::Mat dist_coeffs = cv::Mat::zeros(5, 1, CV_32FC1); + if (last_fov != s.fov) + { + last_fov = s.fov; + if (!get_camera_calibration(static_cast(s.camera_name), intrinsics, dist_coeffs, grayscale.cols, grayscale.rows)) + { + intrinsics.at (0, 0) = focal_length_w; + intrinsics.at (1, 1) = focal_length_h; + intrinsics.at (0, 2) = grayscale.cols/2; + intrinsics.at (1, 2) = grayscale.rows/2; + } + else + { + qDebug() << "got calibration"; + } + } std::vector< aruco::Marker > markers; diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp index deb90ee5..1ec0e13f 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp @@ -42,6 +42,7 @@ void Tracker::load_settings(ht_config_t* config) break; } + static constexpr float pi = 3.14159265358979323846f; config->classification_delay = 500; config->field_of_view = s.fov; config->max_keypoints = 150; diff --git a/ftnoir_tracker_ht/ht-trackercontrols.ui b/ftnoir_tracker_ht/ht-trackercontrols.ui index dd5e57f3..29b80c8d 100644 --- a/ftnoir_tracker_ht/ht-trackercontrols.ui +++ b/ftnoir_tracker_ht/ht-trackercontrols.ui @@ -55,7 +55,7 @@ - Horizontal FOV + Diagonal FOV diff --git a/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui b/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui index 3e900e8e..928b1374 100644 --- a/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui +++ b/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui @@ -114,7 +114,7 @@ - Field of view + Diagonal field of view diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp index dc0659e5..5b9ec8b6 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp @@ -54,9 +54,12 @@ void Tracker_PT::reset_command(Command command) float Tracker_PT::get_focal_length() { - static constexpr float pi = 3.1415926f; - const float fov = static_cast(s.fov) * pi / 180.f; - return 0.5f / tan(0.5f * fov); + CamInfo info = camera.get_info(); + const int w = info.res_x, h = info.res_y; + static constexpr double pi = 3.1415926f; + const double diag = sqrt(w * w + h * h)/w, diag_fov = static_cast(s.fov) * pi / 180.; + const double fov = 2.*atan(tan(diag_fov/2.0)/sqrt(1. + diag*diag)); + return .5 / tan(.5 * fov); } void Tracker_PT::run() -- cgit v1.2.3 From ec054c285c22ef1ff54841adb25f2d5abe41bdcb Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 14 Jul 2015 09:25:42 +0200 Subject: buffer flush --- ftnoir_tracker_ht/ftnoir_tracker_ht.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp index 1ec0e13f..577ae40d 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp @@ -42,16 +42,15 @@ void Tracker::load_settings(ht_config_t* config) break; } - static constexpr float pi = 3.14159265358979323846f; config->classification_delay = 500; config->field_of_view = s.fov; config->max_keypoints = 150; - config->keypoint_distance = 3.4; + config->keypoint_distance = 3.5; config->force_fps = nframes; config->camera_index = camera_name_to_index(s.camera_name); - config->ransac_max_reprojection_error = 8; - config->ransac_max_inlier_error = 8; + config->ransac_max_reprojection_error = 25; + config->ransac_max_inlier_error = config->ransac_max_reprojection_error; config->pyrlk_pyramids = 0; config->pyrlk_win_size_w = config->pyrlk_win_size_h = 21; @@ -59,8 +58,8 @@ void Tracker::load_settings(ht_config_t* config) config->ransac_max_mean_error = 999; config->ransac_abs_max_mean_error = 999; - config->debug = 0; - config->ransac_min_features = 0.85; + config->debug = 1; + config->ransac_min_features = 0.95; config->ransac_num_iters = 300; int res = s.resolution; -- cgit v1.2.3