diff options
Diffstat (limited to 'tracker-aruco')
-rw-r--r-- | tracker-aruco/ftnoir_tracker_aruco.cpp | 2 | ||||
-rw-r--r-- | tracker-aruco/ftnoir_tracker_aruco.h | 15 | ||||
-rw-r--r-- | tracker-aruco/pt_video_widget.cpp | 71 | ||||
-rw-r--r-- | tracker-aruco/pt_video_widget.h | 39 | ||||
-rw-r--r-- | tracker-aruco/trans_calib.cpp | 41 | ||||
-rw-r--r-- | tracker-aruco/trans_calib.h | 36 |
6 files changed, 9 insertions, 195 deletions
diff --git a/tracker-aruco/ftnoir_tracker_aruco.cpp b/tracker-aruco/ftnoir_tracker_aruco.cpp index d17ba599..02ca9920 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.cpp +++ b/tracker-aruco/ftnoir_tracker_aruco.cpp @@ -73,7 +73,7 @@ Tracker::~Tracker() void Tracker::start_tracker(QFrame* videoframe) { videoframe->show(); - videoWidget = new PTVideoWidget(videoframe); + videoWidget = new cv_video_widget(videoframe); QHBoxLayout* layout_ = new QHBoxLayout(); layout_->setContentsMargins(0, 0, 0, 0); layout_->addWidget(videoWidget); diff --git a/tracker-aruco/ftnoir_tracker_aruco.h b/tracker-aruco/ftnoir_tracker_aruco.h index f89f3fdc..6c28c7db 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.h +++ b/tracker-aruco/ftnoir_tracker_aruco.h @@ -8,13 +8,15 @@ #pragma once #include "ui_aruco-trackercontrols.h" -#include "pt_video_widget.h" -#include "opentrack-compat/options.hpp" -#include "trans_calib.h" #include "opentrack/plugin-api.hpp" -#include "cv/camera-dialog.hpp" #include "include/markerdetector.h" +#include "cv/camera-dialog.hpp" +#include "cv/video-widget.hpp" +#include "cv/translation-calibrator.hpp" + +#include <opencv2/core/core.hpp> + #include <QObject> #include <QThread> #include <QMutex> @@ -24,8 +26,7 @@ #include <cinttypes> -#include <opencv2/core/core.hpp> - +#include "opentrack-compat/options.hpp" using namespace options; struct settings : opts { @@ -78,7 +79,7 @@ private: QMutex mtx; volatile bool stop; QHBoxLayout* layout; - PTVideoWidget* videoWidget; + cv_video_widget* videoWidget; settings s; double pose[6]; cv::Mat frame, grayscale, color; diff --git a/tracker-aruco/pt_video_widget.cpp b/tracker-aruco/pt_video_widget.cpp deleted file mode 100644 index 54bc9acd..00000000 --- a/tracker-aruco/pt_video_widget.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * Copyright (c) 2014-2016 Stanislaw Halik <sthalik@misaki.pl> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ - -#include "pt_video_widget.h" -#include <opencv2/imgproc.hpp> - -#include "opentrack/is-window-visible.hpp" - -PTVideoWidget::PTVideoWidget(QWidget* parent) : - QWidget(parent), - freshp(false), - visible(true) -{ - connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint())); - timer.start(50); -} - -void PTVideoWidget::update_image(const cv::Mat& frame) -{ - QMutexLocker foo(&mtx); - - if (!freshp) - { - if (_frame.cols != frame.cols || _frame.rows != frame.rows) - { - _frame = cv::Mat(frame.rows, frame.cols, CV_8U); - _frame2 = cv::Mat(frame.rows, frame.cols, CV_8U); - } - frame.copyTo(_frame); - freshp = true; - } -} - -void PTVideoWidget::paintEvent(QPaintEvent*) -{ - QMutexLocker foo(&mtx); - QPainter painter(this); - painter.drawImage(rect(), texture); -} - -void PTVideoWidget::update_and_repaint() -{ - QMutexLocker l(&mtx); - - if (window_check_timer.elapsed_ms() > 250) - { - visible = is_window_visible(this); - window_check_timer.start(); - } - - if (visible) - { - if (_frame.empty() || !freshp) - return; - cv::cvtColor(_frame, _frame2, cv::COLOR_RGB2BGR); - - if (_frame3.cols != width() || _frame3.rows != height()) - _frame3 = cv::Mat(height(), width(), CV_8U); - - cv::resize(_frame2, _frame3, cv::Size(width(), height()), 0, 0, cv::INTER_NEAREST); - - texture = QImage((const unsigned char*) _frame3.data, _frame3.cols, _frame3.rows, QImage::Format_RGB888); - freshp = false; - update(); - } -} diff --git a/tracker-aruco/pt_video_widget.h b/tracker-aruco/pt_video_widget.h deleted file mode 100644 index 82de3eab..00000000 --- a/tracker-aruco/pt_video_widget.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * Copyright (c) 2014-2016 Stanislaw Halik <sthalik@misaki.pl> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ - -#pragma once - -#include "opentrack-compat/timer.hpp" -#include <opencv2/core/core.hpp> -#include <memory> -#include <QObject> -#include <QWidget> -#include <QPainter> -#include <QPaintEvent> -#include <QTimer> -#include <QMutex> -#include <QMutexLocker> -#include <QDebug> - -class PTVideoWidget final : public QWidget -{ - Q_OBJECT -public: - PTVideoWidget(QWidget *parent); - void update_image(const cv::Mat &frame); -protected slots: - void paintEvent(QPaintEvent*) override; - void update_and_repaint(); -private: - QMutex mtx; - QImage texture; - QTimer timer; - Timer window_check_timer; - cv::Mat _frame, _frame2, _frame3; - bool freshp, visible; -}; diff --git a/tracker-aruco/trans_calib.cpp b/tracker-aruco/trans_calib.cpp deleted file mode 100644 index b5148efd..00000000 --- a/tracker-aruco/trans_calib.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ - -#include "trans_calib.h" - -TranslationCalibrator::TranslationCalibrator() -{ - reset(); -} - -void TranslationCalibrator::reset() -{ - P = cv::Matx66f::zeros(); - y = cv::Vec6f(0,0,0, 0,0,0); -} - -void TranslationCalibrator::update(const cv::Matx33d& R_CM_k, const cv::Vec3d& t_CM_k) -{ - cv::Matx<double, 6,3> H_k_T = cv::Matx<double, 6,3>::zeros(); - for (int i=0; i<3; ++i) { - for (int j=0; j<3; ++j) { - H_k_T(i,j) = R_CM_k(j,i); - } - } - for (int i=0; i<3; ++i) - { - H_k_T(3+i,i) = 1.0; - } - P += H_k_T * H_k_T.t(); - y += H_k_T * t_CM_k; -} - -cv::Vec3f TranslationCalibrator::get_estimate() -{ - cv::Vec6f x = P.inv() * y; - return cv::Vec3f(x[0], x[1], x[2]); -} diff --git a/tracker-aruco/trans_calib.h b/tracker-aruco/trans_calib.h deleted file mode 100644 index cfde0051..00000000 --- a/tracker-aruco/trans_calib.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ - -#pragma once - -#include <opencv2/core/core.hpp> - -//----------------------------------------------------------------------------- -// Calibrates the translation from head to model = t_MH -// by recursive least squares / -// kalman filter in information form with identity noise covariance -// measurement equation when head position = t_CH is fixed: -// (R_CM_k , Id)*(-t_MH, t_CH) = t_CM_k - -class TranslationCalibrator -{ -public: - TranslationCalibrator(); - - // reset the calibration process - void reset(); - - // update the current estimate - void update(const cv::Matx33d& R_CM_k, const cv::Vec3d& t_CM_k); - - // get the current estimate for t_MH - cv::Vec3f get_estimate(); - -private: - cv::Matx66f P; // normalized precision matrix = inverse covariance - cv::Vec6f y; // P*(-t_MH, t_CH) -}; |