summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-06 11:41:16 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-06 11:41:16 +0200
commit3a54a111567370ecf903704d702d12736b693a8e (patch)
tree1981d1bb3a97165d954ed8856061bb44d88fdd7c
parentf58efb5c2c51e5866d4640036865792b822641f6 (diff)
parentfcb8ca75c0c274be2321f0ba91e9f129ae63e354 (diff)
Merge branch 'unstable' into trackhat-ui
-rw-r--r--facetracknoir/settings.ui2
-rw-r--r--ftnoir_protocol_sc/ftnoir_protocol_sc.cpp92
-rw-r--r--ftnoir_protocol_sc/ftnoir_protocol_sc.h33
-rw-r--r--ftnoir_tracker_aruco/aruco-trackercontrols.ui88
-rw-r--r--ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp43
-rw-r--r--ftnoir_tracker_aruco/ftnoir_tracker_aruco.h10
-rw-r--r--ftnoir_tracker_ht/ftnoir_tracker_ht.cpp6
-rw-r--r--ftnoir_tracker_ht/ftnoir_tracker_ht.h5
-rw-r--r--ftnoir_tracker_ht/ht-trackercontrols.ui60
-rw-r--r--ftnoir_tracker_pt/camera.h3
-rw-r--r--ftnoir_tracker_pt/ftnoir_tracker_pt.cpp8
-rw-r--r--ftnoir_tracker_pt/ftnoir_tracker_pt.h6
-rw-r--r--opentrack/camera-names.hpp2
-rw-r--r--opentrack/opencv-camera-dialog.hpp32
14 files changed, 220 insertions, 170 deletions
diff --git a/facetracknoir/settings.ui b/facetracknoir/settings.ui
index b41c09a0..523829f6 100644
--- a/facetracknoir/settings.ui
+++ b/facetracknoir/settings.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>462</width>
- <height>605</height>
+ <height>657</height>
</rect>
</property>
<property name="windowTitle">
diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
index 465d8d20..7d4e09f9 100644
--- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
+++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
@@ -29,8 +29,6 @@
#include "ftnoir_protocol_sc.h"
#include "opentrack/plugin-api.hpp"
-static QLibrary SCClientLib;
-
FTNoIR_Protocol::FTNoIR_Protocol() : should_stop(false), hSimConnect(nullptr)
{
}
@@ -43,28 +41,42 @@ FTNoIR_Protocol::~FTNoIR_Protocol()
void FTNoIR_Protocol::run()
{
- if (!SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0)))
+ HANDLE event = CreateEvent(NULL, FALSE, FALSE, nullptr);
+
+ if (event == nullptr)
+ {
+ qDebug() << "simconnect: event create" << GetLastError();
return;
-#if 0
- simconnect_subscribetosystemevent(hSimConnect, EVENT_PING, "Frame");
+ }
- simconnect_mapclienteventtosimevent(hSimConnect, EVENT_INIT, "");
- simconnect_addclienteventtonotificationgroup(hSimConnect, GROUP0, EVENT_INIT, false);
- simconnect_setnotificationgrouppriority(hSimConnect, GROUP0, SIMCONNECT_GROUP_PRIORITY_HIGHEST);
-#endif
-
while (!should_stop)
{
- (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast<void*>(this)));
- Sleep(1);
+ if (SUCCEEDED(simconnect_open(&hSimConnect, "opentrack", NULL, 0, event, 0)))
+ {
+ simconnect_subscribetosystemevent(hSimConnect, 0, "Frame");
+
+ while (!should_stop)
+ {
+ if (WaitForSingleObject(event, 10) == WAIT_OBJECT_0)
+ {
+ if (FAILED(simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast<void*>(this))))
+ break;
+ }
+ }
+
+ (void) simconnect_close(hSimConnect);
+ }
+
+ if (!should_stop)
+ Sleep(100);
}
-
- (void) simconnect_close(hSimConnect);
+
+ CloseHandle(event);
}
void FTNoIR_Protocol::pose( const double *headpose ) {
virtSCRotX = -headpose[Pitch]; // degrees
- virtSCRotY = -headpose[Yaw];
+ virtSCRotY = headpose[Yaw];
virtSCRotZ = headpose[Roll];
virtSCPosX = headpose[TX]/100.f; // cm to meters
@@ -72,11 +84,13 @@ void FTNoIR_Protocol::pose( const double *headpose ) {
virtSCPosZ = -headpose[TZ]/100.f;
}
-#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#ifdef __GNUC__
+# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#endif
class ActivationContext {
public:
- ActivationContext(const int resid) :ok (false) {
+ ActivationContext(const int resid) : ok(false) {
hactctx = INVALID_HANDLE_VALUE;
actctx_cookie = 0;
ACTCTXA actx = {0};
@@ -99,6 +113,8 @@ public:
ReleaseActCtx(hactctx);
hactctx = INVALID_HANDLE_VALUE;
}
+ else
+ ok = true;
} else {
qDebug() << "SC: can't create win32 activation context" << GetLastError();
}
@@ -135,9 +151,6 @@ bool FTNoIR_Protocol::correct()
return false;
}
- //
- // Get the functions from the DLL.
- //
simconnect_open = (importSimConnect_Open) SCClientLib.resolve("SimConnect_Open");
if (simconnect_open == NULL) {
qDebug() << "FTNoIR_Protocol::correct() says: SimConnect_Open function not found in DLL!";
@@ -154,8 +167,6 @@ bool FTNoIR_Protocol::correct()
return false;
}
- //return true;
-
simconnect_calldispatch = (importSimConnect_CallDispatch) SCClientLib.resolve("SimConnect_CallDispatch");
if (simconnect_calldispatch == NULL) {
qDebug() << "FTNoIR_Protocol::correct() says: SimConnect_CallDispatch function not found in DLL!";
@@ -168,26 +179,6 @@ bool FTNoIR_Protocol::correct()
return false;
}
- simconnect_mapclienteventtosimevent = (importSimConnect_MapClientEventToSimEvent) SCClientLib.resolve("SimConnect_MapClientEventToSimEvent");
- if (simconnect_subscribetosystemevent == NULL) {
- qDebug() << "FTNoIR_Protocol::correct() says: SimConnect_MapClientEventToSimEvent function not found in DLL!";
- return false;
- }
-
- simconnect_addclienteventtonotificationgroup = (importSimConnect_AddClientEventToNotificationGroup) SCClientLib.resolve("SimConnect_AddClientEventToNotificationGroup");
- if (simconnect_subscribetosystemevent == NULL) {
- qDebug() << "FTNoIR_Protocol::correct() says: SimConnect_AddClientEventToNotificationGroup function not found in DLL!";
- return false;
- }
-
- simconnect_setnotificationgrouppriority = (importSimConnect_SetNotificationGroupPriority) SCClientLib.resolve("SimConnect_SetNotificationGroupPriority");
- if (simconnect_subscribetosystemevent == NULL) {
- qDebug() << "FTNoIR_Protocol::correct() says: SimConnect_SetNotificationGroupPriority function not found in DLL!";
- return false;
- }
-
- qDebug() << "FTNoIR_Protocol::correct() says: SimConnect functions resolved in DLL!";
-
start();
return true;
@@ -195,22 +186,7 @@ bool FTNoIR_Protocol::correct()
void FTNoIR_Protocol::handle()
{
- if (prevSCPosX != virtSCPosX ||
- prevSCPosY != virtSCPosY ||
- prevSCPosZ != virtSCPosZ ||
- prevSCRotX != virtSCRotX ||
- prevSCRotY != virtSCRotY ||
- prevSCRotZ != virtSCRotZ)
- {
- (void) simconnect_set6DOF(hSimConnect, virtSCPosX, virtSCPosY, virtSCPosZ, virtSCRotX, virtSCRotZ, virtSCRotY);
- }
-
- prevSCPosX = virtSCPosX;
- prevSCPosY = virtSCPosY;
- prevSCPosZ = virtSCPosZ;
- prevSCRotX = virtSCRotX;
- prevSCRotY = virtSCRotY;
- prevSCRotZ = virtSCRotZ;
+ (void) simconnect_set6DOF(hSimConnect, virtSCPosX, virtSCPosY, virtSCPosZ, virtSCRotX, virtSCRotZ, virtSCRotY);
}
void CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD, void *self_)
diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.h b/ftnoir_protocol_sc/ftnoir_protocol_sc.h
index b65bac85..7c32d014 100644
--- a/ftnoir_protocol_sc/ftnoir_protocol_sc.h
+++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.h
@@ -54,27 +54,6 @@ typedef HRESULT (WINAPI *importSimConnect_Close)(HANDLE hSimConnect);
typedef HRESULT (WINAPI *importSimConnect_CameraSetRelative6DOF)(HANDLE hSimConnect, float fDeltaX, float fDeltaY, float fDeltaZ, float fPitchDeg, float fBankDeg, float fHeadingDeg);
typedef HRESULT (WINAPI *importSimConnect_CallDispatch)(HANDLE hSimConnect, DispatchProc pfcnDispatch, void * pContext);
typedef HRESULT (WINAPI *importSimConnect_SubscribeToSystemEvent)(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char * SystemEventName);
-typedef HRESULT (WINAPI *importSimConnect_MapClientEventToSimEvent)(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char * EventName);
-typedef HRESULT (WINAPI *importSimConnect_AddClientEventToNotificationGroup)(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, SIMCONNECT_CLIENT_EVENT_ID EventID, BOOL bMaskable);
-typedef HRESULT (WINAPI *importSimConnect_SetNotificationGroupPriority)(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, DWORD uPriority);
-
-#define SC_CLIENT_FILENAME "SimConnect.dll"
-
-enum GROUP_ID
-{
- GROUP0=0,
-};
-
-enum EVENT_ID
-{
- EVENT_PING=0,
- EVENT_INIT,
-};
-
-enum INPUT_ID
-{
- INPUT0=0,
-};
struct settings : opts {
value<int> sxs_manifest;
@@ -106,26 +85,16 @@ private:
volatile float virtSCRotY;
volatile float virtSCRotZ;
- float prevSCPosX;
- float prevSCPosY;
- float prevSCPosZ;
-
- float prevSCRotX;
- float prevSCRotY;
- float prevSCRotZ;
-
importSimConnect_Open simconnect_open; // SimConnect function(s) in DLL
importSimConnect_Close simconnect_close;
importSimConnect_CameraSetRelative6DOF simconnect_set6DOF;
importSimConnect_CallDispatch simconnect_calldispatch;
importSimConnect_SubscribeToSystemEvent simconnect_subscribetosystemevent;
- importSimConnect_MapClientEventToSimEvent simconnect_mapclienteventtosimevent;
- importSimConnect_AddClientEventToNotificationGroup simconnect_addclienteventtonotificationgroup;
- importSimConnect_SetNotificationGroupPriority simconnect_setnotificationgrouppriority;
HANDLE hSimConnect; // Handle to SimConnect
static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext);
settings s;
+ QLibrary SCClientLib;
};
class SCControls: public IProtocolDialog
diff --git a/ftnoir_tracker_aruco/aruco-trackercontrols.ui b/ftnoir_tracker_aruco/aruco-trackercontrols.ui
index 15184c41..4433c47c 100644
--- a/ftnoir_tracker_aruco/aruco-trackercontrols.ui
+++ b/ftnoir_tracker_aruco/aruco-trackercontrols.ui
@@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>562</width>
- <height>178</height>
+ <width>586</width>
+ <height>202</height>
</rect>
</property>
<property name="sizePolicy">
@@ -62,6 +62,43 @@
</property>
</widget>
</item>
+ <item row="3" column="1">
+ <widget class="QComboBox" name="resolution">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>640x480</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>320x240</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>320x200</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Default (not recommended!)</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Camera name</string>
+ </property>
+ </widget>
+ </item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
@@ -111,50 +148,27 @@
</item>
</widget>
</item>
- <item row="3" column="1">
- <widget class="QComboBox" name="resolution">
+ <item row="2" column="1">
+ <widget class="QComboBox" name="cameraName">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <item>
- <property name="text">
- <string>640x480</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>320x240</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>320x200</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Default (not recommended!)</string>
- </property>
- </item>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QLabel" name="label_3">
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_6">
<property name="text">
- <string>Camera name</string>
+ <string>Camera settings</string>
</property>
</widget>
</item>
- <item row="2" column="1">
- <widget class="QComboBox" name="cameraName">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
+ <item row="4" column="1">
+ <widget class="QPushButton" name="camera_settings">
+ <property name="text">
+ <string>Open</string>
</property>
</widget>
</item>
@@ -174,7 +188,7 @@
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="cy">
<property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -190,7 +204,7 @@
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="cx">
<property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -206,7 +220,7 @@
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="cz">
<property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp
index ca8cea9e..70af379d 100644
--- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp
+++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp
@@ -101,26 +101,31 @@ void Tracker::run()
fps = 200;
break;
}
- camera = cv::VideoCapture(camera_name_to_index(s.camera_name));
- if (res.width)
+
{
- camera.set(cv::CAP_PROP_FRAME_WIDTH, res.width);
- camera.set(cv::CAP_PROP_FRAME_HEIGHT, res.height);
+ QMutexLocker l(&camera_mtx);
+
+ camera = cv::VideoCapture(camera_name_to_index(s.camera_name));
+ if (res.width)
+ {
+ camera.set(cv::CAP_PROP_FRAME_WIDTH, res.width);
+ camera.set(cv::CAP_PROP_FRAME_HEIGHT, res.height);
+ }
+ if (fps)
+ camera.set(cv::CAP_PROP_FPS, fps);
+
+ if (!camera.isOpened())
+ {
+ qDebug() << "aruco tracker: can't open camera";
+ return;
+ }
}
- if (fps)
- camera.set(cv::CAP_PROP_FPS, fps);
aruco::MarkerDetector detector;
detector.setDesiredSpeed(3);
cv::Rect last_roi(65535, 65535, 0, 0);
- if (!camera.isOpened())
- {
- fprintf(stderr, "aruco tracker: can't open camera\n");
- return;
- }
-
auto freq = cv::getTickFrequency();
auto last_time = cv::getTickCount();
double cur_fps = 0;
@@ -133,8 +138,12 @@ void Tracker::run()
while (!stop)
{
cv::Mat color;
- if (!camera.read(color))
- continue;
+ {
+ QMutexLocker l(&camera_mtx);
+
+ if (!camera.read(color))
+ continue;
+ }
cv::Mat grayscale;
cv::cvtColor(color, grayscale, cv::COLOR_RGB2GRAY);
@@ -391,6 +400,7 @@ TrackerControls::TrackerControls()
connect(ui.btn_calibrate, SIGNAL(clicked()), this, SLOT(toggleCalibrate()));
connect(this, SIGNAL(destroyed()), this, SLOT(cleanupCalib()));
connect(&calib_timer, SIGNAL(timeout()), this, SLOT(update_tracker_calibration()));
+ connect(ui.camera_settings, SIGNAL(pressed()), this, SLOT(camera_settings()));
}
void TrackerControls::toggleCalibrate()
@@ -440,3 +450,8 @@ void TrackerControls::doCancel()
s.b->reload();
this->close();
}
+
+void TrackerControls::camera_settings()
+{
+ open_camera_settings(tracker ? &tracker->camera : nullptr, s.camera_name, tracker ? &tracker->camera_mtx : nullptr);
+}
diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h
index 875a9d41..297fecdb 100644
--- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h
+++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h
@@ -18,6 +18,7 @@
#include "opentrack/options.hpp"
#include "ftnoir_tracker_aruco/trans_calib.h"
#include "opentrack/plugin-api.hpp"
+#include "opentrack/opencv-camera-dialog.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
@@ -40,9 +41,12 @@ struct settings : opts {
{}
};
+class TrackerControls;
+
class Tracker : protected QThread, public ITracker
{
Q_OBJECT
+ friend class TrackerControls;
static constexpr double c_search_window = 2.65;
public:
Tracker();
@@ -52,6 +56,8 @@ public:
void run();
void getRT(cv::Matx33d &r, cv::Vec3d &t);
private:
+ cv::VideoCapture camera;
+ QMutex camera_mtx;
QMutex mtx;
volatile bool stop;
QHBoxLayout* layout;
@@ -59,12 +65,11 @@ private:
settings s;
double pose[6];
cv::Mat frame;
- cv::VideoCapture camera;
cv::Matx33d r;
cv::Vec3d t;
};
-class TrackerControls : public ITrackerDialog
+class TrackerControls : public ITrackerDialog, protected camera_dialog<Tracker>
{
Q_OBJECT
public:
@@ -83,4 +88,5 @@ private slots:
void toggleCalibrate();
void cleanupCalib();
void update_tracker_calibration();
+ void camera_settings();
};
diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp
index b922c0b2..3d142dcb 100644
--- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp
+++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp
@@ -170,6 +170,7 @@ TrackerControls::TrackerControls()
tie_setting(s.resolution, ui.resolution);
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));
+ connect(ui.camera_settings, SIGNAL(pressed()), this, SLOT(camera_settings()));
}
void TrackerControls::doOK()
@@ -183,3 +184,8 @@ void TrackerControls::doCancel()
s.b->reload();
this->close();
}
+
+void TrackerControls::camera_settings()
+{
+ open_camera_settings(nullptr, s.camera_name, nullptr);
+}
diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.h b/ftnoir_tracker_ht/ftnoir_tracker_ht.h
index cd4ffa16..25839039 100644
--- a/ftnoir_tracker_ht/ftnoir_tracker_ht.h
+++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.h
@@ -16,6 +16,8 @@
#include <QObject>
#include "opentrack/options.hpp"
#include "opentrack/plugin-api.hpp"
+#include "opentrack/opencv-camera-dialog.hpp"
+
using namespace options;
struct settings : opts {
@@ -50,7 +52,7 @@ private:
};
// Widget that has controls for FTNoIR protocol client-settings.
-class TrackerControls : public ITrackerDialog
+class TrackerControls : public ITrackerDialog, protected camera_dialog<Tracker>
{
Q_OBJECT
public:
@@ -65,6 +67,7 @@ private:
private slots:
void doOK();
void doCancel();
+ void camera_settings();
};
#endif
diff --git a/ftnoir_tracker_ht/ht-trackercontrols.ui b/ftnoir_tracker_ht/ht-trackercontrols.ui
index 0b94ffc5..dd5e57f3 100644
--- a/ftnoir_tracker_ht/ht-trackercontrols.ui
+++ b/ftnoir_tracker_ht/ht-trackercontrols.ui
@@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>354</width>
- <height>158</height>
+ <height>179</height>
</rect>
</property>
<property name="sizePolicy">
@@ -29,6 +29,13 @@
<string>HT tracker settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Frames per second</string>
+ </property>
+ </widget>
+ </item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="cameraFOV">
<property name="locale">
@@ -52,13 +59,6 @@
</property>
</widget>
</item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Frames per second</string>
- </property>
- </widget>
- </item>
<item row="1" column="1">
<widget class="QComboBox" name="cameraFPS">
<item>
@@ -88,23 +88,9 @@
</item>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>Camera name</string>
- </property>
- </widget>
- </item>
<item row="2" column="1">
<widget class="QComboBox" name="cameraName"/>
</item>
- <item row="3" column="0">
- <widget class="QLabel" name="label_4">
- <property name="text">
- <string>Resolution</string>
- </property>
- </widget>
- </item>
<item row="3" column="1">
<widget class="QComboBox" name="resolution">
<item>
@@ -129,13 +115,41 @@
</item>
</widget>
</item>
- <item row="4" column="1">
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Resolution</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Camera name</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Camera settings</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QPushButton" name="camera_settings">
+ <property name="text">
+ <string>Open</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>
diff --git a/ftnoir_tracker_pt/camera.h b/ftnoir_tracker_pt/camera.h
index bffd19ee..63614ded 100644
--- a/ftnoir_tracker_pt/camera.h
+++ b/ftnoir_tracker_pt/camera.h
@@ -89,12 +89,13 @@ public:
void start() override;
void stop() override;
+ operator cv::VideoCapture&() { return *cap; }
+
protected:
bool _get_frame(cv::Mat* frame) override;
void _set_fps() override;
void _set_res() override;
void _set_device_index() override;
-
private:
cv::VideoCapture* cap;
};
diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp
index 2f852343..d48f9252 100644
--- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp
+++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp
@@ -86,7 +86,12 @@ void Tracker_PT::run()
const double dt = time.elapsed() * 1e-9;
time.start();
cv::Mat frame;
- const bool new_frame = camera.get_frame(dt, &frame);
+ bool new_frame;
+
+ {
+ QMutexLocker l(&camera_mtx);
+ new_frame = camera.get_frame(dt, &frame);
+ }
if (new_frame && !frame.empty())
{
@@ -145,6 +150,7 @@ void Tracker_PT::run()
void Tracker_PT::apply_settings()
{
qDebug()<<"Tracker:: Applying settings";
+ QMutexLocker l(&camera_mtx);
QMutexLocker lock(&mutex);
camera.set_device_index(camera_name_to_index("PS3Eye Camera"));
int res_x, res_y, cam_fps;
diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.h b/ftnoir_tracker_pt/ftnoir_tracker_pt.h
index 3b9f1648..d0764933 100644
--- a/ftnoir_tracker_pt/ftnoir_tracker_pt.h
+++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.h
@@ -17,6 +17,7 @@
#include "point_tracker.h"
#include "pt_video_widget.h"
#include "opentrack/timer.hpp"
+#include "opentrack/opencv-camera-dialog.hpp"
#include <QThread>
#include <QMutex>
@@ -30,11 +31,15 @@
#endif
#include <vector>
+class TrackerDialog_PT;
+
//-----------------------------------------------------------------------------
// Constantly processes the tracking chain in a separate thread
class Tracker_PT : public QThread, public ITracker
{
Q_OBJECT
+ friend class camera_dialog<Tracker_PT>;
+ friend class TrackerDialog_PT;
public:
Tracker_PT();
~Tracker_PT() override;
@@ -61,6 +66,7 @@ private:
volatile int commands;
+ QMutex camera_mtx;
CVCamera camera;
PointExtractor point_extractor;
PointTracker point_tracker;
diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp
index 3d3948fa..6f82ba34 100644
--- a/opentrack/camera-names.hpp
+++ b/opentrack/camera-names.hpp
@@ -13,6 +13,7 @@
# include <unistd.h>
#endif
+template<typename = void>
QList<QString> get_camera_names() {
QList<QString> ret;
#if defined(_WIN32)
@@ -82,6 +83,7 @@ QList<QString> get_camera_names() {
return ret;
}
+template<typename = void>
int camera_name_to_index(const QString &name)
{
auto list = get_camera_names();
diff --git a/opentrack/opencv-camera-dialog.hpp b/opentrack/opencv-camera-dialog.hpp
new file mode 100644
index 00000000..3b700a70
--- /dev/null
+++ b/opentrack/opencv-camera-dialog.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <QMutex>
+#include <QMutexLocker>
+#include <opencv2/videoio.hpp>
+#include "opentrack/camera-names.hpp"
+
+template<typename tracker>
+class camera_dialog
+{
+ cv::VideoCapture fake_capture;
+public:
+ void open_camera_settings(cv::VideoCapture* cap, const QString& camera_name, QMutex* camera_mtx)
+ {
+ if (cap)
+ {
+ QMutexLocker l(camera_mtx);
+
+ if (cap->isOpened())
+ {
+ cap->set(cv::CAP_PROP_SETTINGS, 1);
+ return;
+ }
+ }
+
+ fake_capture = cv::VideoCapture(camera_name_to_index(camera_name));
+ fake_capture.set(cv::CAP_PROP_SETTINGS, 1);
+ // don't hog the camera capture
+ fake_capture.open("");
+ }
+};
+