diff options
Diffstat (limited to 'tracker-aruco/ftnoir_tracker_aruco.h')
-rw-r--r-- | tracker-aruco/ftnoir_tracker_aruco.h | 156 |
1 files changed, 72 insertions, 84 deletions
diff --git a/tracker-aruco/ftnoir_tracker_aruco.h b/tracker-aruco/ftnoir_tracker_aruco.h index 02b7e0a7..839be6d5 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.h +++ b/tracker-aruco/ftnoir_tracker_aruco.h @@ -13,8 +13,9 @@ #include "api/plugin-api.hpp" #include "cv/video-widget.hpp" #include "compat/timer.hpp" +#include "video/camera.hpp" -#include "include/markerdetector.h" +#include "aruco/markerdetector.h" #include <QObject> #include <QThread> @@ -23,56 +24,64 @@ #include <QDialog> #include <QTimer> +#include <memory> #include <cinttypes> #include <opencv2/core.hpp> -#include <opencv2/videoio.hpp> // value 0->1 //#define DEBUG_UNSHARP_MASKING .75 +//canny thresholding +//#define USE_EXPERIMENTAL_CANNY + using namespace options; -struct settings : opts { - enum rot - { - rot_zero = 0, - rot_neg = -1, - rot_plus = +1, - }; - - value<int> fov; - value<double> headpos_x, headpos_y, headpos_z; - value<QString> camera_name; - value<int> force_fps, resolution; - value<rot> model_rotation; - settings() : - opts("aruco-tracker"), - fov(b, "field-of-view", 56), - headpos_x(b, "headpos-x", 0), - headpos_y(b, "headpos-y", 0), - headpos_z(b, "headpos-z", 0), - camera_name(b, "camera-name", ""), - force_fps(b, "force-fps", 0), - resolution(b, "force-resolution", 0), - model_rotation(b, "model-rotation", rot_zero) - {} +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_300 = 9, + fps_250 = 10, + fps_MAX = 11, }; -class aruco_dialog; +struct settings : opts { + value<double> headpos_x { b, "headpos-x", 0 }, + headpos_y { b, "headpos-y", 0 }, + headpos_z { b, "headpos-z", 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 }; + value<bool> use_mjpeg { b, "use-mjpeg", false }; + + settings(); +}; -class aruco_tracker : protected QThread, public ITracker +class aruco_tracker : protected virtual QThread, public ITracker { Q_OBJECT - friend class aruco_dialog; static constexpr float c_search_window = 1.3f; public: aruco_tracker(); ~aruco_tracker() override; - void start_tracker(QFrame* frame) 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; + std::unique_ptr<video::impl::camera> camera; + private: bool detect_with_roi(); bool detect_without_roi(); @@ -89,72 +98,48 @@ private: void set_detector_params(); void cycle_detection_params(); - cv::Point3f rotate_model(float x, float y, settings::rot mode); - - cv::VideoCapture camera; - QMutex camera_mtx; QMutex mtx; - qshared<cv_video_widget> videoWidget; - qshared<QHBoxLayout> layout; + std::unique_ptr<cv_video_widget> videoWidget; + std::unique_ptr<QHBoxLayout> layout; settings s; - double pose[6], fps, no_detection_timeout; - cv::Mat frame, grayscale, color; + double pose[6] {}, fps = 0; + double no_detection_timeout = 0; cv::Matx33d r; -#ifdef DEBUG_UNSHARP_MASKING - cv::Mat blurred; -#endif - std::vector<cv::Point3f> obj_points; - cv::Matx33d intrinsics; - aruco::MarkerDetector detector; - std::vector<aruco::Marker> markers; + cv::Matx33d intrinsics = cv::Matx33d::eye(); cv::Vec3d t; cv::Vec3d rvec, tvec; + 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; - cv::Matx33d m_r, m_q, rmat; - cv::Vec3d euler; - std::vector<cv::Point3f> roi_points; - cv::Rect last_roi; + 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; - volatile bool stop; - bool use_otsu; - - struct resolution_tuple - { - int width; - int height; - }; - - static constexpr const int adaptive_sizes[] = - { - 7, - 9, - //11, - 13, - //5, - }; + unsigned adaptive_size_pos { 0 }; + bool use_otsu = false; +#if !defined USE_EXPERIMENTAL_CANNY static constexpr int adaptive_thres = 6; +#else + static constexpr int adaptive_thres = 3; +#endif - static constexpr const resolution_tuple resolution_choices[] = - { - { 640, 480 }, - { 320, 240 }, - { 0, 0 } - }; + static constexpr double timeout = .35; + static constexpr double timeout_backoff_c = .25; + + static constexpr float size_min = 0.05f; + static constexpr float size_max = 0.5f; + + static constexpr double RC = .25; #ifdef DEBUG_UNSHARP_MASKING static constexpr double gauss_kernel_size = 3; + cv::Mat blurred; #endif - - static constexpr double timeout = 1; - static constexpr double timeout_backoff_c = 4./11; - - static constexpr const float size_min = 0.05; - static constexpr const float size_max = 0.5; - - static constexpr const double RC = .25; }; class aruco_dialog : public ITrackerDialog @@ -165,12 +150,14 @@ 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; TranslationCalibrator calibrator; QTimer calib_timer; -private slots: +private Q_SLOTS: void doOK(); void doCancel(); void toggleCalibrate(); @@ -182,6 +169,7 @@ private slots: class aruco_metadata : public Metadata { - QString name() { return QString("aruco -- paper marker tracker"); } - QIcon icon() { return QIcon(":/images/aruco.png"); } + Q_OBJECT + QString name() override { return QString("aruco -- paper marker tracker"); } + QIcon icon() override { return QIcon(":/images/aruco.png"); } }; |