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 --- faceAPI/FaceAPI2FSX.vcproj | 233 +++++++++++++++++++++++++++++++++++++++++++++ faceAPI/main.cpp | 95 +++++++++++++----- faceAPI/utils.h | 26 ++--- 3 files changed, 316 insertions(+), 38 deletions(-) create mode 100644 faceAPI/FaceAPI2FSX.vcproj (limited to 'faceAPI') 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