summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_filter_ewma2
diff options
context:
space:
mode:
authorDonovan Baarda <abo@minkirri.apana.org.au>2014-10-15 14:07:20 +1100
committerDonovan Baarda <abo@minkirri.apana.org.au>2014-10-15 14:07:20 +1100
commitdbd04e283082ab869a22abf03c4c6280b03935bb (patch)
tree3951c6f91f76047e655f35e04db4eecd576c49df /ftnoir_filter_ewma2
parentd880464fbe9180aefde94594330126e115066dc3 (diff)
parent051a2e4392bc75b246cc5cb897ae0bbb1f92042e (diff)
Merge branch 'unstable' of https://github.com/opentrack/opentrack into dev/kalman
Conflicts: ftnoir_filter_kalman/ftnoir_filter_kalman.h
Diffstat (limited to 'ftnoir_filter_ewma2')
-rw-r--r--ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp88
-rw-r--r--ftnoir_filter_ewma2/ftnoir_filter_ewma2.h35
-rw-r--r--ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp30
-rw-r--r--ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp28
4 files changed, 45 insertions, 136 deletions
diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp
index d3cb2c32..c7169faa 100644
--- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp
+++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp
@@ -1,13 +1,5 @@
-/********************************************************************************
-* FaceTrackNoIR This program is a private project of some enthusiastic *
-* gamers from Holland, who don't like to pay much for *
-* head-tracking. *
-* *
-* Copyright (C) 2012 Wim Vriend (Developing) *
-* Ron Hendriks (Researching and Testing) *
-* *
-* Homepage *
-* *
+/*** Written by Donovan Baarda
+*
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 3 of the License, or (at your *
@@ -23,28 +15,13 @@
* *
********************************************************************************/
#include "ftnoir_filter_ewma2.h"
-#include "math.h"
+#include <cmath>
#include <QDebug>
#include <QWidget>
-#include "facetracknoir/global-settings.h"
+#include "facetracknoir/plugin-support.h"
#include <algorithm>
#include <QMutexLocker>
-///////////////////////////////////////////////////////////////////////////////
-//
-// EWMA Filter: Exponentially Weighted Moving Average filter with dynamic smoothing parameter
-//
-// This filter tries to adjust the amount of filtering to minimize lag when
-// moving, and minimize noise when still. It uses the delta filtered over the
-// last 3 frames (0.1secs) compared to the delta's average noise variance over
-// the last 3600 frames (~2mins) to try and detect movement vs noise. As the
-// delta increases from 0->3 stdevs of the noise, the filtering scales down
-// from maxSmooth->minSmooth at a rate controlled by the powCurve setting.
-//
-// Written by Donovan Baarda
-//
-///////////////////////////////////////////////////////////////////////////////
-
FTNoIR_Filter::FTNoIR_Filter() :
first_run(true),
// Deltas are smoothed over the last 3 frames (0.1sec at 30fps).
@@ -64,46 +41,57 @@ void FTNoIR_Filter::FilterHeadPoseData(const double *target_camera_position,
{
double new_delta, new_noise, norm_noise;
double alpha;
- double pos[6];
//On the first run, initialize to output=target and return.
if (first_run==true) {
for (int i=0;i<6;i++) {
+ new_camera_position[i] = target_camera_position[i];
+ current_camera_position[i] = target_camera_position[i];
delta[i] = 0.0;
noise[i] = 0.0;
- l.write(target_camera_position, target_camera_position, new_camera_position);
}
first_run=false;
return;
}
- if (!l.idempotentp(target_camera_position))
+ bool new_frame = false;
+
+ for (int i = 0; i < 6; i++)
{
- double cur[6];
- l.get_state(cur);
- // Calculate the new camera position.
- for (int i=0;i<6;i++) {
- // Calculate the current and smoothed delta.
- new_delta = target_camera_position[i]-cur[i];
- delta[i] = delta_smoothing*new_delta + (1.0-delta_smoothing)*delta[i];
- // Calculate the current and smoothed noise variance.
- new_noise = delta[i]*delta[i];
- noise[i] = noise_smoothing*new_noise + (1.0-noise_smoothing)*noise[i];
- // Normalise the noise between 0->1 for 0->9 variances (0->3 stddevs).
- norm_noise = std::min<double>(new_noise/(9.0*noise[i]), 1.0);
- // Calculate the alpha from the normalized noise.
- // TODO(abo): change kSmoothingScaleCurve to a float where 1.0 is sqrt(norm_noise).
- alpha = 1.0/(s.kMinSmoothing+(1.0-pow(norm_noise,s.kSmoothingScaleCurve/20.0))*(s.kMaxSmoothing-s.kMinSmoothing));
- // Update the current camera position to the new position.
- double value = alpha*target_camera_position[i] + (1.0-alpha)*cur[i];
- pos[i] = value;
+ if (target_camera_position[i] != current_camera_position[i])
+ {
+ new_frame = true;
+ break;
}
}
- l.write(target_camera_position, pos, new_camera_position);
+ if (!new_frame)
+ {
+ for (int i = 0; i < 6; i++)
+ new_camera_position[i] = current_camera_position[i];
+ return;
+ }
+
+ // Calculate the new camera position.
+ for (int i=0;i<6;i++) {
+ // Calculate the current and smoothed delta.
+ new_delta = target_camera_position[i]-current_camera_position[i];
+ delta[i] = delta_smoothing*new_delta + (1.0-delta_smoothing)*delta[i];
+ // Calculate the current and smoothed noise variance.
+ new_noise = delta[i]*delta[i];
+ noise[i] = noise_smoothing*new_noise + (1.0-noise_smoothing)*noise[i];
+ // Normalise the noise between 0->1 for 0->9 variances (0->3 stddevs).
+ norm_noise = std::min<double>(new_noise/(9.0*noise[i]), 1.0);
+ // Calculate the alpha from the normalized noise.
+ // TODO(abo): change kSmoothingScaleCurve to a float where 1.0 is sqrt(norm_noise).
+ alpha = 1.0/(s.kMinSmoothing+(1.0-pow(norm_noise,s.kSmoothingScaleCurve/20.0))*(s.kMaxSmoothing-s.kMinSmoothing));
+ // Update the current camera position to the new position.
+ double pos = alpha*target_camera_position[i] + (1.0-alpha)*current_camera_position[i];
+ new_camera_position[i] = current_camera_position[i] = pos;
+ }
}
-extern "C" FTNOIR_FILTER_BASE_EXPORT IFilter* CALLING_CONVENTION GetConstructor()
+extern "C" OPENTRACK_EXPORT IFilter* GetConstructor()
{
return new FTNoIR_Filter;
}
diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h
index ea25a135..8863348c 100644
--- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h
+++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h
@@ -1,38 +1,10 @@
-/********************************************************************************
-* FaceTrackNoIR This program is a private project of some enthusiastic *
-* gamers from Holland, who don't like to pay much for *
-* head-tracking. *
-* *
-* Copyright (C) 2012 Wim Vriend (Developing) *
-* Ron Hendriks (Researching and Testing) *
-* *
-* Homepage *
-* *
-* This program is free software; you can redistribute it and/or modify it *
-* under the terms of the GNU General Public License as published by the *
-* Free Software Foundation; either version 3 of the License, or (at your *
-* option) any later version. *
-* *
-* This program is distributed in the hope that it will be useful, but *
-* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
-* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
-* more details. *
-* *
-* You should have received a copy of the GNU General Public License along *
-* with this program; if not, see <http://www.gnu.org/licenses/>. *
-* *
-********************************************************************************/
#pragma once
-#ifndef INCLUDED_FTN_FILTER_H
-#define INCLUDED_FTN_FILTER_H
-#include "ftnoir_filter_base/ftnoir_filter_base.h"
-#include "facetracknoir/global-settings.h"
+#include "facetracknoir/plugin-api.hpp"
#include "ui_ftnoir_ewma_filtercontrols.h"
#include <QWidget>
#include <QMutex>
#include "facetracknoir/options.h"
-#include "facetracknoir/lerp.hpp"
using namespace options;
struct settings {
@@ -62,8 +34,8 @@ private:
double noise_smoothing;
double delta[6];
double noise[6];
+ double current_camera_position[6];
settings s;
- lerp l;
};
class FilterControls: public QWidget, public IFilterDialog
@@ -93,6 +65,3 @@ public:
void getDescription(QString *strToBeFilled) { *strToBeFilled = QString("Exponentially Weighted Moving Average filter with dynamic smoothing parameter"); }
void getIcon(QIcon *icon){ *icon = QIcon(":/images/filter-16.png"); }
};
-
-#endif //INCLUDED_FTN_FILTER_H
-//END
diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp
index fb02354e..b6bde553 100644
--- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp
+++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2_dialog.cpp
@@ -1,31 +1,7 @@
-/********************************************************************************
-* FaceTrackNoIR This program is a private project of some enthusiastic *
-* gamers from Holland, who don't like to pay much for *
-* head-tracking. *
-* *
-* Copyright (C) 2012 Wim Vriend (Developing) *
-* Ron Hendriks (Researching and Testing) *
-* *
-* Homepage *
-* *
-* This program is free software; you can redistribute it and/or modify it *
-* under the terms of the GNU General Public License as published by the *
-* Free Software Foundation; either version 3 of the License, or (at your *
-* option) any later version. *
-* *
-* This program is distributed in the hope that it will be useful, but *
-* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
-* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
-* more details. *
-* *
-* You should have received a copy of the GNU General Public License along *
-* with this program; if not, see <http://www.gnu.org/licenses/>. *
-* *
-********************************************************************************/
#include "ftnoir_filter_ewma2.h"
#include <cmath>
#include <QDebug>
-#include "facetracknoir/global-settings.h"
+#include "facetracknoir/plugin-support.h"
#include "ui_ftnoir_ewma_filtercontrols.h"
FilterControls::FilterControls() :
@@ -57,7 +33,7 @@ void FilterControls::doOK() {
}
void FilterControls::doCancel() {
- s.b->revert();
+ s.b->reload();
this->close();
}
@@ -67,7 +43,7 @@ void FilterControls::save() {
pFilter->receiveSettings();
}
-extern "C" FTNOIR_FILTER_BASE_EXPORT IFilterDialog* CALLING_CONVENTION GetDialog( )
+extern "C" OPENTRACK_EXPORT IFilterDialog* GetDialog( )
{
return new FilterControls;
}
diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp
index 6ef7768e..5ec6138a 100644
--- a/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp
+++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma_dll.cpp
@@ -1,31 +1,7 @@
-/********************************************************************************
-* FaceTrackNoIR This program is a private project of some enthusiastic *
-* gamers from Holland, who don't like to pay much for *
-* head-tracking. *
-* *
-* Copyright (C) 2012 Wim Vriend (Developing) *
-* Ron Hendriks (Researching and Testing) *
-* *
-* Homepage *
-* *
-* This program is free software; you can redistribute it and/or modify it *
-* under the terms of the GNU General Public License as published by the *
-* Free Software Foundation; either version 3 of the License, or (at your *
-* option) any later version. *
-* *
-* This program is distributed in the hope that it will be useful, but *
-* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
-* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
-* more details. *
-* *
-* You should have received a copy of the GNU General Public License along *
-* with this program; if not, see <http://www.gnu.org/licenses/>. *
-* *
-********************************************************************************/
#include "ftnoir_filter_ewma2.h"
-#include "facetracknoir/global-settings.h"
+#include "facetracknoir/plugin-support.h"
-extern "C" FTNOIR_FILTER_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata()
+extern "C" OPENTRACK_EXPORT Metadata* GetMetadata()
{
return new FTNoIR_FilterDll;
}