From 277cc7603eb6b4d9fed6a0a2de245e4cdde6ee8b Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Tue, 22 Mar 2011 21:34:47 +0000 Subject: Successfully use console app for faceAPI 3.2.6. combined with tracker class in DLL. Even managed to get the video-widget connected to the main-window... git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@56 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FTNoIR_Tracker_Base/ftnoir_tracker_base.h | 2 +- FTNoIR_Tracker_Base/ftnoir_tracker_sm_types.h | 5 + FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.h | 2 +- FTNoIR_Tracker_SM/ftnoir_tracker_faceapi.cpp | 88 +++------ FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.h | 2 +- FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp | 3 +- FaceTrackNoIR.suo | Bin 353280 -> 354816 bytes FaceTrackNoIR/UIElements/aboutFaceTrackNoIR.png | Bin 28783 -> 28821 bytes FaceTrackNoIR/tracker.cpp | 7 +- bin/FaceTrackNoIR.exe | Bin 626688 -> 626688 bytes bin/cleye.config | 4 + bin/smft32.dll | Bin 10809344 -> 10940416 bytes faceAPI/FaceAPI2FSX.vcproj | 233 ++++++++++++++++++++++++ faceAPI/main.cpp | 95 +++++++--- faceAPI/utils.h | 26 +-- 15 files changed, 363 insertions(+), 104 deletions(-) create mode 100644 bin/cleye.config create mode 100644 faceAPI/FaceAPI2FSX.vcproj diff --git a/FTNoIR_Tracker_Base/ftnoir_tracker_base.h b/FTNoIR_Tracker_Base/ftnoir_tracker_base.h index 1965d3d2..93fd5140 100644 --- a/FTNoIR_Tracker_Base/ftnoir_tracker_base.h +++ b/FTNoIR_Tracker_Base/ftnoir_tracker_base.h @@ -24,7 +24,7 @@ struct ITracker virtual void Release() = 0; // Member required to enable Auto-remove virtual void Initialize( QFrame *videoframe ) = 0; virtual void StartTracker( HWND parent_window ) = 0; - virtual void StopTracker() = 0; + virtual void StopTracker(bool exit) = 0; virtual bool GiveHeadPoseData(THeadPoseData *data) = 0; }; diff --git a/FTNoIR_Tracker_Base/ftnoir_tracker_sm_types.h b/FTNoIR_Tracker_Base/ftnoir_tracker_sm_types.h index 9ebfd173..abc4a473 100644 --- a/FTNoIR_Tracker_Base/ftnoir_tracker_sm_types.h +++ b/FTNoIR_Tracker_Base/ftnoir_tracker_sm_types.h @@ -21,3 +21,8 @@ struct SMMemMap { }; typedef SMMemMap * PSMMemMap; +enum FTNoIR_Tracker_Command { + FT_SM_START = 10, + FT_SM_STOP = 20, + FT_SM_EXIT = 100 +}; diff --git a/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.h b/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.h index 5bed0a16..1edc612f 100644 --- a/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.h +++ b/FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.h @@ -19,7 +19,7 @@ public: void Release(); void Initialize( QFrame *videoframe ); void StartTracker( HWND parent_window ); - void StopTracker(); + void StopTracker( bool exit ); bool GiveHeadPoseData(THeadPoseData *data); // Returns true if confidence is good void loadSettings(); bool SMCreateMapping(); diff --git a/FTNoIR_Tracker_SM/ftnoir_tracker_faceapi.cpp b/FTNoIR_Tracker_SM/ftnoir_tracker_faceapi.cpp index a7f0668e..358ad962 100644 --- a/FTNoIR_Tracker_SM/ftnoir_tracker_faceapi.cpp +++ b/FTNoIR_Tracker_SM/ftnoir_tracker_faceapi.cpp @@ -18,22 +18,22 @@ FTNoIR_Tracker_SM::~FTNoIR_Tracker_SM() qDebug() << "stopTracker says: terminating"; if ( pMemData != NULL ) { - pMemData->command = 100; // Issue 'stop' command UnmapViewOfFile ( pMemData ); } CloseHandle( hSMMutex ); CloseHandle( hSMMemMap ); hSMMemMap = 0; - - //_engine->stop(); - //smAPIQuit(); } void FTNoIR_Tracker_SM::Release() { qDebug() << "FTNoIR_Tracker_SM::Release says: Starting "; - delete this; + + if ( pMemData != NULL ) { + pMemData->command = FT_SM_EXIT; // Issue 'exit' command + } + delete this; } void FTNoIR_Tracker_SM::Initialize( QFrame *videoframe ) @@ -48,91 +48,57 @@ void FTNoIR_Tracker_SM::Initialize( QFrame *videoframe ) QMessageBox::warning(0,"FaceTrackNoIR Error","Memory mapping not created!",QMessageBox::Ok,QMessageBox::NoButton); } + if ( pMemData != NULL ) { + pMemData->command = 0; // Reset any and all commands + pMemData->handle = videoframe->winId(); // Handle of Videoframe widget + } + // // Start FTNoIR_FaceAPI_EXE.exe. The exe contains all faceAPI-stuff and is non-Qt... // - QString program = "FTNoIR_FaceAPI_EXE.exe"; - faceAPI = new QProcess(0); - faceAPI->start(program); - - ////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()); - - ////} - ////catch (sm::faceapi::Error &e) - ////{ - //// /* ERROR with camera */ - //// QMessageBox::warning(0,"faceAPI Error",e.what(),QMessageBox::Ok,QMessageBox::NoButton); - ////} - - + QString program = "FTNoIR_FaceAPI_EXE.exe"; + faceAPI = new QProcess(0); + faceAPI->start(program); // Show the video widget qDebug() << "FTNoIR_Tracker_SM::Initialize says: videoframe = " << videoframe; - //// QMainWindow derived class. See mainwindow.h - // QSharedPointer camera; - // main_window = new MainWindow(camera,_engine,0); - // main_window->show(); - - //videoframe->show(); - //_display = new VideoDisplayWidget( _engine, videoframe, 0 ); - //l = new QVBoxLayout(videoframe); - //l->setMargin(0); - //l->setSpacing(0); - //l->addWidget(_display); - + videoframe->show(); return; } void FTNoIR_Tracker_SM::StartTracker( HWND parent_window ) { - - //// 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 ); + if ( pMemData != NULL ) { + pMemData->command = FT_SM_START; // Start command + } return; } -void FTNoIR_Tracker_SM::StopTracker() +void FTNoIR_Tracker_SM::StopTracker( bool exit ) { qDebug() << "FTNoIR_Tracker_SM::StopTracker says: Starting "; // stops the faceapi engine -//// _engine->stop(); + if ( pMemData != NULL ) { +// if (exit == true) { + pMemData->command = (exit) ? FT_SM_EXIT : FT_SM_STOP; // Issue 'stop' command + //} + //else { + // pMemData->command = FT_SM_STOP; // Issue 'stop' command + //} + } return; } bool FTNoIR_Tracker_SM::GiveHeadPoseData(THeadPoseData *data) { - - qDebug() << "FTNoIR_Tracker_SM::GiveHeadPoseData says: Starting "; - // // Check if the pointer is OK and wait for the Mutex. // if ( (pMemData != NULL) && (WaitForSingleObject(hSMMutex, 100) == WAIT_OBJECT_0) ) { - qDebug() << "FTNoIR_Tracker_SM::GiveHeadPoseData says: Retrieving data."; +// qDebug() << "FTNoIR_Tracker_SM::GiveHeadPoseData says: Retrieving data."; // // Copy the measurements to FaceTrackNoIR. diff --git a/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.h b/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.h index 506eb157..b5d644fd 100644 --- a/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.h +++ b/FTNoIR_Tracker_UDP/FTNoIR_Tracker_UDP.h @@ -16,7 +16,7 @@ public: void Release(); void Initialize( QFrame *videoframe ); void StartTracker( HWND parent_window ); - void StopTracker(); + void StopTracker( bool exit ); bool GiveHeadPoseData(THeadPoseData *data); void loadSettings(); diff --git a/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp b/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp index 1905a3bd..ba140cbb 100644 --- a/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp +++ b/FTNoIR_Tracker_UDP/ftnoir_tracker_udp.cpp @@ -127,11 +127,12 @@ void FTNoIR_Tracker_UDP::StartTracker( HWND parent_window ) return; } -void FTNoIR_Tracker_UDP::StopTracker() +void FTNoIR_Tracker_UDP::StopTracker( bool exit ) { // // OK, the thread is not stopped, doing this. That might be dangerous anyway... // + if (exit || !exit) return; return; } diff --git a/FaceTrackNoIR.suo b/FaceTrackNoIR.suo index 8240a44c..15da2e44 100644 Binary files a/FaceTrackNoIR.suo and b/FaceTrackNoIR.suo differ diff --git a/FaceTrackNoIR/UIElements/aboutFaceTrackNoIR.png b/FaceTrackNoIR/UIElements/aboutFaceTrackNoIR.png index 97ff1d1f..a7d80c1b 100644 Binary files a/FaceTrackNoIR/UIElements/aboutFaceTrackNoIR.png and b/FaceTrackNoIR/UIElements/aboutFaceTrackNoIR.png differ diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index 39bc8dce..01739389 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -234,6 +234,11 @@ QFrame *video_frame; /** destructor empty **/ Tracker::~Tracker() { + // Stop the Tracker + if (pTracker) { + pTracker->StopTracker( true ); + } + // Trigger thread to stop ::SetEvent(m_StopThread); @@ -438,7 +443,7 @@ void Tracker::run() { } else { if (setEngineStop) { // Only stop engine when option is checked - pTracker->StopTracker(); + pTracker->StopTracker( false ); } } qDebug() << "Tracker::run() says StartStop pressed, do_tracking =" << Tracker::do_tracking; diff --git a/bin/FaceTrackNoIR.exe b/bin/FaceTrackNoIR.exe index 2830d3be..020047d7 100644 Binary files a/bin/FaceTrackNoIR.exe and b/bin/FaceTrackNoIR.exe differ diff --git a/bin/cleye.config b/bin/cleye.config new file mode 100644 index 00000000..55a478ab --- /dev/null +++ b/bin/cleye.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/bin/smft32.dll b/bin/smft32.dll index 3e410ee4..bf3e0f13 100644 Binary files a/bin/smft32.dll and b/bin/smft32.dll differ diff --git a/faceAPI/FaceAPI2FSX.vcproj b/faceAPI/FaceAPI2FSX.vcproj new file mode 100644 index 00000000..e936c79c --- /dev/null +++ b/faceAPI/FaceAPI2FSX.vcproj @@ -0,0 +1,233 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/faceAPI/main.cpp b/faceAPI/main.cpp index f1c5f768..3b260dca 100644 --- a/faceAPI/main.cpp +++ b/faceAPI/main.cpp @@ -1,9 +1,33 @@ -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// FaceAPI2FSX program implementation -// Merges the old CockpitCamera.cpp and TestAppConsole.cpp into a single file -// -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/******************************************************************************** +* FaceTrackNoIR This program is a private project of the some enthusiastic * +* gamers from Holland, who don't like to pay much for * +* head-tracking. * +* * +* Copyright (C) 2011 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 . * +*********************************************************************************/ +/* + Modifications (last one on top): + 20110322 - WVR: Somehow the video-widget of faceAPI version 3.2.6. does not + work with FaceTrackNoIR (Qt issue?!). To be able to use + release 3.2.6 of faceAPI anyway, this console-app is used. + It exchanges data with FaceTrackNoIR via shared-memory... +*/ //Precompiled header #include "stdafx.h" @@ -184,7 +208,8 @@ smCameraHandle createFirstCamera() // The main function: setup a tracking engine and show a video window, then loop on the keyboard. void run() { - // Capture control-C + char msg[100]; + // Capture control-C // signal(SIGINT, CtrlCHandler); // Make the console window a bit bigger (see utils.h) @@ -295,7 +320,12 @@ void run() // Create and show a video-display window smVideoDisplayHandle video_display_handle = 0; - THROW_ON_ERROR(smVideoDisplayCreate(engine_handle,&video_display_handle,0,TRUE)); + if (pMemData) { + THROW_ON_ERROR(smVideoDisplayCreate(engine_handle,&video_display_handle,(smWindowHandle) pMemData->handle,TRUE)); + } + else { + THROW_ON_ERROR(smVideoDisplayCreate(engine_handle,&video_display_handle,0,TRUE)); + } // Setup the VideoDisplay THROW_ON_ERROR(smVideoDisplaySetFlags(video_display_handle,g_overlay_flags)); @@ -304,9 +334,7 @@ void run() smWindowHandle win_handle = 0; THROW_ON_ERROR(smVideoDisplayGetWindowHandle(video_display_handle,&win_handle)); SetWindowText(win_handle, _T("faceAPI Video-widget")); - - // Start tracking - THROW_ON_ERROR(smEngineStart(engine_handle)); + MoveWindow(win_handle, 0, 0, 250, 150, true); // Loop on the keyboard while (processKeyPress(engine_handle, video_display_handle) && !stopCommand) @@ -335,7 +363,37 @@ void run() // Prevent CPU overload in our simple loop. const int frame_period_ms = 10; Sleep(frame_period_ms); - } + + // + // Process the command sent by FaceTrackNoIR. + // + sprintf_s(msg, "Command: %d\n", pMemData->command); + OutputDebugStringA(msg); + if (pMemData) { + switch (pMemData->command) { + case FT_SM_START: + THROW_ON_ERROR(smEngineStart(engine_handle)); // Start tracking + pMemData->command = 0; // Reset + break; + + case FT_SM_STOP: + THROW_ON_ERROR(smEngineStop(engine_handle)); // Stop tracking + pMemData->command = 0; // Reset + break; + + case FT_SM_EXIT: + THROW_ON_ERROR(smEngineStop(engine_handle)); // Stop tracking + stopCommand = TRUE; + pMemData->command = 0; // Reset + break; + + default: + pMemData->command = 0; // Reset + // should never be reached + break; + } + } + } // While(1) // Destroy engine THROW_ON_ERROR(smEngineDestroy(&engine_handle)); @@ -382,33 +440,20 @@ int _tmain(int /*argc*/, _TCHAR** /*argv*/) // void updateHeadPose(smEngineHeadPoseData* temp_head_pose) { - char msg[100]; - - OutputDebugString(_T("updateHeadPose() says: Starting Function\n")); - // // Check if the pointer is OK and wait for the Mutex. // if ( (pMemData != NULL) && (WaitForSingleObject(hSMMutex, 100) == WAIT_OBJECT_0) ) { - OutputDebugString(_T("updateHeadPose() says: Writing Data\n")); - // // Copy the Raw measurements directly to the client. // if (temp_head_pose->confidence > 0.0f) { memcpy(&pMemData->data.new_pose,temp_head_pose,sizeof(smEngineHeadPoseData)); - sprintf(msg, "HeadPose Yaw: %.2f\n", pMemData->data.new_pose.head_rot.x_rads); - OutputDebugStringA(msg); - } - - if (pMemData->command == 100) { - stopCommand = TRUE; } ReleaseMutex(hSMMutex); } - }; // diff --git a/faceAPI/utils.h b/faceAPI/utils.h index 9c67665e..1fdb35b5 100644 --- a/faceAPI/utils.h +++ b/faceAPI/utils.h @@ -25,7 +25,7 @@ namespace sm bool g_ctrl_c_detected(false); bool g_do_head_pose_printing(false); bool g_do_face_data_printing(false); - unsigned short g_overlay_flags(SM_API_VIDEO_DISPLAY_HEAD_MESH); + unsigned short g_overlay_flags(SM_API_VIDEO_DISPLAY_HEAD_MESH | SM_API_VIDEO_DISPLAY_PERFORMANCE); // CTRL-C handler function void __cdecl CtrlCHandler(int) @@ -324,20 +324,20 @@ namespace sm { HANDLE console_handle = GetStdHandle(STD_OUTPUT_HANDLE); // Buffer of 255 x 1024 - ////COORD buffer_size; - ////buffer_size.X = 255; - ////buffer_size.Y = 1024; - ////SetConsoleScreenBufferSize(console_handle, buffer_size); - ////// Window size of 120 x 50 - ////SMALL_RECT window_size; - ////window_size.Left = 0; - ////window_size.Right = 20; - ////window_size.Top = 0; - ////window_size.Bottom = 20; - ////SetConsoleWindowInfo(console_handle,TRUE,&window_size); + COORD buffer_size; + buffer_size.X = 255; + buffer_size.Y = 1024; + SetConsoleScreenBufferSize(console_handle, buffer_size); + // Window size of 120 x 50 + SMALL_RECT window_size; + window_size.Left = 0; + window_size.Right = 120; + window_size.Top = 0; + window_size.Bottom = 50; + SetConsoleWindowInfo(console_handle,TRUE,&window_size); // Green text SetConsoleTextAttribute(console_handle, FOREGROUND_GREEN | FOREGROUND_INTENSITY); - ShowWindow(GetConsoleWindow(), SW_HIDE); +// ShowWindow(GetConsoleWindow(), SW_HIDE); } } } -- cgit v1.2.3