diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-06 10:01:24 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-07-06 10:47:44 +0200 |
commit | 2e7407a094c74b629cbe8348e9007c6373e476fe (patch) | |
tree | 10049a7d1eb41d442648741b77846119e95096bc | |
parent | 81d2ffa8b95f0dce0a89784d08fe3ba9501cca1e (diff) |
aruco: use camera settings class
-rw-r--r-- | ftnoir_tracker_aruco/aruco-trackercontrols.ui | 88 | ||||
-rw-r--r-- | ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 43 | ||||
-rw-r--r-- | 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 @@ <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(); }; |