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 --- FaceTrackNoIR/FaceTrackNoIR.cpp | 14 ++-- FaceTrackNoIR/FaceTrackNoIR.vcproj | 28 +++---- FaceTrackNoIR/tracker.cpp | 145 ++----------------------------------- FaceTrackNoIR/tracker.h | 15 +--- 4 files changed, 31 insertions(+), 171 deletions(-) (limited to 'FaceTrackNoIR') 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; } -- cgit v1.2.3