From 88f3a9e7f6bc7d54fa98a63166eaf55e4762224e Mon Sep 17 00:00:00 2001 From: Xavier Hallade Date: Fri, 21 Aug 2015 20:22:52 +0200 Subject: added a tracker that uses the RealSense SDK --- .gitignore | 3 + CMakeLists.txt | 9 ++ ftnoir_tracker_rs/README.md | 16 +++ ftnoir_tracker_rs/ftnoir_tracker_rs.cpp | 111 +++++++++++++++ ftnoir_tracker_rs/ftnoir_tracker_rs.h | 46 +++++++ ftnoir_tracker_rs/ftnoir_tracker_rs_controls.cpp | 40 ++++++ ftnoir_tracker_rs/ftnoir_tracker_rs_controls.h | 23 ++++ ftnoir_tracker_rs/ftnoir_tracker_rs_controls.ui | 67 +++++++++ ftnoir_tracker_rs/images/RS.png | Bin 0 -> 4287 bytes .../intel_rs_sdk_runtime_websetup_6.0.21.6598.exe | Bin 0 -> 780456 bytes .../rs_impl/bin/opentrack-tracker-rs-impl.exe | Bin 0 -> 83968 bytes ftnoir_tracker_rs/rs_impl/build.bat | 2 + .../rs_impl/ftnoir_tracker_rs_impl.cpp | 151 +++++++++++++++++++++ ftnoir_tracker_rs/rs_impl/ftnoir_tracker_rs_impl.h | 19 +++ ftnoir_tracker_rs/rs_impl/udp_sender.cpp | 53 ++++++++ ftnoir_tracker_rs/rs_tracker.qrc | 5 + 16 files changed, 545 insertions(+) create mode 100644 ftnoir_tracker_rs/README.md create mode 100644 ftnoir_tracker_rs/ftnoir_tracker_rs.cpp create mode 100644 ftnoir_tracker_rs/ftnoir_tracker_rs.h create mode 100644 ftnoir_tracker_rs/ftnoir_tracker_rs_controls.cpp create mode 100644 ftnoir_tracker_rs/ftnoir_tracker_rs_controls.h create mode 100644 ftnoir_tracker_rs/ftnoir_tracker_rs_controls.ui create mode 100644 ftnoir_tracker_rs/images/RS.png create mode 100644 ftnoir_tracker_rs/redist/intel_rs_sdk_runtime_websetup_6.0.21.6598.exe create mode 100644 ftnoir_tracker_rs/rs_impl/bin/opentrack-tracker-rs-impl.exe create mode 100644 ftnoir_tracker_rs/rs_impl/build.bat create mode 100644 ftnoir_tracker_rs/rs_impl/ftnoir_tracker_rs_impl.cpp create mode 100644 ftnoir_tracker_rs/rs_impl/ftnoir_tracker_rs_impl.h create mode 100644 ftnoir_tracker_rs/rs_impl/udp_sender.cpp create mode 100644 ftnoir_tracker_rs/rs_tracker.qrc diff --git a/.gitignore b/.gitignore index 7aef1021..d3ccc990 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ # merely git cola saves there /patches/ .DS_Store +*.obj +*.exp +*.pdb \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 54fbfed5..c54b1780 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -360,6 +360,10 @@ endif() opentrack_library(opentrack-tracker-udp ftnoir_tracker_udp) opentrack_library(opentrack-tracker-freepie-udp ftnoir_tracker_freepie-udp) +if(WIN32) + opentrack_library(opentrack-tracker-rs ftnoir_tracker_rs) +endif() + if(OpenCV_FOUND) opentrack_library(opentrack-tracker-pt ftnoir_tracker_pt) target_link_libraries(opentrack-tracker-pt ${OpenCV_LIBS}) @@ -553,6 +557,11 @@ if(WIN32) install(FILES "${CMAKE_SOURCE_DIR}/bin/cleye.config" DESTINATION .) endif() +if(WIN32) + install(FILES "${CMAKE_SOURCE_DIR}/ftnoir_tracker_rs/rs_impl/bin/opentrack-tracker-rs-impl.exe" DESTINATION . ${opentrack-perms}) + install(FILES "${CMAKE_SOURCE_DIR}/ftnoir_tracker_rs/redist/intel_rs_sdk_runtime_websetup_6.0.21.6598.exe" DESTINATION ./clientfiles/ ${opentrack-perms}) +endif() + if(APPLE) install(CODE " execute_process(COMMAND /bin/sh \"${CMAKE_SOURCE_DIR}/macosx/make-app-bundle.sh\" diff --git a/ftnoir_tracker_rs/README.md b/ftnoir_tracker_rs/README.md new file mode 100644 index 00000000..5fca4392 --- /dev/null +++ b/ftnoir_tracker_rs/README.md @@ -0,0 +1,16 @@ +# Intel® RealSense™ plugin for opentrack +This is a tracker providing markerless 3D head tracking using the Intel® RealSense™ SDK and the Intel® RealSense™ front-facing cameras. + +More information on RealSense can be found on [Intel.com](http://www.intel.com/content/www/us/en/architecture-and-technology/realsense-overview.html) + +This tracker uses a separate process that gets data from the SDK. Its sources are under rs_impl and can be recompiled by calling build.bat, which depends on +Microsoft Visual C++ Compiler and the [Intel® RealSense™ SDK R4](https://software.intel.com/en-us/intel-realsense-sdk) + +# ISC License +Copyright (c) 2015, Intel Corporation + + Author: Xavier Hallade + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/ftnoir_tracker_rs/ftnoir_tracker_rs.cpp b/ftnoir_tracker_rs/ftnoir_tracker_rs.cpp new file mode 100644 index 00000000..deae3bca --- /dev/null +++ b/ftnoir_tracker_rs/ftnoir_tracker_rs.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2015, Intel Corporation + * Author: Xavier Hallade + * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "ftnoir_tracker_rs.h" +#include "ftnoir_tracker_rs_controls.h" + +#include "opentrack/plugin-api.hpp" +#include + +RSTracker::RSTracker() : mPose{ 0,0,0, 0,0,0 } { + mThread.setObjectName("RSTrackerWorkerThread"); + + mRealSenseImplProcess.moveToThread(&mThread); + mSocket.moveToThread(&mThread); + + connect(&mRealSenseImplProcess, SIGNAL(finished(int)), + this, SLOT(rsImplProcessFinished(int)), Qt::QueuedConnection); + + qRegisterMetaType("QProcess::ProcessError"); + connect(&mRealSenseImplProcess, SIGNAL(error(QProcess::ProcessError)), + this, SLOT(rsImplProcessError(QProcess::ProcessError)), Qt::QueuedConnection); + + connect(&mSocket, SIGNAL(readyRead()), + this, SLOT(readPendingUdpPoseData()), Qt::DirectConnection); + + connect(&mThread, &QThread::started, + &mThread, [this]{ + mSocket.bind(QHostAddress::LocalHost, 4242, QUdpSocket::DontShareAddress); + mRealSenseImplProcess.start("clientfiles\\opentrack-tracker-rs-impl.exe", QProcess::NotOpen); + }, Qt::DirectConnection); + + connect(&mThread, &QThread::finished, + &mThread, [this]{ + mRealSenseImplProcess.kill(); + mRealSenseImplProcess.waitForFinished(); + }, Qt::DirectConnection); +} + +void RSTracker::start_tracker(QFrame*) +{ + mThread.start(); +} + +void RSTracker::readPendingUdpPoseData(){ + double pose[6]; + + while(mSocket.hasPendingDatagrams()) { + mSocket.readDatagram((char*)pose, sizeof(pose)); + QMutexLocker foo(&mMutex); + memcpy(mPose, pose, sizeof(pose)); + } +} + +void RSTracker::rsImplProcessError(QProcess::ProcessError error){ + if(error == QProcess::FailedToStart){ + QMessageBox::warning(NULL, "RealSense Tracking Error", "Couldn't start the RealSense tracking module.\nMaybe clientfiles\\opentrack-tracker-rs-impl.exe is missing.", QMessageBox::Ok); + } + else if(error == QProcess::Crashed){ + QMessageBox::warning(NULL, "RealSense Tracking Error", "The RealSense tracking module has crashed.", QMessageBox::Ok); + } +} + + +void RSTracker::rsImplProcessFinished(int exitCode){ + if(exitCode!=0){ + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Critical); + msgBox.setText("RealSense Tracking Error"); + if(exitCode==-101){ //The implementation got an invalid handle from the RealSense SDK session/modules + msgBox.setInformativeText("Couldn't initialize RealSense tracking. Please install SDK Runtime R4."); + } + else { + msgBox.setInformativeText("Status code: " + QString::number(exitCode) + ".\n\nNote that you need the latest camera drivers and the SDK runtime R4 to be installed."); + } + QPushButton* triggerSdkInstallation = msgBox.addButton("Install Runtime", QMessageBox::ActionRole); + msgBox.addButton(QMessageBox::Ok); + msgBox.exec(); + + if(msgBox.clickedButton() == triggerSdkInstallation){ + bool pStarted = QProcess::startDetached("clientfiles\\intel_rs_sdk_runtime_websetup_6.0.21.6598.exe --finstall=core,face3d --fnone=all"); + if(!pStarted){ + QMessageBox::warning(0, "Intel® RealSenseTM Runtime Installation", "Installation process failed to start.", QMessageBox::Ok); + } + } + } +} + +void RSTracker::data(double *data) +{ + QMutexLocker foo(&mMutex); + memcpy(data, mPose, sizeof(mPose)); +} + +RSTracker::~RSTracker() { + mThread.quit(); + mThread.wait(); +} + +QString RSTrackerMetaData::name() { + return QString("RealSense 3D Face Tracking"); +} + +QIcon RSTrackerMetaData::icon() { + return QIcon(":/images/RS.png"); +} + +OPENTRACK_DECLARE_TRACKER(RSTracker, RSTrackerControls, RSTrackerMetaData) diff --git a/ftnoir_tracker_rs/ftnoir_tracker_rs.h b/ftnoir_tracker_rs/ftnoir_tracker_rs.h new file mode 100644 index 00000000..7cda7370 --- /dev/null +++ b/ftnoir_tracker_rs/ftnoir_tracker_rs.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Intel Corporation + * Author: Xavier Hallade + * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#pragma once + +#include "ui_ftnoir_tracker_rs_controls.h" +#include "opentrack/plugin-api.hpp" +#include +#include +#include +#include + +class RSTracker : protected QObject, public ITracker +{ + Q_OBJECT + +public: + RSTracker(); + ~RSTracker(); + void start_tracker(QFrame *) override; + void data(double *data) override; + +private: + QMutex mMutex; + QThread mThread; + QProcess mRealSenseImplProcess; + QUdpSocket mSocket; + double mPose[6]; + +private slots: + void rsImplProcessError(QProcess::ProcessError); + void rsImplProcessFinished(int); + void readPendingUdpPoseData(); + +}; + +class RSTrackerMetaData : public Metadata +{ +public: + QString name(); + QIcon icon(); +}; diff --git a/ftnoir_tracker_rs/ftnoir_tracker_rs_controls.cpp b/ftnoir_tracker_rs/ftnoir_tracker_rs_controls.cpp new file mode 100644 index 00000000..e5187bd1 --- /dev/null +++ b/ftnoir_tracker_rs/ftnoir_tracker_rs_controls.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015, Intel Corporation + * Author: Xavier Hallade + * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "ftnoir_tracker_rs_controls.h" + +#include +#include + +RSTrackerControls::RSTrackerControls() +{ + ui.setupUi(this); + connect(ui.triggerSDKInstallButton, SIGNAL(clicked(bool)), this, SLOT(doInstallRSRuntime())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); +} + +void RSTrackerControls::doInstallRSRuntime() +{ + bool processStarted = QProcess::startDetached("clientfiles\\intel_rs_sdk_runtime_websetup_6.0.21.6598.exe --finstall=core,face3d --fnone=all"); + if(processStarted){ + this->close(); + } + else{ + QMessageBox::warning(0, "Intel® RealSenseTM Runtime Installation", "Installation process failed to start.", QMessageBox::Ok); + } +} + +void RSTrackerControls::doOK() +{ + this->close(); +} + +void RSTrackerControls::doCancel() +{ + this->close(); +} diff --git a/ftnoir_tracker_rs/ftnoir_tracker_rs_controls.h b/ftnoir_tracker_rs/ftnoir_tracker_rs_controls.h new file mode 100644 index 00000000..010dac99 --- /dev/null +++ b/ftnoir_tracker_rs/ftnoir_tracker_rs_controls.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2015, Intel Corporation + * Author: Xavier Hallade + * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "ftnoir_tracker_rs.h" + +class RSTrackerControls : public ITrackerDialog +{ + Q_OBJECT +public: + RSTrackerControls(); + void register_tracker(ITracker *) {} + void unregister_tracker() {} +private: + Ui::UIRSControls ui; + private slots: + void doOK(); + void doCancel(); + void doInstallRSRuntime(); +}; diff --git a/ftnoir_tracker_rs/ftnoir_tracker_rs_controls.ui b/ftnoir_tracker_rs/ftnoir_tracker_rs_controls.ui new file mode 100644 index 00000000..834803d1 --- /dev/null +++ b/ftnoir_tracker_rs/ftnoir_tracker_rs_controls.ui @@ -0,0 +1,67 @@ + + + UIRSControls + + + Qt::NonModal + + + + 0 + 0 + 378 + 193 + + + + RealSense 3D Tracker settings + + + + images/RS.pngimages/RS.png + + + Qt::LeftToRight + + + false + + + + + + There is no configuration available at the moment. + +The application will activate your camera for face tracking by the +Intel® RealSense™ SDK. By design, the application has no direct access +to any camera images. + +In order to use this tracker, you need a PC equipped with +an Intel® RealSense™ R200 camera and the RealSense™ SDK R4 runtime. + + + + + + + Install SDK Runtime R4 + + + + + + + QDialogButtonBox::Ok + + + + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/ftnoir_tracker_rs/images/RS.png b/ftnoir_tracker_rs/images/RS.png new file mode 100644 index 00000000..bc1dfc11 Binary files /dev/null and b/ftnoir_tracker_rs/images/RS.png differ diff --git a/ftnoir_tracker_rs/redist/intel_rs_sdk_runtime_websetup_6.0.21.6598.exe b/ftnoir_tracker_rs/redist/intel_rs_sdk_runtime_websetup_6.0.21.6598.exe new file mode 100644 index 00000000..34ecc9df Binary files /dev/null and b/ftnoir_tracker_rs/redist/intel_rs_sdk_runtime_websetup_6.0.21.6598.exe differ diff --git a/ftnoir_tracker_rs/rs_impl/bin/opentrack-tracker-rs-impl.exe b/ftnoir_tracker_rs/rs_impl/bin/opentrack-tracker-rs-impl.exe new file mode 100644 index 00000000..1e2a57f1 Binary files /dev/null and b/ftnoir_tracker_rs/rs_impl/bin/opentrack-tracker-rs-impl.exe differ diff --git a/ftnoir_tracker_rs/rs_impl/build.bat b/ftnoir_tracker_rs/rs_impl/build.bat new file mode 100644 index 00000000..15206431 --- /dev/null +++ b/ftnoir_tracker_rs/rs_impl/build.bat @@ -0,0 +1,2 @@ +cd "%VS120COMNTOOLS%\..\..\VC" +vcvarsall x64 && cd %~dp0 && CL /nologo /Ox /DUNICODE /D_UNICODE /MT /I"%RSSDK_DIR%\opensource\include" ftnoir_tracker_rs_impl.cpp udp_sender.cpp "%RSSDK_DIR%\opensource\src\libpxc\libpxc.cpp" /link ADVAPI32.LIB Ws2_32.lib /SUBSYSTEM:CONSOLE /OUT:bin\opentrack-tracker-rs-impl.exe \ No newline at end of file diff --git a/ftnoir_tracker_rs/rs_impl/ftnoir_tracker_rs_impl.cpp b/ftnoir_tracker_rs/rs_impl/ftnoir_tracker_rs_impl.cpp new file mode 100644 index 00000000..c1ba5c75 --- /dev/null +++ b/ftnoir_tracker_rs/rs_impl/ftnoir_tracker_rs_impl.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2015, Intel Corporation + * Author: Xavier Hallade + * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "ftnoir_tracker_rs_impl.h" +#include +#include + +PXCSenseManager* g_senseManager = NULL; +PXCFaceData* g_faceData = NULL; + +pxcStatus rs_tracker_set_configuration(PXCFaceModule *faceModule){ + pxcStatus retStatus; + PXCFaceConfiguration *faceConfig = NULL; + + if (faceModule == NULL) + return PXC_STATUS_HANDLE_INVALID; + + faceConfig = faceModule->CreateActiveConfiguration(); + if (faceConfig == NULL){ + return PXC_STATUS_HANDLE_INVALID; + } + + faceConfig->pose.isEnabled = true; + faceConfig->pose.maxTrackedFaces = 1; + faceConfig->pose.smoothingLevel = PXCFaceConfiguration::SmoothingLevelType::SMOOTHING_DISABLED; + faceConfig->strategy = PXCFaceConfiguration::STRATEGY_CLOSEST_TO_FARTHEST; + faceConfig->detection.isEnabled = false; + faceConfig->landmarks.isEnabled = false; + faceConfig->DisableAllAlerts(); + faceConfig->SetTrackingMode(PXCFaceConfiguration::FACE_MODE_COLOR_PLUS_DEPTH); + + retStatus = faceConfig->ApplyChanges(); + if (retStatus != PXC_STATUS_NO_ERROR){ + faceConfig->Release(); + return retStatus; + } + + faceConfig->Release(); + return PXC_STATUS_NO_ERROR; +} + +int rs_tracker_impl_start(){ + pxcStatus retStatus; + PXCFaceModule *faceModule = NULL; + + g_senseManager = PXCSenseManager::CreateInstance(); + if (g_senseManager == NULL){ + rs_tracker_impl_end(); + return PXC_STATUS_HANDLE_INVALID; + } + + retStatus = g_senseManager->EnableFace(); + if (retStatus != PXC_STATUS_NO_ERROR){ + rs_tracker_impl_end(); + return retStatus; + } + + faceModule = g_senseManager->QueryFace(); + if (faceModule == NULL){ + rs_tracker_impl_end(); + return PXC_STATUS_HANDLE_INVALID; + } + + retStatus = rs_tracker_set_configuration(faceModule); + if (retStatus != PXC_STATUS_NO_ERROR){ + rs_tracker_impl_end(); + return PXC_STATUS_HANDLE_INVALID; + } + + retStatus = g_senseManager->Init(); + if (retStatus != PXC_STATUS_NO_ERROR){ + rs_tracker_impl_end(); + return retStatus; + } + + g_faceData = faceModule->CreateOutput(); + if (g_faceData == NULL){ + rs_tracker_impl_end(); + return PXC_STATUS_HANDLE_INVALID; + } + + return PXC_STATUS_NO_ERROR; +} + +int rs_tracker_impl_update_pose(double *data){ + pxcStatus retStatus; + PXCFaceData::PoseEulerAngles angles; + PXCFaceData::HeadPosition headPosition; + PXCFaceData::Face *face = NULL; + PXCFaceData::PoseData *pose = NULL; + bool poseAnglesAvailable = false; + bool headPositionAvailable = false; + + if (g_senseManager != NULL && g_faceData != NULL + && (retStatus = g_senseManager->AcquireFrame(true, 16)) == PXC_STATUS_NO_ERROR){ + + retStatus = g_faceData->Update(); + if (retStatus != PXC_STATUS_NO_ERROR){ + rs_tracker_impl_end(); + return retStatus; + } + + pxcI32 numberOfDetectedFaces = g_faceData->QueryNumberOfDetectedFaces(); + for (pxcI32 i = 0; i < numberOfDetectedFaces; ++i) { + face = g_faceData->QueryFaceByIndex(0); + if (face == NULL) continue; + + pose = face->QueryPose(); + if (pose == NULL) continue; + + poseAnglesAvailable = pose->QueryPoseAngles(&angles); + if (!poseAnglesAvailable) continue; + + headPositionAvailable = pose->QueryHeadPosition(&headPosition); + if (!headPositionAvailable) continue; + + //TODO: use pxcI32 pose->QueryConfidence(); ? for data[6] or to filter here ? + + //x, y, z: cm + data[0] = headPosition.headCenter.x / 10.; + data[1] = headPosition.headCenter.y / 10.; + data[2] = headPosition.headCenter.z / 10.; + + //yaw, pitch, roll: degrees + data[3] = -angles.yaw; + data[4] = angles.pitch; + data[5] = -angles.roll; + } + + g_senseManager->ReleaseFrame(); + } + + return retStatus; +} + +int rs_tracker_impl_end(){ + if (g_faceData != NULL){ + g_faceData->Release(); + g_faceData = NULL; + } + + if (g_senseManager != NULL){ + g_senseManager->Release(); + g_senseManager = NULL; + } + return PXC_STATUS_NO_ERROR; +} diff --git a/ftnoir_tracker_rs/rs_impl/ftnoir_tracker_rs_impl.h b/ftnoir_tracker_rs/rs_impl/ftnoir_tracker_rs_impl.h new file mode 100644 index 00000000..0e4073d0 --- /dev/null +++ b/ftnoir_tracker_rs/rs_impl/ftnoir_tracker_rs_impl.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2015, Intel Corporation + * Author: Xavier Hallade + * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#pragma once +#ifdef EXPORT_RS_IMPL +#define RSTRACKERIMPL_VISIBILITY __declspec( dllexport ) +#else +#define RSTRACKERIMPL_VISIBILITY +#endif + +extern "C" { + RSTRACKERIMPL_VISIBILITY int rs_tracker_impl_start(); + RSTRACKERIMPL_VISIBILITY int rs_tracker_impl_update_pose(double *pose); + RSTRACKERIMPL_VISIBILITY int rs_tracker_impl_end(); +} diff --git a/ftnoir_tracker_rs/rs_impl/udp_sender.cpp b/ftnoir_tracker_rs/rs_impl/udp_sender.cpp new file mode 100644 index 00000000..095edd8f --- /dev/null +++ b/ftnoir_tracker_rs/rs_impl/udp_sender.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Intel Corporation + * Author: Xavier Hallade + * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "ftnoir_tracker_rs_impl.h" +#include +#include +#include +#include + +#define UDP_PORT 4242 + +int main(){ + double pose[6] = { 0., 0., 0., 0., 0., 0. }; + struct sockaddr_in socketInfo; + SOCKET s = 0; + WSADATA wsa; + + int retStatus = rs_tracker_impl_start(); + if (retStatus != 0){ + exit(retStatus); + } + + if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) //init winsocketapi + exit(EXIT_FAILURE); + + memset(&socketInfo, 0, sizeof(socketInfo)); + socketInfo.sin_family = AF_INET; + socketInfo.sin_port = htons(UDP_PORT); + InetPton(AF_INET, L"127.0.0.1", &socketInfo.sin_addr.S_un.S_addr); + + if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == SOCKET_ERROR) //create UDP socket + exit(EXIT_FAILURE); + + for(;;) { + retStatus = rs_tracker_impl_update_pose(pose); + if(retStatus == 0){ //no error + if (sendto(s, (char*)&pose, sizeof(pose), 0, (struct sockaddr *) &socketInfo, sizeof(socketInfo)) == SOCKET_ERROR) //send new data + exit(EXIT_FAILURE); + } + + if(retStatus != 0 && retStatus != -303)// -303=timeout and 0 are ok, else we've got to stop. + break; + } + + closesocket(s); + WSACleanup(); + + return retStatus; +} diff --git a/ftnoir_tracker_rs/rs_tracker.qrc b/ftnoir_tracker_rs/rs_tracker.qrc new file mode 100644 index 00000000..ccdda669 --- /dev/null +++ b/ftnoir_tracker_rs/rs_tracker.qrc @@ -0,0 +1,5 @@ + + + images/RS.png + + -- cgit v1.2.3