diff options
Diffstat (limited to 'tracker-aruco')
-rw-r--r-- | tracker-aruco/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tracker-aruco/aruco-trackercontrols.ui | 30 | ||||
-rw-r--r-- | tracker-aruco/ftnoir_tracker_aruco.cpp | 94 | ||||
-rw-r--r-- | tracker-aruco/ftnoir_tracker_aruco.h | 70 | ||||
-rw-r--r-- | tracker-aruco/lang/nl_NL.ts | 31 | ||||
-rw-r--r-- | tracker-aruco/lang/ru_RU.ts | 31 | ||||
-rw-r--r-- | tracker-aruco/lang/stub.ts | 31 | ||||
-rw-r--r-- | tracker-aruco/lang/zh_CN.ts | 31 |
8 files changed, 138 insertions, 182 deletions
diff --git a/tracker-aruco/CMakeLists.txt b/tracker-aruco/CMakeLists.txt index 253cdd5f..bfa7a348 100644 --- a/tracker-aruco/CMakeLists.txt +++ b/tracker-aruco/CMakeLists.txt @@ -15,7 +15,7 @@ if(OpenCV_FOUND) maybe_add_static_define() - set(modules "${SDK_ARUCO_LIBPATH}" opencv_core opencv_calib3d opencv_imgproc opencv_videoio) + set(modules "${SDK_ARUCO_LIBPATH}" opencv_calib3d opencv_imgproc opencv_core) get_filename_component(dir "${SDK_ARUCO_LIBPATH}" DIRECTORY) get_filename_component(dir "${dir}" ABSOLUTE) diff --git a/tracker-aruco/aruco-trackercontrols.ui b/tracker-aruco/aruco-trackercontrols.ui index a1600a8f..9c3bd78a 100644 --- a/tracker-aruco/aruco-trackercontrols.ui +++ b/tracker-aruco/aruco-trackercontrols.ui @@ -154,36 +154,6 @@ <verstretch>0</verstretch> </sizepolicy> </property> - <item> - <property name="text"> - <string>Default</string> - </property> - </item> - <item> - <property name="text"> - <string>30</string> - </property> - </item> - <item> - <property name="text"> - <string>60</string> - </property> - </item> - <item> - <property name="text"> - <string>75</string> - </property> - </item> - <item> - <property name="text"> - <string>125</string> - </property> - </item> - <item> - <property name="text"> - <string>200</string> - </property> - </item> </widget> </item> <item row="4" column="1"> diff --git a/tracker-aruco/ftnoir_tracker_aruco.cpp b/tracker-aruco/ftnoir_tracker_aruco.cpp index 502b50ad..8928566f 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.cpp +++ b/tracker-aruco/ftnoir_tracker_aruco.cpp @@ -5,7 +5,6 @@ * copyright notice and this permission notice appear in all copies. */ -#include "cv/video-widget.hpp" #include "ftnoir_tracker_aruco.h" #include "cv/video-property-page.hpp" #include "compat/camera-names.hpp" @@ -28,6 +27,7 @@ #include <QDebug> #include <vector> +#include <tuple> #include <cstdio> #include <cmath> #include <algorithm> @@ -134,35 +134,35 @@ bool aruco_tracker::detect_without_roi() return markers.size() == 1 && markers[0].size() == 4; } +static int enum_to_fps(int value) +{ + int fps; + + switch (value) + { + default: eval_once(qDebug() << "aruco: invalid fps enum value"); + [[fallthrough]]; + case fps_default: fps = 0; break; + case fps_30: fps = 30; break; + case fps_60: fps = 60; break; + case fps_75: fps = 75; break; + case fps_125: fps = 125; break; + case fps_200: fps = 200; break; + case fps_50: fps = 50; break; + case fps_100: fps = 100; break; + case fps_120: fps = 120; break; + } + + return fps; +} + bool aruco_tracker::open_camera() { int rint = s.resolution; if (rint < 0 || rint >= (int)(sizeof(resolution_choices) / sizeof(resolution_tuple))) rint = 0; resolution_tuple res = resolution_choices[rint]; - int fps; - switch (*s.force_fps) - { - default: - case 0: - fps = 0; - break; - case 1: - fps = 30; - break; - case 2: - fps = 60; - break; - case 3: - fps = 75; - break; - case 4: - fps = 125; - break; - case 5: - fps = 200; - break; - } + int fps = enum_to_fps(s.force_fps); QMutexLocker l(&camera_mtx); @@ -373,7 +373,10 @@ void aruco_tracker::run() QMutexLocker l(&camera_mtx); if (!camera.read(color)) + { + portable::sleep(100); continue; + } } cv::cvtColor(color, grayscale, cv::COLOR_BGR2GRAY); @@ -451,17 +454,52 @@ void aruco_tracker::data(double *data) data[TZ] = pose[TZ]; } +void aruco_dialog::make_fps_combobox() +{ + std::vector<std::tuple<int, int>> resolutions; + resolutions.reserve(fps_MAX); + + for (int k = 0; k < fps_MAX; k++) + { + int hz = enum_to_fps(k); + resolutions.emplace_back(k, hz); + } + + std::sort(resolutions.begin(), resolutions.end(), [](const auto& a, const auto& b) { + auto [idx1, hz1] = a; + auto [idx2, hz2] = b; + + return hz1 < hz2; + }); + + for (auto [idx, hz] : resolutions) + { + QString name; + + if (hz == 0) + name = tr("Default"); + else + name = QString::number(hz); + + ui.cameraFPS->addItem(name, idx); + } +} + aruco_dialog::aruco_dialog() : calibrator(1, 0) { + ui.setupUi(this); + //setAttribute(Qt::WA_NativeWindow, true); + + make_fps_combobox(); + tie_setting(s.force_fps, ui.cameraFPS); + tracker = nullptr; calib_timer.setInterval(100); - ui.setupUi(this); - setAttribute(Qt::WA_NativeWindow, true); ui.cameraName->addItems(get_camera_names()); + tie_setting(s.camera_name, ui.cameraName); tie_setting(s.resolution, ui.resolution); - tie_setting(s.force_fps, ui.cameraFPS); tie_setting(s.fov, ui.cameraFOV); tie_setting(s.headpos_x, ui.cx); tie_setting(s.headpos_y, ui.cy); @@ -546,4 +584,6 @@ void aruco_dialog::update_camera_settings_state(const QString& name) ui.camera_settings->setEnabled(true); } +settings::settings() : opts("aruco-tracker") {} + OPENTRACK_DECLARE_TRACKER(aruco_tracker, aruco_dialog, aruco_metadata) diff --git a/tracker-aruco/ftnoir_tracker_aruco.h b/tracker-aruco/ftnoir_tracker_aruco.h index 6c249c6a..1d6fd107 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.h +++ b/tracker-aruco/ftnoir_tracker_aruco.h @@ -37,34 +37,48 @@ using namespace options; -struct settings : opts { - value<QString> camera_name { b, "camera-name", ""}; - value<int> fov { b, "field-of-view", 56 }; +enum aruco_fps +{ + fps_default = 0, + fps_30 = 1, + fps_60 = 2, + fps_75 = 3, + fps_125 = 4, + fps_200 = 5, + fps_50 = 6, + fps_100 = 7, + fps_120 = 8, + fps_MAX = 9, +}; +struct settings : opts { value<double> headpos_x { b, "headpos-x", 0 }, headpos_y { b, "headpos-y", 0 }, headpos_z { b, "headpos-z", 0 }; - value<int> force_fps { b, "force-fps", 0 }, - resolution { b, "force-resolution", 0 }; + value<QString> camera_name { b, "camera-name", ""}; + value<int> resolution { b, "force-resolution", 0 }; + value<int> fov { b, "field-of-view", 56 }; + value<aruco_fps> force_fps { b, "force-fps", fps_default }; - settings() : opts("aruco-tracker") {} + settings(); }; -class aruco_dialog; - class aruco_tracker : protected virtual QThread, public ITracker { Q_OBJECT - friend class aruco_dialog; - static constexpr inline float c_search_window = 1.3f; + static constexpr float c_search_window = 1.3f; public: aruco_tracker(); ~aruco_tracker() override; module_status start_tracker(QFrame* frame) override; void data(double *data) override; void run() override; + void getRT(cv::Matx33d &r, cv::Vec3d &t); + QMutex camera_mtx; + cv::VideoCapture camera; + private: bool detect_with_roi(); bool detect_without_roi(); @@ -81,48 +95,46 @@ private: void set_detector_params(); void cycle_detection_params(); - cv::VideoCapture camera; - QMutex camera_mtx; QMutex mtx; std::unique_ptr<cv_video_widget> videoWidget; std::unique_ptr<QHBoxLayout> layout; settings s; double pose[6] {}, fps = 0; double no_detection_timeout = 0; - cv::Mat frame, grayscale, color; cv::Matx33d r; - std::vector<cv::Point3f> obj_points {4}; cv::Matx33d intrinsics = cv::Matx33d::eye(); - aruco::MarkerDetector detector; - std::vector<aruco::Marker> markers; cv::Vec3d t; cv::Vec3d rvec, tvec; - std::vector<cv::Point2f> roi_projection; - std::vector<cv::Point2f> repr2; cv::Matx33d m_r, m_q, rmat = cv::Matx33d::eye(); cv::Vec3d euler; std::vector<cv::Point3f> roi_points {4}; + std::vector<cv::Point2f> roi_projection; + std::vector<cv::Point2f> repr2; + std::vector<cv::Point3f> obj_points {4}; + aruco::MarkerDetector detector; + std::vector<aruco::Marker> markers; + cv::Mat frame, grayscale, color; cv::Rect last_roi { 65535, 65535, 0, 0 }; Timer fps_timer, last_detection_timer; unsigned adaptive_size_pos { 0 }; bool use_otsu = false; #if !defined USE_EXPERIMENTAL_CANNY - static constexpr inline int adaptive_thres = 6; + static constexpr int adaptive_thres = 6; #else - static constexpr inline int adaptive_thres = 3; + static constexpr int adaptive_thres = 3; #endif - static constexpr inline double timeout = .35; - static constexpr inline double timeout_backoff_c = .25; + static constexpr double timeout = .35; + static constexpr double timeout_backoff_c = .25; - static constexpr inline float size_min = 0.05; - static constexpr inline float size_max = 0.5; + static constexpr float size_min = 0.05f; + static constexpr float size_max = 0.5f; - static constexpr inline double RC = .25; + static constexpr double RC = .25; #ifdef DEBUG_UNSHARP_MASKING - static constexpr inline double gauss_kernel_size = 3; + static constexpr double gauss_kernel_size = 3; cv::Mat blurred; #endif }; @@ -135,6 +147,8 @@ public: void register_tracker(ITracker * x) override { tracker = static_cast<aruco_tracker*>(x); } void unregister_tracker() override { tracker = nullptr; } private: + void make_fps_combobox(); + Ui::Form ui; aruco_tracker* tracker; settings s; @@ -153,6 +167,6 @@ private Q_SLOTS: class aruco_metadata : public Metadata { Q_OBJECT - QString name() { return QString("aruco -- paper marker tracker"); } - QIcon icon() { return QIcon(":/images/aruco.png"); } + QString name() override { return QString("aruco -- paper marker tracker"); } + QIcon icon() override { return QIcon(":/images/aruco.png"); } }; diff --git a/tracker-aruco/lang/nl_NL.ts b/tracker-aruco/lang/nl_NL.ts index a4136086..87040565 100644 --- a/tracker-aruco/lang/nl_NL.ts +++ b/tracker-aruco/lang/nl_NL.ts @@ -36,30 +36,6 @@ <translation><html><head/><body><p>Lees de <a href="https://github.com/opentrack/opentrack/wiki/Aruco-tracker"><span style=" text-decoration: underline; color:#0000ff;">wiki-pagina</span></a> en voornamelijk de laatste paragraaf voordat u de markering uitprint.</p></body></html></translation> </message> <message> - <source>Default</source> - <translation>Standaard</translation> - </message> - <message> - <source>30</source> - <translation>30</translation> - </message> - <message> - <source>60</source> - <translation>30</translation> - </message> - <message> - <source>75</source> - <translation>75</translation> - </message> - <message> - <source>125</source> - <translation>125</translation> - </message> - <message> - <source>200</source> - <translation>200</translation> - </message> - <message> <source>Default (not recommended!)</source> <translation>Standaard (niet aanbevolen)</translation> </message> @@ -84,4 +60,11 @@ <translation>Schakel tussen kalibratie</translation> </message> </context> +<context> + <name>aruco_dialog</name> + <message> + <source>Default</source> + <translation type="unfinished">Standaard</translation> + </message> +</context> </TS> diff --git a/tracker-aruco/lang/ru_RU.ts b/tracker-aruco/lang/ru_RU.ts index f2088d1d..57c8170d 100644 --- a/tracker-aruco/lang/ru_RU.ts +++ b/tracker-aruco/lang/ru_RU.ts @@ -16,30 +16,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>Default</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>30</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>60</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>75</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>125</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>200</source> - <translation type="unfinished"></translation> - </message> - <message> <source>640x480</source> <translation type="unfinished"></translation> </message> @@ -84,4 +60,11 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>aruco_dialog</name> + <message> + <source>Default</source> + <translation type="unfinished"></translation> + </message> +</context> </TS> diff --git a/tracker-aruco/lang/stub.ts b/tracker-aruco/lang/stub.ts index aadcbd03..67cb36b8 100644 --- a/tracker-aruco/lang/stub.ts +++ b/tracker-aruco/lang/stub.ts @@ -16,30 +16,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>Default</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>30</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>60</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>75</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>125</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>200</source> - <translation type="unfinished"></translation> - </message> - <message> <source>640x480</source> <translation type="unfinished"></translation> </message> @@ -84,4 +60,11 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>aruco_dialog</name> + <message> + <source>Default</source> + <translation type="unfinished"></translation> + </message> +</context> </TS> diff --git a/tracker-aruco/lang/zh_CN.ts b/tracker-aruco/lang/zh_CN.ts index 2f497e98..b5093b4e 100644 --- a/tracker-aruco/lang/zh_CN.ts +++ b/tracker-aruco/lang/zh_CN.ts @@ -28,30 +28,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>Default</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>30</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>60</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>75</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>125</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>200</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Camera name</source> <translation type="unfinished"></translation> </message> @@ -84,4 +60,11 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>aruco_dialog</name> + <message> + <source>Default</source> + <translation type="unfinished"></translation> + </message> +</context> </TS> |