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_SM/FTNoIR_Tracker_SM.h | 9 ++--- FTNoIR_Tracker_SM/FTNoIR_Tracker_SM.vcproj | 2 +- FTNoIR_Tracker_SM/ftnoir_tracker_faceapi.cpp | 52 +++++++++++++++++++--------- 3 files changed, 41 insertions(+), 22 deletions(-) (limited to 'FTNoIR_Tracker_SM') 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())) -- cgit v1.2.3