From 09b4c95b8036b9466ca89acbe0b1f3d810499863 Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Thu, 10 Mar 2011 20:40:13 +0000 Subject: faceAPI inside DLL works; no video-display yet... git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@53 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FTNoIR_Tracker_Base/ftnoir_tracker_base.h | 3 +- FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.h | 9 +- FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.vcproj | 2 +- FTNoIR_Tracker_SM/ftnoir_tracker_faceapi.cpp | 52 ++++++---- FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.h | 3 +- FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp | 12 ++- FaceTrackNoIR.suo | Bin 343552 -> 343552 bytes FaceTrackNoIR/FaceTrackNoIR.cpp | 14 +-- FaceTrackNoIR/FaceTrackNoIR.vcproj | 28 +++--- FaceTrackNoIR/tracker.cpp | 145 ++------------------------- FaceTrackNoIR/tracker.h | 15 +-- bin/FaceTrackNoIR.exe | Bin 761856 -> 626688 bytes 12 files changed, 86 insertions(+), 197 deletions(-) diff --git a/FTNoIR_Tracker_Base/ftnoir_tracker_base.h b/FTNoIR_Tracker_Base/ftnoir_tracker_base.h index f39a8b4d..49a79b97 100644 --- a/FTNoIR_Tracker_Base/ftnoir_tracker_base.h +++ b/FTNoIR_Tracker_Base/ftnoir_tracker_base.h @@ -23,7 +23,8 @@ struct ITracker virtual void Release() = 0; // Member required to enable Auto-remove virtual void Initialize() = 0; virtual void StartTracker() = 0; - virtual void GiveHeadPoseData(THeadPoseData *data) = 0; + virtual void StopTracker() = 0; + virtual bool GiveHeadPoseData(THeadPoseData *data) = 0; }; // Handle type. In C++ language the iterface type is used. diff --git a/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.h b/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.h index 0687730a..12bfbe80 100644 --- a/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.h +++ b/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.h @@ -1,12 +1,14 @@ #include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" #include "ui_FTNoIR_SMClientcontrols.h" -#include +#include "sm_api_qt.h" #include #include #include "Windows.h" #include "math.h" +using namespace std; +//using namespace sm::faceapi::samplecode; using namespace sm::faceapi; using namespace sm::faceapi::qt; @@ -19,7 +21,8 @@ public: void Release(); void Initialize(); void StartTracker(); - void GiveHeadPoseData(THeadPoseData *data); + void StopTracker(); + bool GiveHeadPoseData(THeadPoseData *data); // Returns true if confidence is good void loadSettings(); bool setParameterValue(const int index, const float newvalue); @@ -30,8 +33,6 @@ private: QSharedPointer _engine; smEngineHandle _engine_handle; - THeadPoseData newHeadPose; // Structure with new headpose - //parameter list for the filter-function(s) enum { diff --git a/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.vcproj b/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.vcproj index 243e919b..cf0cd64f 100644 --- a/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.vcproj +++ b/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.vcproj @@ -38,7 +38,7 @@ /> (1000.0f,9999.0f)); parameterValueAsFloat.append(0.0f); setParameterValue(kPortAddress,5551.0f); - - newHeadPose.x = 0.0f; - newHeadPose.y = 0.0f; - newHeadPose.z = 0.0f; - newHeadPose.yaw = 0.0f; - newHeadPose.pitch = 0.0f; - newHeadPose.roll = 0.0f; } FTNoIR_Tracker_SM::~FTNoIR_Tracker_SM() { + _engine->stop(); + smAPIQuit(); } void FTNoIR_Tracker_SM::Release() @@ -52,8 +47,6 @@ void FTNoIR_Tracker_SM::Initialize() CameraInfo::registerType(SM_API_CAMERA_TYPE_WDM); _engine = QSharedPointer(new HeadTrackerV2()); - // starts the faceapi engine - _engine->start(); } catch (sm::faceapi::Error &e) { @@ -66,20 +59,45 @@ void FTNoIR_Tracker_SM::Initialize() void FTNoIR_Tracker_SM::StartTracker() { + + // starts the faceapi engine + if (_engine->state() != SM_API_ENGINE_STATE_HT_TRACKING) { + _engine->start(); + } + + // some parameteres [optional] + smHTSetHeadPosePredictionEnabled( _engine->handle(), false); + smHTSetLipTrackingEnabled( _engine->handle(), false); + smLoggingSetFileOutputEnable( false ); return; } -void FTNoIR_Tracker_SM::GiveHeadPoseData(THeadPoseData *data) +void FTNoIR_Tracker_SM::StopTracker() { - data->x = newHeadPose.x; - data->y = newHeadPose.y; - data->z = newHeadPose.z; - data->yaw = newHeadPose.yaw; - data->pitch = newHeadPose.pitch; - data->roll = newHeadPose.roll; + + // stops the faceapi engine + _engine->stop(); return; } +bool FTNoIR_Tracker_SM::GiveHeadPoseData(THeadPoseData *data) +{ + smEngineHeadPoseData head_pose; // headpose from faceAPI + smEngineHeadPoseData temp_head_pose; // headpose from faceAPI + + smReturnCode smret = smHTCurrentHeadPose(_engine->handle(), &temp_head_pose); + memcpy(&head_pose, &temp_head_pose, sizeof(smEngineHeadPoseData)); + + data->x = head_pose.head_pos.x * 100.0f; // From meters to centimeters + data->y = head_pose.head_pos.y * 100.0f; + data->z = head_pose.head_pos.z * 100.0f; + data->yaw = head_pose.head_rot.y_rads * 57.295781f; // From rads to degrees + data->pitch = head_pose.head_rot.x_rads * 57.295781f; + data->roll = head_pose.head_rot.z_rads * 57.295781f; + + return ( head_pose.confidence > 0 ); +} + bool FTNoIR_Tracker_SM::setParameterValue(const int index, const float newvalue) { if ((index >= 0) && (index < parameterValueAsFloat.size())) diff --git a/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.h b/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.h index 9a0cad1f..ab9c0ed5 100644 --- a/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.h +++ b/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.h @@ -16,7 +16,8 @@ public: void Release(); void Initialize(); void StartTracker(); - void GiveHeadPoseData(THeadPoseData *data); + void StopTracker(); + bool GiveHeadPoseData(THeadPoseData *data); void loadSettings(); bool setParameterValue(const int index, const float newvalue); diff --git a/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp b/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp index 1a64261e..afeae10d 100644 --- a/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp +++ b/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp @@ -127,7 +127,15 @@ void FTNoIR_Tracker_UDP::StartTracker() return; } -void FTNoIR_Tracker_UDP::GiveHeadPoseData(THeadPoseData *data) +void FTNoIR_Tracker_UDP::StopTracker() +{ + // + // OK, the thread is not stopped, doing this. That might be dangerous anyway... + // + return; +} + +bool FTNoIR_Tracker_UDP::GiveHeadPoseData(THeadPoseData *data) { data->x = newHeadPose.x; data->y = newHeadPose.y; @@ -135,7 +143,7 @@ void FTNoIR_Tracker_UDP::GiveHeadPoseData(THeadPoseData *data) data->yaw = newHeadPose.yaw; data->pitch = newHeadPose.pitch; data->roll = newHeadPose.roll; - return; + return true; } bool FTNoIR_Tracker_UDP::setParameterValue(const int index, const float newvalue) diff --git a/FaceTrackNoIR.suo b/FaceTrackNoIR.suo index f545da19..d41bcf62 100644 Binary files a/FaceTrackNoIR.suo and b/FaceTrackNoIR.suo differ diff --git a/FaceTrackNoIR/FaceTrackNoIR.cpp b/FaceTrackNoIR/FaceTrackNoIR.cpp index d8184fff..2acf8ec0 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.cpp +++ b/FaceTrackNoIR/FaceTrackNoIR.cpp @@ -491,12 +491,12 @@ void FaceTrackNoIR::startTracker( ) { tracker = new Tracker ( ui.iconcomboBox->currentIndex(), ui.iconcomboTrackerSource->currentIndex() ); // Show the video widget - ui.video_frame->show(); - _display = new VideoDisplayWidget( tracker->getEngine(), ui.video_frame, 0 ); - l = new QVBoxLayout(ui.video_frame); - l->setMargin(0); - l->setSpacing(0); - l->addWidget(_display); + //ui.video_frame->show(); + //_display = new VideoDisplayWidget( tracker->getEngine(), ui.video_frame, 0 ); + //l = new QVBoxLayout(ui.video_frame); + //l->setMargin(0); + //l->setSpacing(0); + //l->addWidget(_display); // // Setup the Tracker and send the settings. @@ -743,7 +743,7 @@ QLibrary *trackerLib; { switch (ui.iconcomboTrackerSource->currentIndex()) { case FT_SM_FACEAPI: // Face API - _engine_controls = new EngineControls( tracker->getEngine(), true, false, this, Qt::Dialog ); +// _engine_controls = new EngineControls( tracker->getEngine(), true, false, this, Qt::Dialog ); break; case FT_FTNOIR: // FTNoir server qDebug() << "FaceTrackNoIR::showEngineControls case FT_FTNOIR."; diff --git a/FaceTrackNoIR/FaceTrackNoIR.vcproj b/FaceTrackNoIR/FaceTrackNoIR.vcproj index 08ab6ddd..16a3d715 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.vcproj +++ b/FaceTrackNoIR/FaceTrackNoIR.vcproj @@ -47,7 +47,7 @@ OmitFramePointers="false" EnableFiberSafeOptimizations="false" WholeProgramOptimization="false" - AdditionalIncludeDirectories=".\GeneratedFiles;"$(QTDIR)\include";".\GeneratedFiles\$(ConfigurationName)";"$(QTDIR)\include\QtCore";"$(QTDIR)\include\QtNetwork";"$(QTDIR)\include\QtGui";"$(QTDIR)\include\QtOpenGL";"$(QTDIR)\include\QtWebKit";"$(QTDIR)\include\QtTest";"$(SM_API_PATH)\include";"$(SM_API_CPP_WRAPPERS)\include";"$(SM_API_QTDIR)\include";"$(SM_API_WIDGETS)\include";"$(SolutionDir)\FTNoIR_Tracker_UDP";"$(SolutionDir)\FTNoIR_Tracker_UDP\GeneratedFiles";"$(SolutionDir)\FTNoIR_Filter_EWMA2"" + AdditionalIncludeDirectories=".\GeneratedFiles;"$(QTDIR)\include";".\GeneratedFiles\$(ConfigurationName)";"$(QTDIR)\include\QtCore";"$(QTDIR)\include\QtNetwork";"$(QTDIR)\include\QtGui";"$(QTDIR)\include\QtOpenGL";"$(QTDIR)\include\QtWebKit";"$(QTDIR)\include\QtTest";"$(SolutionDir)\FTNoIR_Tracker_UDP";"$(SolutionDir)\FTNoIR_Tracker_UDP\GeneratedFiles";"$(SolutionDir)\FTNoIR_Filter_EWMA2"" PreprocessorDefinitions="UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_THREAD_SUPPORT;QT_NO_DEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_OPENGL_LIB;QT_NETWORK_LIB;QT_DLL" RuntimeLibrary="2" FloatingPointModel="2" @@ -151,7 +151,7 @@ /> @@ -288,7 +288,7 @@ @@ -314,7 +314,7 @@ @@ -340,7 +340,7 @@ @@ -370,7 +370,7 @@ @@ -396,7 +396,7 @@ @@ -426,7 +426,7 @@ @@ -452,7 +452,7 @@ @@ -478,7 +478,7 @@ @@ -512,7 +512,7 @@ @@ -542,7 +542,7 @@ @@ -568,7 +568,7 @@ diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index 2571be40..18b9c0b8 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -52,12 +52,9 @@ // // Definitions for testing purposes // -#define USE_HEADPOSE_CALLBACK +//#define USE_HEADPOSE_CALLBACK //#define USE_DEBUG_CLIENT -//using namespace sm::faceapi; -//using namespace sm::faceapi::qt; - // Flags bool Tracker::confid = false; bool Tracker::set_initial = false; @@ -119,30 +116,6 @@ QLibrary *filterLib; // switch (selectedTracker) { case FT_SM_FACEAPI: - //try { - // // Initialize the faceAPI Qt library - // sm::faceapi::qt::initialize(); - // smLoggingSetFileOutputEnable( false ); - - // // Initialize the API - // faceapi_scope = new APIScope(); - - // //if (APIScope::internalQtGuiIsDisabled()){ - // // QMessageBox::warning(0,"faceAPI Error","Something Bad",QMessageBox::Ok,QMessageBox::NoButton); - // //} - - // // Create head-tracking engine v2 using first detected webcam - // CameraInfo::registerType(SM_API_CAMERA_TYPE_WDM); - // _engine = QSharedPointer(new HeadTrackerV2()); - - // // starts the faceapi engine - // _engine->start(); - //} - //catch (sm::faceapi::Error &e) - //{ - // /* ERROR with camera */ - // QMessageBox::warning(0,"faceAPI Error",e.what(),QMessageBox::Ok,QMessageBox::NoButton); - //} trackerLib = new QLibrary("FTNoIR_Tracker_SM.dll"); getIT = (importGetTracker) trackerLib->resolve("GetTracker"); @@ -268,11 +241,6 @@ Tracker::~Tracker() { ::CloseHandle( Tracker::hTrackMutex ); } - if (selectedTracker == FT_SM_FACEAPI) { - _engine->stop(); - smAPIQuit(); - } - // Stop the started server(s) if (server_Game) { server_Game->deleteLater(); @@ -291,24 +259,8 @@ void Tracker::setup(QWidget *head, FaceTrackNoIR *parent) { bool DLL_Ok; // retrieve pointers to the User Interface and the main Application -// headPoseWidget = head; mainApp = parent; - - if (selectedTracker == FT_SM_FACEAPI) { - //registers the faceapi callback for receiving headpose data **/ -# ifdef USE_HEADPOSE_CALLBACK - registerHeadPoseCallback(); -# endif - - // some parameteres [optional] - smHTSetHeadPosePredictionEnabled( _engine->handle(), false); - smHTSetLipTrackingEnabled( _engine->handle(), false); - smLoggingSetFileOutputEnable( false ); - } - - if (selectedTracker == FT_FTNOIR) { - pTracker->StartTracker(); - } + pTracker->StartTracker(); // // Check if the Protocol-server files were installed OK. @@ -352,11 +304,6 @@ void Tracker::run() { THeadPoseData target_camera_position; THeadPoseData new_camera_position; -# ifndef USE_HEADPOSE_CALLBACK - smEngineHeadPoseData head_pose; // headpose from faceAPI - smEngineHeadPoseData temp_head_pose; // headpose from faceAPI -# endif - current_camera_position.x = 0.0f; current_camera_position.y = 0.0f; current_camera_position.z = 0.0f; @@ -482,13 +429,11 @@ void Tracker::run() { current_camera_position.pitch = 0.0f; current_camera_position.roll = 0.0f; - if (_engine->state() != SM_API_ENGINE_STATE_HT_TRACKING) { - _engine->start(); - } + pTracker->StartTracker(); } else { if (setEngineStop) { // Only stop engine when option is checked - _engine->stop(); + pTracker->StopTracker(); } } qDebug() << "Tracker::run() says StartStop pressed, do_tracking =" << Tracker::do_tracking; @@ -524,27 +469,9 @@ void Tracker::run() { if (WaitForSingleObject(Tracker::hTrackMutex, 100) == WAIT_OBJECT_0) { -# ifndef USE_HEADPOSE_CALLBACK - smReturnCode smret = smHTCurrentHeadPose(_engine->handle(), &temp_head_pose); - memcpy(&head_pose, &temp_head_pose, sizeof(smEngineHeadPoseData)); - - if ( head_pose.confidence > 0 ) { - - Tracker::confid = true; - - // Write the Raw headpose-data and add it to the RawList, for processing... - addHeadPose( head_pose ); - } else { - Tracker::confid = false; - } -# endif - - if (selectedTracker == FT_FTNOIR) { - THeadPoseData newpose; - pTracker->GiveHeadPoseData(&newpose); - addHeadPose(newpose); - Tracker::confid = true; - } + THeadPoseData newpose; + Tracker::confid = pTracker->GiveHeadPoseData(&newpose); + addHeadPose(newpose); // // Get the System-time and substract the time from the previous call. @@ -714,64 +641,8 @@ void Tracker::run() { //for lower cpu load usleep(10000); -// yieldCurrentThread(); - } -} - -/** registers the faceapi headpose callback function **/ -void Tracker::registerHeadPoseCallback() { - Q_ASSERT(_engine_handle); - smReturnCode error = smHTRegisterHeadPoseCallback( _engine->handle(), 0, receiveHeadPose); - //showErrorBox(0, "Register HeadPose Callback", error); -} - -/** Callback function for head-pose - only static methods could be called **/ -void Tracker::receiveHeadPose(void *,smEngineHeadPoseData head_pose, smCameraVideoFrame video_frame) -{ - // - // Perform actions, when valid data is received from faceAPI. - // - if (( head_pose.confidence > 0 ) && (WaitForSingleObject(Tracker::hTrackMutex, 100) == WAIT_OBJECT_0) ) { - - Tracker::confid = true; - - // Write the Raw headpose-data and add it to the RawList, for processing... - addHeadPose( head_pose ); - } else { - Tracker::confid = false; + yieldCurrentThread(); } - - ReleaseMutex(Tracker::hTrackMutex); -} - -/** Add the headpose-data to the Lists **/ -void Tracker::addHeadPose( smEngineHeadPoseData head_pose ) -{ - // Pitch - Tracker::Pitch.headPos = head_pose.head_rot.x_rads * 57.295781f; // degrees - addRaw2List ( &Pitch.rawList, Pitch.maxItems, Tracker::Pitch.headPos ); - Tracker::Pitch.confidence = head_pose.confidence; // Just this one ... - Tracker::Pitch.newSample = true; - - // Yaw - Tracker::Yaw.headPos = head_pose.head_rot.y_rads * 57.295781f; // degrees - addRaw2List ( &Yaw.rawList, Yaw.maxItems, Tracker::Yaw.headPos ); - - // Roll - Tracker::Roll.headPos = head_pose.head_rot.z_rads * 57.295781f; // degrees - addRaw2List ( &Roll.rawList, Roll.maxItems, Tracker::Roll.headPos ); - - // X-position - Tracker::X.headPos = head_pose.head_pos.x * 100.0f; // centimeters - addRaw2List ( &X.rawList, X.maxItems, Tracker::X.headPos ); - - // Y-position - Tracker::Y.headPos = head_pose.head_pos.y * 100.0f; // centimeters - addRaw2List ( &Y.rawList, Y.maxItems, Tracker::Y.headPos ); - - // Z-position (distance to camera, absolute!) - Tracker::Z.headPos = head_pose.head_pos.z * 100.0f; // centimeters - addRaw2List ( &Z.rawList, Z.maxItems, Tracker::Z.headPos ); } /** Add the headpose-data to the Lists **/ diff --git a/FaceTrackNoIR/tracker.h b/FaceTrackNoIR/tracker.h index bfed3cd4..2ee26bba 100644 --- a/FaceTrackNoIR/tracker.h +++ b/FaceTrackNoIR/tracker.h @@ -23,7 +23,6 @@ #ifndef __TRACKER_H__ #define __TRACKER_H__ -//#include #include #include #include @@ -62,9 +61,6 @@ typedef IFilter *(WINAPI *importGetFilter)(void); #pragma comment (lib, "dinput8.lib") #pragma comment (lib, "dxguid.lib") -using namespace sm::faceapi; -using namespace sm::faceapi::qt; - enum AngleName { PITCH = 0, YAW = 1, @@ -155,16 +151,9 @@ private: FTNoIR_Client selectedClient; FTNoIR_Face_Tracker selectedTracker; - ///** face api variables **/ -// APIScope *faceapi_scope; - // QSharedPointer _engine; - //smEngineHandle _engine_handle; 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); - static void addHeadPose( smEngineHeadPoseData head_pose ); static void addHeadPose( THeadPoseData head_pose ); static void addRaw2List ( QList *rawList, float maxIndex, float raw ); static float lowPassFilter ( float newvalue, float *oldvalue, float dt, float coeff); @@ -213,13 +202,13 @@ public: void setup(QWidget *head, FaceTrackNoIR *parent); - void registerHeadPoseCallback(); +// void registerHeadPoseCallback(); bool handleGameCommand ( int command ); QString getGameProgramName(); // Get the ProgramName from the game and display it. void loadSettings(); // Load settings from the INI-file bool isShortKeyPressed( TShortKey *key, BYTE *keystate ); - QSharedPointer getEngine() { return _engine; }; +// QSharedPointer getEngine() { return _engine; }; static bool getConfid() { return confid; } diff --git a/bin/FaceTrackNoIR.exe b/bin/FaceTrackNoIR.exe index 0a93dfc9..092b7d83 100644 Binary files a/bin/FaceTrackNoIR.exe and b/bin/FaceTrackNoIR.exe differ -- cgit v1.2.3