From 2e7407a094c74b629cbe8348e9007c6373e476fe Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 6 Jul 2015 10:01:24 +0200 Subject: aruco: use camera settings class --- ftnoir_tracker_aruco/aruco-trackercontrols.ui | 88 ++++++++++++++++----------- ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 43 ++++++++----- ftnoir_tracker_aruco/ftnoir_tracker_aruco.h | 10 ++- 3 files changed, 88 insertions(+), 53 deletions(-) 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 @@ 0 0 - 562 - 178 + 586 + 202 @@ -62,6 +62,43 @@ + + + + + 0 + 0 + + + + + 640x480 + + + + + 320x240 + + + + + 320x200 + + + + + Default (not recommended!) + + + + + + + + Camera name + + + @@ -111,50 +148,27 @@ - - + + 0 0 - - - 640x480 - - - - - 320x240 - - - - - 320x200 - - - - - Default (not recommended!) - - - - + + - Camera name + Camera settings - - - - - 0 - 0 - + + + + Open @@ -174,7 +188,7 @@ - + 0 0 @@ -190,7 +204,7 @@ - + 0 0 @@ -206,7 +220,7 @@ - + 0 0 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 #include @@ -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 { Q_OBJECT public: @@ -83,4 +88,5 @@ private slots: void toggleCalibrate(); void cleanupCalib(); void update_tracker_calibration(); + void camera_settings(); }; -- cgit v1.2.3