diff options
-rw-r--r-- | tracker-pt/camera.cpp | 12 | ||||
-rw-r--r-- | tracker-pt/camera.h | 9 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.cpp | 30 |
3 files changed, 39 insertions, 12 deletions
diff --git a/tracker-pt/camera.cpp b/tracker-pt/camera.cpp index c995c11b..85a5a93b 100644 --- a/tracker-pt/camera.cpp +++ b/tracker-pt/camera.cpp @@ -9,9 +9,14 @@ #include <string> #include <QDebug> #include "opentrack-compat/sleep.hpp" +#include "opentrack-compat/camera-names.hpp" -void Camera::set_device_index(int index) +void Camera::set_device(const QString& name) { + const int index = camera_name_to_index(name); + + desired_name = name; + if (desired_index != index) { desired_index = index; @@ -24,6 +29,11 @@ void Camera::set_device_index(int index) } } +QString Camera::get_desired_name() const +{ + return desired_name; +} + void Camera::set_fps(int fps) { if (cam_desired.fps != fps) diff --git a/tracker-pt/camera.h b/tracker-pt/camera.h index e73d9dff..615f7142 100644 --- a/tracker-pt/camera.h +++ b/tracker-pt/camera.h @@ -11,6 +11,7 @@ #include <memory> #include <opencv2/highgui.hpp> #include <string> +#include <QString> struct CamInfo { @@ -35,7 +36,7 @@ public: void restart() { stop(); start(); } // calls corresponding template methods and reinitializes frame rate calculation - void set_device_index(int index); + void set_device(const QString& name); void set_fps(int fps); void set_res(int x_res, int y_res); @@ -46,6 +47,7 @@ public: bool get_info(CamInfo &ret); CamInfo get_desired() const { return cam_desired; } + QString get_desired_name() const; protected: // get a frame from the camera virtual bool _get_frame(cv::Mat* frame) = 0; @@ -58,10 +60,11 @@ private: float dt_valid; float dt_mean; protected: - int desired_index; - int active_index; CamInfo cam_info; CamInfo cam_desired; + QString desired_name; + int desired_index; + int active_index; }; inline Camera::~Camera() {} diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index 6dd40ceb..14813b62 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -153,15 +153,29 @@ void Tracker_PT::run() void Tracker_PT::apply_settings() { - qDebug()<<"Tracker:: Applying settings"; + qDebug() << "Tracker:: Applying settings"; QMutexLocker l(&camera_mtx); - camera.stop(); - camera.set_device_index(camera_name_to_index(s.camera_name)); - camera.set_res(s.cam_res_x, s.cam_res_y); - camera.set_fps(s.cam_fps); - camera.start(); - frame = cv::Mat(); - qDebug()<<"Tracker::apply ends"; + + CamInfo info = camera.get_desired(); + const QString name = camera.get_desired_name(); + + if (s.cam_fps != info.fps || + s.cam_res_x != info.res_x || + s.cam_res_y != info.res_y || + s.camera_name != name) + { + qDebug() << "pt: camera reset needed"; + camera.stop(); + camera.set_device(s.camera_name); + camera.set_res(s.cam_res_x, s.cam_res_y); + camera.set_fps(s.cam_fps); + frame = cv::Mat(); + camera.start(); + } + else + qDebug() << "pt: camera not needing reset"; + + qDebug() << "Tracker::apply ends"; } void Tracker_PT::start_tracker(QFrame *parent_window) |