From 42a4fd8884604a6af192bffa4517d5877cedc744 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 29 Apr 2015 22:07:10 -0700 Subject: [PATCH] Add velocity filtering of DDE eyebrows --- interface/src/devices/DdeFaceTracker.cpp | 22 +++++++++++++++++----- interface/src/devices/DdeFaceTracker.h | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/interface/src/devices/DdeFaceTracker.cpp b/interface/src/devices/DdeFaceTracker.cpp index be25c0794d..d6cc644db1 100644 --- a/interface/src/devices/DdeFaceTracker.cpp +++ b/interface/src/devices/DdeFaceTracker.cpp @@ -169,7 +169,9 @@ DdeFaceTracker::DdeFaceTracker(const QHostAddress& host, quint16 serverPort, qui _lastLeftEyeBlink(0.0f), _filteredLeftEyeBlink(0.0f), _lastRightEyeBlink(0.0f), - _filteredRightEyeBlink(0.0f) + _filteredRightEyeBlink(0.0f), + _lastBrowUp(0.0f), + _filteredBrowUp(0.0f) { _coefficients.resize(NUM_FACESHIFT_BLENDSHAPES); @@ -389,10 +391,20 @@ void DdeFaceTracker::decodePacket(const QByteArray& buffer) { } // Use BrowsU_C to control both brows' up and down - _coefficients[_browDownLeftIndex] = -_coefficients[_browUpCenterIndex]; - _coefficients[_browDownRightIndex] = -_coefficients[_browUpCenterIndex]; - _coefficients[_browUpLeftIndex] = _coefficients[_browUpCenterIndex]; - _coefficients[_browUpRightIndex] = _coefficients[_browUpCenterIndex]; + float browUp = _coefficients[_browUpCenterIndex]; + if (isFiltering) { + const float BROW_VELOCITY_FILTER_STRENGHT = 0.8f; + float velocity = fabs(browUp - _lastBrowUp) / _averageMessageTime; + float velocityFilter = glm::clamp(velocity * BROW_VELOCITY_FILTER_STRENGHT, 0.0f, 1.0f); + _filteredBrowUp = velocityFilter * browUp + (1.0f - velocityFilter) * _filteredBrowUp; + _lastBrowUp = browUp; + browUp = _filteredBrowUp; + _coefficients[_browUpCenterIndex] = browUp; + } + _coefficients[_browUpLeftIndex] = browUp; + _coefficients[_browUpRightIndex] = browUp; + _coefficients[_browDownLeftIndex] = -browUp; + _coefficients[_browDownRightIndex] = -browUp; // Offset jaw open coefficient static const float JAW_OPEN_THRESHOLD = 0.16f; diff --git a/interface/src/devices/DdeFaceTracker.h b/interface/src/devices/DdeFaceTracker.h index d9df5723cf..d4572c8430 100644 --- a/interface/src/devices/DdeFaceTracker.h +++ b/interface/src/devices/DdeFaceTracker.h @@ -109,6 +109,8 @@ private: float _filteredLeftEyeBlink; float _lastRightEyeBlink; float _filteredRightEyeBlink; + float _lastBrowUp; + float _filteredBrowUp; }; #endif // hifi_DdeFaceTracker_h \ No newline at end of file