diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-08 05:55:32 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-08 05:55:59 +0200 |
commit | 527eef2a2f0e68b286e1b782ba148ecdfafbb89c (patch) | |
tree | 2be0f0b96df712f7b12534291db3c36564be62ca /opentrack/opencv-camera-dialog.hpp | |
parent | 3a54a111567370ecf903704d702d12736b693a8e (diff) | |
parent | ab47eac174db02710a7fa6c194e00c31cef755a4 (diff) |
Merge branch 'unstable' into trackhat-ui
Diffstat (limited to 'opentrack/opencv-camera-dialog.hpp')
-rw-r--r-- | opentrack/opencv-camera-dialog.hpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/opentrack/opencv-camera-dialog.hpp b/opentrack/opencv-camera-dialog.hpp index 3b700a70..6218f125 100644 --- a/opentrack/opencv-camera-dialog.hpp +++ b/opentrack/opencv-camera-dialog.hpp @@ -1,5 +1,6 @@ #pragma once +#include <QTimer> #include <QMutex> #include <QMutexLocker> #include <opencv2/videoio.hpp> @@ -9,6 +10,14 @@ template<typename tracker> class camera_dialog { cv::VideoCapture fake_capture; + QTimer t; + +private: + void delete_capture() + { + fake_capture.open(""); + } + public: void open_camera_settings(cv::VideoCapture* cap, const QString& camera_name, QMutex* camera_mtx) { @@ -23,10 +32,20 @@ public: } } + if (t.isActive()) + return; + + // don't hog the camera capture + if (!t.isSingleShot()) + QObject::connect(&t, &QTimer::timeout, [&]() -> void { delete_capture(); }); + + t.setSingleShot(true); + t.setInterval(3000); + 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(""); + // HACK: we're not notified when it's safe to close the capture + t.start(); } }; |