From f41f404de607b4f8f5aa270e36ae7c43baf63862 Mon Sep 17 00:00:00 2001 From: Xavier Hallade Date: Wed, 3 Feb 2016 23:40:48 +0100 Subject: tracker/rs: added camera preview, removed separate process and TCP socket the RS implementation still resides in a different DLL as it has to be compiled separately by MSVC compiler. --- tracker-rs/ftnoir_tracker_rs.cpp | 139 ++++++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 62 deletions(-) (limited to 'tracker-rs/ftnoir_tracker_rs.cpp') diff --git a/tracker-rs/ftnoir_tracker_rs.cpp b/tracker-rs/ftnoir_tracker_rs.cpp index e073fa3f..7bb47256 100644 --- a/tracker-rs/ftnoir_tracker_rs.cpp +++ b/tracker-rs/ftnoir_tracker_rs.cpp @@ -7,97 +7,112 @@ #include "ftnoir_tracker_rs.h" #include "ftnoir_tracker_rs_controls.h" - +#include "imagewidget.h" #include "opentrack/plugin-api.hpp" #include +#include +#include -RSTracker::RSTracker() : mPose{ 0,0,0, 0,0,0 } { - mThread.setObjectName("RSTrackerWorkerThread"); +RSTracker::RSTracker() { + connect(&mTrackerWorkerThread, &RSTrackerWorkerThread::trackingHasFinished, + this, &RSTracker::handleTrackingEnded); - mRealSenseImplProcess.moveToThread(&mThread); - mSocket.moveToThread(&mThread); + connect(&mPreviewUpdateTimer, &QTimer::timeout, + this, &RSTracker::updatePreview); +} - connect(&mRealSenseImplProcess, SIGNAL(finished(int)), - this, SLOT(rsImplProcessFinished(int)), Qt::QueuedConnection); +void RSTracker::configurePreviewFrame() +{ + if(mImageWidget!=nullptr || mPreviewFrame==nullptr) + return; - qRegisterMetaType("QProcess::ProcessError"); - connect(&mRealSenseImplProcess, SIGNAL(error(QProcess::ProcessError)), - this, SLOT(rsImplProcessError(QProcess::ProcessError)), Qt::QueuedConnection); + mImageWidget = new ImageWidget(mPreviewFrame); + mImageWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); - connect(&mSocket, SIGNAL(readyRead()), - this, SLOT(readPendingUdpPoseData()), Qt::DirectConnection); + if(mPreviewFrame->layout() != nullptr){ + delete mPreviewFrame->layout(); + } - connect(&mThread, &QThread::started, - &mThread, [this]{ - mSocket.bind(QHostAddress::LocalHost, 4242, QUdpSocket::DontShareAddress); - mRealSenseImplProcess.start("opentrack-tracker-rs-impl.exe", QProcess::NotOpen); - }, Qt::DirectConnection); + QLayout* layout = new QStackedLayout(); + mPreviewFrame->setLayout(layout); - connect(&mThread, &QThread::finished, - &mThread, [this]{ - mRealSenseImplProcess.kill(); - mRealSenseImplProcess.waitForFinished(); - }, Qt::DirectConnection); + layout->addWidget(mImageWidget); } -void RSTracker::start_tracker(QFrame*) +void RSTracker::start_tracker(QFrame* previewFrame) { - mThread.start(); + mPreviewFrame = previewFrame; + + mTrackerWorkerThread.start(QThread::HighPriority); + + configurePreviewFrame(); + + startPreview(); } -void RSTracker::readPendingUdpPoseData(){ - double pose[6]; +void RSTracker::startPreview(){ + mPreviewUpdateTimer.start(kPreviewUpdateInterval); +} - while(mSocket.hasPendingDatagrams()) { - mSocket.readDatagram((char*)pose, sizeof(pose)); - QMutexLocker foo(&mMutex); - memcpy(mPose, pose, sizeof(pose)); +void RSTracker::updatePreview(){ + if(mImageWidget->isEnabled()) + mImageWidget->setImage(mTrackerWorkerThread.getPreview()); +} + +void RSTracker::stopPreview(){ + mPreviewUpdateTimer.stop(); +} + +void RSTracker::handleTrackingEnded(int exitCode){ + stopPreview(); + + if(exitCode!=0) + showRealSenseErrorMessageBox(exitCode); +} + +bool RSTracker::startSdkInstallationProcess() +{ + bool pStarted = QProcess::startDetached("contrib\\intel_rs_sdk_runtime_websetup_7.0.23.8048.exe --finstall=core,face3d --fnone=all"); + if(!pStarted){ + QMessageBox::warning(0, "Intel® RealSense™ Runtime Installation", "Installation process failed to start.", QMessageBox::Ok); } + return pStarted; } -void RSTracker::rsImplProcessError(QProcess::ProcessError error){ - if(error == QProcess::FailedToStart){ - QMessageBox::warning(NULL, "RealSense Tracking Error", "Couldn't start the RealSense tracking module.\nMaybe opentrack-tracker-rs-impl.exe is missing.", QMessageBox::Ok); +void RSTracker::showRealSenseErrorMessageBox(int exitCode) +{ + 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 R5."); } - else if(error == QProcess::Crashed){ - QMessageBox::warning(NULL, "RealSense Tracking Error", "The RealSense tracking module has crashed.", QMessageBox::Ok); + else { + msgBox.setInformativeText("Status code: " + QString::number(exitCode) + ".\n\nNote that you need the latest camera drivers and the SDK runtime R5 to be installed."); } -} + QPushButton* triggerSdkInstallation = msgBox.addButton("Install Runtime", QMessageBox::ActionRole); + msgBox.addButton(QMessageBox::Ok); + msgBox.exec(); -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 R5."); - } - else { - msgBox.setInformativeText("Status code: " + QString::number(exitCode) + ".\n\nNote that you need the latest camera drivers and the SDK runtime R5 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("contrib\\intel_rs_sdk_runtime_websetup_7.0.23.8048.exe --finstall=core,face3d --fnone=all"); - if(!pStarted){ - QMessageBox::warning(0, "Intel® RealSense™ Runtime Installation", "Installation process failed to start.", QMessageBox::Ok); - } - } - } + if(msgBox.clickedButton() == triggerSdkInstallation) + startSdkInstallationProcess(); } void RSTracker::data(double *data) { - QMutexLocker foo(&mMutex); - memcpy(data, mPose, sizeof(mPose)); + mTrackerWorkerThread.getPose(data); } RSTracker::~RSTracker() { - mThread.quit(); - mThread.wait(); + stopPreview(); + + if (mPreviewFrame!=nullptr && mPreviewFrame->layout()!=nullptr) + delete mPreviewFrame->layout(); + + mTrackerWorkerThread.requestInterruption(); + mTrackerWorkerThread.quit(); + mTrackerWorkerThread.wait(); } QString RSTrackerMetaData::name() { -- cgit v1.2.3 From 652bdad279f7769523d3c6faa609448028907256 Mon Sep 17 00:00:00 2001 From: Xavier Hallade Date: Thu, 11 Feb 2016 16:50:09 +0100 Subject: tracker/rs: updated runtime to 2016 R1. --- tracker-rs/CMakeLists.txt | 2 +- tracker-rs/ftnoir_tracker_rs.cpp | 4 ++-- tracker-rs/ftnoir_tracker_rs_controls.ui | 10 +++++----- tracker-rs/ftnoir_tracker_rs_worker.cpp | 9 +++++---- .../intel_rs_sdk_runtime_websetup_7.0.23.8048.exe | Bin 1203240 -> 0 bytes .../intel_rs_sdk_runtime_websetup_8.0.24.6528.exe | Bin 0 -> 1226096 bytes .../rs_impl/bin/opentrack-tracker-rs-impl.dll | Bin 72704 -> 72704 bytes .../rs_impl/bin/opentrack-tracker-rs-impl.lib | Bin 2882 -> 2882 bytes 8 files changed, 13 insertions(+), 12 deletions(-) delete mode 100644 tracker-rs/redist/intel_rs_sdk_runtime_websetup_7.0.23.8048.exe create mode 100644 tracker-rs/redist/intel_rs_sdk_runtime_websetup_8.0.24.6528.exe (limited to 'tracker-rs/ftnoir_tracker_rs.cpp') diff --git a/tracker-rs/CMakeLists.txt b/tracker-rs/CMakeLists.txt index 76ffd191..9219aafd 100644 --- a/tracker-rs/CMakeLists.txt +++ b/tracker-rs/CMakeLists.txt @@ -2,5 +2,5 @@ if(WIN32) opentrack_boilerplate(opentrack-tracker-rs) target_link_libraries(opentrack-tracker-rs "${CMAKE_SOURCE_DIR}/tracker-rs/rs_impl/bin/opentrack-tracker-rs-impl.lib") install(FILES "${CMAKE_SOURCE_DIR}/tracker-rs/rs_impl/bin/opentrack-tracker-rs-impl.dll" DESTINATION . ${opentrack-perms}) - install(FILES "${CMAKE_SOURCE_DIR}/tracker-rs/redist/intel_rs_sdk_runtime_websetup_7.0.23.8048.exe" DESTINATION ./contrib/ ${opentrack-perms}) + install(FILES "${CMAKE_SOURCE_DIR}/tracker-rs/redist/intel_rs_sdk_runtime_websetup_8.0.24.6528.exe" DESTINATION ./contrib/ ${opentrack-perms}) endif() diff --git a/tracker-rs/ftnoir_tracker_rs.cpp b/tracker-rs/ftnoir_tracker_rs.cpp index 7bb47256..d8d12210 100644 --- a/tracker-rs/ftnoir_tracker_rs.cpp +++ b/tracker-rs/ftnoir_tracker_rs.cpp @@ -72,7 +72,7 @@ void RSTracker::handleTrackingEnded(int exitCode){ bool RSTracker::startSdkInstallationProcess() { - bool pStarted = QProcess::startDetached("contrib\\intel_rs_sdk_runtime_websetup_7.0.23.8048.exe --finstall=core,face3d --fnone=all"); + bool pStarted = QProcess::startDetached("contrib\\intel_rs_sdk_runtime_websetup_8.0.24.6528.exe --finstall=core,face3d --fnone=all"); if(!pStarted){ QMessageBox::warning(0, "Intel® RealSense™ Runtime Installation", "Installation process failed to start.", QMessageBox::Ok); } @@ -88,7 +88,7 @@ void RSTracker::showRealSenseErrorMessageBox(int exitCode) msgBox.setInformativeText("Couldn't initialize RealSense tracking. Please install SDK Runtime R5."); } else { - msgBox.setInformativeText("Status code: " + QString::number(exitCode) + ".\n\nNote that you need the latest camera drivers and the SDK runtime R5 to be installed."); + msgBox.setInformativeText("Status code: " + QString::number(exitCode) + ".\n\nNote that you need the latest camera drivers and the SDK runtime 2016 R1 to be installed."); } QPushButton* triggerSdkInstallation = msgBox.addButton("Install Runtime", QMessageBox::ActionRole); diff --git a/tracker-rs/ftnoir_tracker_rs_controls.ui b/tracker-rs/ftnoir_tracker_rs_controls.ui index 023e14d3..30d06956 100644 --- a/tracker-rs/ftnoir_tracker_rs_controls.ui +++ b/tracker-rs/ftnoir_tracker_rs_controls.ui @@ -9,8 +9,8 @@ 0 0 - 378 - 193 + 484 + 244 @@ -36,15 +36,15 @@ 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 R5 runtime. +In order to use this tracker, you need a PC equipped with an Intel® RealSense™ +F200 or SR300 camera and the RealSense™ SDK 2016 R1 runtime. - Install SDK Runtime R5 + Install Runtime diff --git a/tracker-rs/ftnoir_tracker_rs_worker.cpp b/tracker-rs/ftnoir_tracker_rs_worker.cpp index c387b731..213f13ff 100644 --- a/tracker-rs/ftnoir_tracker_rs_worker.cpp +++ b/tracker-rs/ftnoir_tracker_rs_worker.cpp @@ -29,13 +29,14 @@ void RSTrackerWorkerThread::run(){ while(!isInterruptionRequested()){ retValue = rs_tracker_impl_update_pose(pose); - if(retValue!=0 && retValue!=-303){ // -303 is only a timeout. + if(retValue == 0){ // success + QMutexLocker lock(&mMutex); + memcpy(mPose, pose, sizeof(pose)); + } + else if(retValue != -303){ // pose update failed. -303 is OK as it's only a timeout. emit trackingHasFinished(retValue); break; } - - QMutexLocker lock(&mMutex); - memcpy(mPose, pose, sizeof(pose)); } rs_tracker_impl_end(); diff --git a/tracker-rs/redist/intel_rs_sdk_runtime_websetup_7.0.23.8048.exe b/tracker-rs/redist/intel_rs_sdk_runtime_websetup_7.0.23.8048.exe deleted file mode 100644 index 2e2b365c..00000000 Binary files a/tracker-rs/redist/intel_rs_sdk_runtime_websetup_7.0.23.8048.exe and /dev/null differ diff --git a/tracker-rs/redist/intel_rs_sdk_runtime_websetup_8.0.24.6528.exe b/tracker-rs/redist/intel_rs_sdk_runtime_websetup_8.0.24.6528.exe new file mode 100644 index 00000000..5b3704ed Binary files /dev/null and b/tracker-rs/redist/intel_rs_sdk_runtime_websetup_8.0.24.6528.exe differ diff --git a/tracker-rs/rs_impl/bin/opentrack-tracker-rs-impl.dll b/tracker-rs/rs_impl/bin/opentrack-tracker-rs-impl.dll index 9e75d4e3..d6e0a261 100644 Binary files a/tracker-rs/rs_impl/bin/opentrack-tracker-rs-impl.dll and b/tracker-rs/rs_impl/bin/opentrack-tracker-rs-impl.dll differ diff --git a/tracker-rs/rs_impl/bin/opentrack-tracker-rs-impl.lib b/tracker-rs/rs_impl/bin/opentrack-tracker-rs-impl.lib index 772cd340..47743c50 100644 Binary files a/tracker-rs/rs_impl/bin/opentrack-tracker-rs-impl.lib and b/tracker-rs/rs_impl/bin/opentrack-tracker-rs-impl.lib differ -- cgit v1.2.3 From 61a58641089b07b23910c94c677e262388039fb9 Mon Sep 17 00:00:00 2001 From: Xavier Hallade Date: Fri, 12 Feb 2016 10:46:39 +0100 Subject: tracker/rs: cleaned up preview widget setup and deletetion. --- tracker-rs/ftnoir_tracker_rs.cpp | 14 ++++++++++---- tracker-rs/ftnoir_tracker_rs_worker.cpp | 4 ++-- tracker-rs/imagewidget.cpp | 9 ++++++--- tracker-rs/imagewidget.h | 3 ++- 4 files changed, 20 insertions(+), 10 deletions(-) (limited to 'tracker-rs/ftnoir_tracker_rs.cpp') diff --git a/tracker-rs/ftnoir_tracker_rs.cpp b/tracker-rs/ftnoir_tracker_rs.cpp index d8d12210..99c5e9d0 100644 --- a/tracker-rs/ftnoir_tracker_rs.cpp +++ b/tracker-rs/ftnoir_tracker_rs.cpp @@ -26,6 +26,8 @@ void RSTracker::configurePreviewFrame() if(mImageWidget!=nullptr || mPreviewFrame==nullptr) return; + mPreviewFrame->show(); + mImageWidget = new ImageWidget(mPreviewFrame); mImageWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); @@ -35,19 +37,20 @@ void RSTracker::configurePreviewFrame() QLayout* layout = new QStackedLayout(); mPreviewFrame->setLayout(layout); - layout->addWidget(mImageWidget); + + mImageWidget->show(); } void RSTracker::start_tracker(QFrame* previewFrame) { mPreviewFrame = previewFrame; - mTrackerWorkerThread.start(QThread::HighPriority); - configurePreviewFrame(); startPreview(); + + mTrackerWorkerThread.start(QThread::HighPriority); } void RSTracker::startPreview(){ @@ -55,7 +58,7 @@ void RSTracker::startPreview(){ } void RSTracker::updatePreview(){ - if(mImageWidget->isEnabled()) + if(mImageWidget!=nullptr && mImageWidget->isEnabled()) mImageWidget->setImage(mTrackerWorkerThread.getPreview()); } @@ -107,6 +110,9 @@ void RSTracker::data(double *data) RSTracker::~RSTracker() { stopPreview(); + if(mImageWidget!=nullptr) + delete mImageWidget; + if (mPreviewFrame!=nullptr && mPreviewFrame->layout()!=nullptr) delete mPreviewFrame->layout(); diff --git a/tracker-rs/ftnoir_tracker_rs_worker.cpp b/tracker-rs/ftnoir_tracker_rs_worker.cpp index 213f13ff..c0ea6749 100644 --- a/tracker-rs/ftnoir_tracker_rs_worker.cpp +++ b/tracker-rs/ftnoir_tracker_rs_worker.cpp @@ -11,7 +11,7 @@ RSTrackerWorkerThread::RSTrackerWorkerThread(): mPose{0,0,0,0,0,0}{ setObjectName("RSTrackerWorkerThread"); - mPreviewRawData = (uchar*)malloc(kPreviewStreamWidth*kPreviewStreamHeight); + mPreviewRawData = (uchar*)malloc(1*kPreviewStreamWidth*kPreviewStreamHeight); memset(mPreviewRawData, 125, kPreviewStreamWidth*kPreviewStreamHeight); //start with a gray image. } @@ -33,7 +33,7 @@ void RSTrackerWorkerThread::run(){ QMutexLocker lock(&mMutex); memcpy(mPose, pose, sizeof(pose)); } - else if(retValue != -303){ // pose update failed. -303 is OK as it's only a timeout. + else if(retValue != -303){ // pose update failed and not because of a timeout (-303) emit trackingHasFinished(retValue); break; } diff --git a/tracker-rs/imagewidget.cpp b/tracker-rs/imagewidget.cpp index 0136c621..63986234 100644 --- a/tracker-rs/imagewidget.cpp +++ b/tracker-rs/imagewidget.cpp @@ -16,12 +16,15 @@ ImageWidget::ImageWidget(QWidget *parent) : void ImageWidget::setImage(const QImage image) { - mImage = image; + { + QMutexLocker lock(&mMutex); + mImage = image; + } repaint(); } void ImageWidget::paintEvent(QPaintEvent*) { - QPainter painter(this); - painter.drawImage(rect(), mImage, mImage.rect()); + QMutexLocker lock(&mMutex); + QPainter(this).drawImage(rect(), mImage, mImage.rect()); } diff --git a/tracker-rs/imagewidget.h b/tracker-rs/imagewidget.h index 8f800058..e8b6e61e 100644 --- a/tracker-rs/imagewidget.h +++ b/tracker-rs/imagewidget.h @@ -9,6 +9,7 @@ #include #include +#include class ImageWidget : public QWidget { Q_OBJECT @@ -18,7 +19,7 @@ public: private: QImage mImage; - uchar* mRawData; + QMutex mMutex; protected: void paintEvent(QPaintEvent* event); -- cgit v1.2.3