From 5a63e2a7735fa982885b1164e35aedbaabf95047 Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Mon, 24 Jan 2011 21:18:52 +0000 Subject: EWMA2-filter implemented. git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@43 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FaceTrackNoIR/FaceTrackNoIR.cpp | 66 ++-- FaceTrackNoIR/FaceTrackNoIR.h | 9 +- FaceTrackNoIR/FaceTrackNoIR.ui | 686 ++++++++++++++++------------------------ FaceTrackNoIR/tracker.cpp | 47 ++- FaceTrackNoIR/tracker.h | 14 +- 5 files changed, 337 insertions(+), 485 deletions(-) (limited to 'FaceTrackNoIR') diff --git a/FaceTrackNoIR/FaceTrackNoIR.cpp b/FaceTrackNoIR/FaceTrackNoIR.cpp index fb48b149..cec69d44 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.cpp +++ b/FaceTrackNoIR/FaceTrackNoIR.cpp @@ -117,12 +117,9 @@ void FaceTrackNoIR::setupFaceTrackNoIR() { connect(ui.chkUseEWMA, SIGNAL(stateChanged(int)), this, SLOT(setUseFilter(int))); // Connect sliders for reduction factor - connect(ui.redYaw, SIGNAL(valueChanged(int)), this, SLOT(setRedYaw(int))); - connect(ui.redRoll, SIGNAL(valueChanged(int)), this, SLOT(setRedRoll(int))); - connect(ui.redPitch, SIGNAL(valueChanged(int)), this, SLOT(setRedPitch(int))); - connect(ui.redX, SIGNAL(valueChanged(int)), this, SLOT(setRedX(int))); - connect(ui.redY, SIGNAL(valueChanged(int)), this, SLOT(setRedY(int))); - connect(ui.redZ, SIGNAL(valueChanged(int)), this, SLOT(setRedZ(int))); + connect(ui.minSmooth, SIGNAL(valueChanged(int)), this, SLOT(setMinSmooth(int))); + connect(ui.maxSmooth, SIGNAL(valueChanged(int)), this, SLOT(setMaxSmooth(int))); + connect(ui.powCurve, SIGNAL(valueChanged(int)), this, SLOT(setPowCurve(int))); // Connect slider for smoothing connect(ui.slideSmoothing, SIGNAL(valueChanged(int)), this, SLOT(setSmoothing(int))); @@ -310,12 +307,9 @@ void FaceTrackNoIR::save() { iniFile.setValue ( "invertY", ui.chkInvertY->isChecked() ); iniFile.setValue ( "invertZ", ui.chkInvertZ->isChecked() ); iniFile.setValue ( "useEWMA", ui.chkUseEWMA->isChecked() ); - iniFile.setValue ( "redYaw", ui.redYaw->value() ); - iniFile.setValue ( "redPitch", ui.redPitch->value() ); - iniFile.setValue ( "redRoll", ui.redRoll->value() ); - iniFile.setValue ( "redX", ui.redX->value() ); - iniFile.setValue ( "redY", ui.redY->value() ); - iniFile.setValue ( "redZ", ui.redZ->value() ); + iniFile.setValue ( "minSmooth", ui.minSmooth->value() ); + iniFile.setValue ( "powCurve", ui.powCurve->value() ); + iniFile.setValue ( "maxSmooth", ui.maxSmooth->value() ); iniFile.endGroup (); iniFile.beginGroup ( "GameProtocol" ); @@ -429,12 +423,9 @@ void FaceTrackNoIR::loadSettings() { ui.chkInvertY->setChecked (iniFile.value ( "invertY", 0 ).toBool()); ui.chkInvertZ->setChecked (iniFile.value ( "invertZ", 0 ).toBool()); ui.chkUseEWMA->setChecked (iniFile.value ( "useEWMA", 1 ).toBool()); - ui.redYaw->setValue (iniFile.value ( "redYaw", 70 ).toInt()); - ui.redPitch->setValue (iniFile.value ( "redPitch", 70 ).toInt()); - ui.redRoll->setValue (iniFile.value ( "redRoll", 70 ).toInt()); - ui.redX->setValue (iniFile.value ( "redX", 70 ).toInt()); - ui.redY->setValue (iniFile.value ( "redY", 70 ).toInt()); - ui.redZ->setValue (iniFile.value ( "redZ", 70 ).toInt()); + ui.minSmooth->setValue (iniFile.value ( "minSmooth", 2 ).toInt()); + ui.powCurve->setValue (iniFile.value ( "powCurve", 10 ).toInt()); + ui.maxSmooth->setValue (iniFile.value ( "maxSmooth", 10 ).toInt()); iniFile.endGroup (); iniFile.beginGroup ( "GameProtocol" ); @@ -509,12 +500,9 @@ void FaceTrackNoIR::startTracker( ) { tracker->setInvertY (ui.chkInvertY->isChecked() ); tracker->setInvertZ (ui.chkInvertZ->isChecked() ); - tracker->setRedYaw (ui.redYaw->value() ); - tracker->setRedPitch (ui.redPitch->value() ); - tracker->setRedRoll (ui.redRoll->value() ); - tracker->setRedX (ui.redX->value() ); - tracker->setRedY (ui.redY->value() ); - tracker->setRedZ (ui.redZ->value() ); + tracker->setMinSmooth (ui.minSmooth->value() ); + tracker->setPowCurve (ui.powCurve->value() ); + tracker->setMaxSmooth (ui.maxSmooth->value() ); tracker->start( QThread::TimeCriticalPriority ); @@ -635,38 +623,20 @@ void FaceTrackNoIR::setUseFilter( int set ) { } /** set the redhold from the slider **/ -void FaceTrackNoIR::setRedYaw( int redh ) { - Tracker::setRedYaw ( redh ); +void FaceTrackNoIR::setMinSmooth( int redh ) { + Tracker::setMinSmooth ( redh ); settingsDirty = true; } /** set the redhold from the slider **/ -void FaceTrackNoIR::setRedPitch( int redh ) { - Tracker::setRedPitch ( redh ); +void FaceTrackNoIR::setPowCurve( int redh ) { + Tracker::setPowCurve ( redh ); settingsDirty = true; } /** set the redhold from the slider **/ -void FaceTrackNoIR::setRedRoll( int redh ) { - Tracker::setRedRoll ( redh ); - settingsDirty = true; -} - -/** set the redhold from the slider **/ -void FaceTrackNoIR::setRedX( int redh ) { - Tracker::setRedX ( redh ); - settingsDirty = true; -} - -/** set the redhold from the slider **/ -void FaceTrackNoIR::setRedY( int redh ) { - Tracker::setRedY ( redh ); - settingsDirty = true; -} - -/** set the redhold from the slider **/ -void FaceTrackNoIR::setRedZ( int redh ) { - Tracker::setRedZ ( redh ); +void FaceTrackNoIR::setMaxSmooth( int redh ) { + Tracker::setMaxSmooth ( redh ); settingsDirty = true; } diff --git a/FaceTrackNoIR/FaceTrackNoIR.h b/FaceTrackNoIR/FaceTrackNoIR.h index 984b09c0..c1d48a4b 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.h +++ b/FaceTrackNoIR/FaceTrackNoIR.h @@ -136,12 +136,9 @@ private: void setUseFilter( int set ); // reduction factor sliders - void setRedYaw( int redh ); - void setRedPitch( int redh ); - void setRedRoll( int redh ); - void setRedX( int redh ); - void setRedY( int redh ); - void setRedZ( int redh ); + void setMinSmooth( int redh ); + void setMaxSmooth( int redh ); + void setPowCurve( int redh ); //smoothing slider void setSmoothing( int smooth ); diff --git a/FaceTrackNoIR/FaceTrackNoIR.ui b/FaceTrackNoIR/FaceTrackNoIR.ui index 15d960bd..22e5bcf4 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.ui +++ b/FaceTrackNoIR/FaceTrackNoIR.ui @@ -1244,115 +1244,17 @@ background:none; - - - - - 25 - 0 - - - - - 150 - 16777215 - - - - Qt::RightToLeft - - - color:#ccc; -background:none; - - - Yaw - - - - - - - - 25 - 0 - - - - - 150 - 16777215 - - - - Qt::RightToLeft - - - color:#ccc; -background:none; - - - Pitch - - - - - - - - 25 - 0 - - - - - 150 - 16777215 - - - - Qt::RightToLeft - - - color:#ccc; -background:none; - - - Roll - - - - - - - - 110 - 0 - - - - - 150 - 16777215 - - - - color:#ccc; -background:none; - - - Red.factor (100 = 1) - - - - + 45 15 + + 1 + 100 @@ -1360,7 +1262,7 @@ background:none; 10 - 70 + 2 Qt::Horizontal @@ -1371,13 +1273,16 @@ background:none; - + 45 15 + + 1 + 100 @@ -1385,7 +1290,7 @@ background:none; 10 - 70 + 10 Qt::Horizontal @@ -1396,13 +1301,16 @@ background:none; - + 45 15 + + 1 + 100 @@ -1410,7 +1318,7 @@ background:none; 10 - 70 + 10 Qt::Horizontal @@ -1421,7 +1329,7 @@ background:none; - + 40 @@ -1431,6 +1339,9 @@ background:none; background:none; + + 1 + 100 @@ -1438,12 +1349,12 @@ background:none; 5 - 70 + 2 - + 40 @@ -1453,6 +1364,9 @@ background:none; background:none; + + 1 + 100 @@ -1460,12 +1374,12 @@ background:none; 5 - 70 + 10 - + 40 @@ -1482,42 +1396,58 @@ background:none; 5 - 70 + 10 - + + + + 35 + 0 + + + + + 30 + 16777215 + + - background:none; + color:#ccc; +background:none; - + frames - - - background:none; + + + + 35 + 0 + - - + + + 30 + 16777215 + - - - - - background:none; + color:#ccc; +background:none; - + frames - - + + 0 @@ -1535,99 +1465,90 @@ background:none; background:none; - Invert + pow - - - - - - Qt::Vertical - - - - - - + - 25 + 0 0 - 150 + 30 16777215 - - Qt::RightToLeft - color:#ccc; background:none; - X + Min. - + - 25 + 0 0 - 150 + 30 16777215 - - Qt::RightToLeft - color:#ccc; background:none; - Y + Max. - + - 25 + 0 0 - 150 + 30 16777215 - - Qt::RightToLeft - color:#ccc; background:none; - Z + Curve + + + + + + Qt::Vertical + + + + + @@ -1681,158 +1602,219 @@ background:none; - - + + - 45 - 15 + 25 + 0 - - 100 - - - 10 + + + 150 + 16777215 + - - 70 + + Qt::RightToLeft - - Qt::Horizontal + + color:#ccc; +background:none; - - QSlider::NoTicks + + X - - + + - 45 - 15 + 25 + 0 - - 100 - - - 10 + + + 150 + 16777215 + - - 70 + + Qt::RightToLeft - - Qt::Horizontal + + color:#ccc; +background:none; - - QSlider::NoTicks + + Y - - + + - 45 - 15 + 25 + 0 - - 100 - - - 10 + + + 150 + 16777215 + - - 70 + + Qt::RightToLeft - - Qt::Horizontal + + color:#ccc; +background:none; - - QSlider::NoTicks + + Z - - + + - 40 - 22 + 25 + 0 - - background:none; + + + 150 + 16777215 + - - 100 + + Qt::RightToLeft - - 5 + + color:#ccc; +background:none; - - 70 + + Yaw - - + + - 40 - 22 + 25 + 0 - - background:none; + + + 150 + 16777215 + - - 100 + + Qt::RightToLeft - - 5 + + color:#ccc; +background:none; - - 70 + + Pitch - - + + - 40 - 22 + 25 + 0 + + + + + 150 + 16777215 + + + + Qt::RightToLeft + + + color:#ccc; +background:none; + + + Roll + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 20 + 20 + + + + background:none; - - 100 + + - - 5 + + + + + + background:none; - - 70 + + + + + + + + + background:none; + + + - + - 110 + 0 0 - 150 + 30 16777215 @@ -1841,42 +1823,12 @@ background:none; background:none; - Red.factor (100 = 1) - - - - - - - Qt::RightToLeft - - - color:#ccc; -background:none; - - - EWMA + Invert - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 20 - 20 - - - - @@ -2244,12 +2196,12 @@ background:none; setValue(int) - 776 - 180 + 442 + 347 - 832 - 182 + 494 + 349 @@ -2260,204 +2212,108 @@ background:none; setValue(int) - 832 - 182 - - - 776 - 180 - - - - - redYaw - valueChanged(int) - spinRedYaw - setValue(int) - - - 492 - 431 - - - 543 - 432 - - - - - spinRedYaw - valueChanged(int) - redYaw - setValue(int) - - - 532 - 433 - - - 481 - 433 - - - - - redPitch - valueChanged(int) - spinRedPitch - setValue(int) - - - 486 - 462 - - - 540 - 469 - - - - - spinRedPitch - valueChanged(int) - redPitch - setValue(int) - - - 533 - 458 - - - 501 - 460 - - - - - redRoll - valueChanged(int) - spinRedRoll - setValue(int) - - - 498 - 487 - - - 542 - 492 - - - - - spinRedRoll - valueChanged(int) - redRoll - setValue(int) - - - 537 - 495 + 494 + 349 - 504 - 490 + 442 + 347 - redX + minSmooth valueChanged(int) - spinRedX + spinMinSmooth setValue(int) - 803 - 432 + 648 + 293 - 847 - 439 + 696 + 295 - spinRedX + spinMinSmooth valueChanged(int) - redX + minSmooth setValue(int) - 844 - 429 + 696 + 295 - 800 - 428 + 648 + 293 - redY + maxSmooth valueChanged(int) - spinRedY + spinMaxSmooth setValue(int) - 785 - 461 + 648 + 320 - 851 - 465 + 696 + 322 - spinRedY + spinMaxSmooth valueChanged(int) - redY + maxSmooth setValue(int) - 845 - 463 + 696 + 322 - 792 - 464 + 648 + 320 - redZ + powCurve valueChanged(int) - spinRedZ + spinPowCurve setValue(int) - 794 - 483 + 648 + 347 - 845 - 486 + 696 + 349 - spinRedZ + spinPowCurve valueChanged(int) - redZ + powCurve setValue(int) - 843 - 499 + 696 + 349 - 805 - 493 + 648 + 347 diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index ab2f3b86..c054873d 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -53,7 +53,7 @@ // Definitions for testing purposes // #define USE_HEADPOSE_CALLBACK -#define USE_DEBUG_CLIENT +//#define USE_DEBUG_CLIENT using namespace sm::faceapi; using namespace sm::faceapi::qt; @@ -80,6 +80,10 @@ TShortKey Tracker::CenterKey; // ShortKey to Center headposition TShortKey Tracker::StartStopKey; // ShortKey to Start/stop tracking TShortKey Tracker::InhibitKey; // ShortKey to inhibit axis while tracking +ITrackerPtr Tracker::pTracker; // Pointer to Tracker instance (in DLL) +IFilterPtr Tracker::pFilter; // Pointer to Filter instance (in DLL) + + /** constructor **/ Tracker::Tracker( int clientID, int facetrackerID ) { importGetTracker getIT; @@ -552,7 +556,6 @@ void Tracker::run() { if (Tracker::do_tracking && Tracker::confid) { // Pitch - current_camera_position = new_camera_position; // Remember the latest position target_camera_position.x = X.headPos - X.offset_headPos - X.initial_headPos; target_camera_position.y = Y.headPos - Y.offset_headPos - Y.initial_headPos; target_camera_position.z = Z.headPos - Z.offset_headPos - Z.initial_headPos; @@ -607,11 +610,11 @@ void Tracker::run() { // All Protocol server(s) if (server_Game) { server_Game->setVirtRotX ( new_camera_position.pitch ); // degrees - //server_Game->setVirtRotY ( new_camera_position.yaw ); - //server_Game->setVirtRotZ ( new_camera_position.roll ); - //server_Game->setVirtPosX ( new_camera_position.x ); // centimeters - //server_Game->setVirtPosY ( new_camera_position.y ); - //server_Game->setVirtPosZ ( new_camera_position.z ); + server_Game->setVirtRotY ( new_camera_position.yaw ); + server_Game->setVirtRotZ ( new_camera_position.roll ); + server_Game->setVirtPosX ( new_camera_position.x ); // centimeters + server_Game->setVirtPosY ( new_camera_position.y ); + server_Game->setVirtPosZ ( new_camera_position.z ); } # ifdef USE_DEBUG_CLIENT @@ -805,6 +808,36 @@ void Tracker::addRaw2List ( QList *rawList, float maxIndex, float raw ) { rawList->prepend ( raw ); } +// +// Set the filter-value from the GUI. +// +void Tracker::setMinSmooth ( int x ) { + if (Tracker::pFilter) { + Tracker::pFilter->setParameterValue(0, x); + qDebug() << "Tracker::setMinSmooth Min Smooting frames set to: " << x; + } +} + +// +// Set the filter-value from the GUI. +// +void Tracker::setMaxSmooth ( int x ) { + if (Tracker::pFilter) { + Tracker::pFilter->setParameterValue(1, x); + qDebug() << "Tracker::setMaxSmooth Max Smooting frames set to: " << x; + } +} + +// +// Set the filter-value from the GUI. +// +void Tracker::setPowCurve( int x ) { + if (Tracker::pFilter) { + Tracker::pFilter->setParameterValue(2, x); + qDebug() << "Tracker::setPowCurve Pow Curve set to: " << x; + } +} + // // Get the Smoothed value from the QList. // diff --git a/FaceTrackNoIR/tracker.h b/FaceTrackNoIR/tracker.h index 49310a23..73d4161e 100644 --- a/FaceTrackNoIR/tracker.h +++ b/FaceTrackNoIR/tracker.h @@ -141,8 +141,8 @@ private: APIScope *faceapi_scope; QSharedPointer _engine; smEngineHandle _engine_handle; - ITrackerPtr pTracker; // Pointer to Tracker instance (in DLL) - IFilterPtr pFilter; // Pointer to Filter instance (in DLL) + static ITrackerPtr pTracker; // Pointer to Tracker instance (in DLL) + static IFilterPtr pFilter; // Pointer to Filter instance (in DLL) /** static callback method for the head pose tracking **/ static void STDCALL receiveHeadPose(void *,smEngineHeadPoseData head_pose, smCameraVideoFrame video_frame); @@ -222,13 +222,9 @@ public: static void setInvertZ(bool invert) { Z.invert = invert?-1.0f:+1.0f; } static void setUseFilter(bool set) { useFilter = set; } - - static void setRedYaw(int x) { Yaw.red = x/100.0f; } - static void setRedPitch(int x) { Pitch.red = x/100.0f; } - static void setRedRoll(int x) { Roll.red = x/100.0f; } - static void setRedX(int x) { X.red = x/100.0f; } - static void setRedY(int x) { Y.red = x/100.0f; } - static void setRedZ(int x) { Z.red = x/100.0f; } + static void setMinSmooth(int x); + static void setMaxSmooth(int x); + static void setPowCurve(int x); static float getSmoothFromList ( QList *rawList ); static float getDegreesFromRads ( float rads ) { return (rads * 57.295781f); } -- cgit v1.2.3