diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-11-11 18:10:42 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-11-12 12:04:27 +0100 |
commit | e5d2902e11ae6ea2e26e0caa6588384225e018f6 (patch) | |
tree | 6b9660910daf250290c339780d5b2ef062646130 | |
parent | 049044f181414991a103ace961214c78171c284d (diff) |
tracker/pt: refactor
- separate .{cpp,hpp} for few classes
- don't include namespaces globally; harmless but looks bad
anyway
- class with all public members to struct
-rw-r--r-- | tracker-pt/affine.cpp | 32 | ||||
-rw-r--r-- | tracker-pt/affine.hpp | 29 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.h | 17 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt_settings.cpp | 4 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt_settings.h | 23 | ||||
-rw-r--r-- | tracker-pt/numeric.hpp | 22 | ||||
-rw-r--r-- | tracker-pt/point_extractor.cpp | 6 | ||||
-rw-r--r-- | tracker-pt/point_extractor.h | 13 | ||||
-rw-r--r-- | tracker-pt/point_tracker.cpp | 7 | ||||
-rw-r--r-- | tracker-pt/point_tracker.h | 46 |
10 files changed, 125 insertions, 74 deletions
diff --git a/tracker-pt/affine.cpp b/tracker-pt/affine.cpp new file mode 100644 index 00000000..9018e107 --- /dev/null +++ b/tracker-pt/affine.cpp @@ -0,0 +1,32 @@ +/* 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 "affine.hpp" + +Affine::Affine() : R(mat33::eye()), t(0,0,0) {} + +Affine::Affine(const mat33& R, const vec3& t) : R(R),t(t) {} + +Affine operator*(const Affine& X, const Affine& Y) +{ + return Affine(X.R*Y.R, X.R*Y.t + X.t); +} + +Affine operator*(const mat33& X, const Affine& Y) +{ + return Affine(X*Y.R, X*Y.t); +} + +Affine operator*(const Affine& X, const mat33& Y) +{ + return Affine(X.R*Y, X.t); +} + +vec3 operator*(const Affine& X, const vec3& v) +{ + return X.R*v + X.t; +} diff --git a/tracker-pt/affine.hpp b/tracker-pt/affine.hpp new file mode 100644 index 00000000..aedb0bc8 --- /dev/null +++ b/tracker-pt/affine.hpp @@ -0,0 +1,29 @@ +/* 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.hpp> +#include "numeric.hpp" +using namespace types; + + + +class Affine final +{ +public: + Affine(); + Affine(const mat33& R, const vec3& t); + + mat33 R; + vec3 t; +}; + +Affine operator*(const Affine& X, const Affine& Y); +Affine operator*(const mat33& X, const Affine& Y); +Affine operator*(const Affine& X, const mat33& Y); +vec3 operator*(const Affine& X, const vec3& v); diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h index 3b93eaf4..020694ae 100644 --- a/tracker-pt/ftnoir_tracker_pt.h +++ b/tracker-pt/ftnoir_tracker_pt.h @@ -6,12 +6,12 @@ * copyright notice and this permission notice appear in all copies. */ -#ifndef FTNOIR_TRACKER_PT_H -#define FTNOIR_TRACKER_PT_H +#pragma once #include "api/plugin-api.hpp" #include "ftnoir_tracker_pt_settings.h" -using namespace pt_types; + +#include "numeric.hpp" #include "camera.h" #include "point_extractor.h" @@ -28,10 +28,12 @@ using namespace pt_types; #include <memory> #include <vector> +namespace impl { + +using namespace types; + class TrackerDialog_PT; -//----------------------------------------------------------------------------- -// Constantly processes the tracking chain in a separate thread class Tracker_PT : public QThread, public ITracker { Q_OBJECT @@ -83,10 +85,13 @@ private: //static constexpr float deg2rad = float(M_PI/180); }; +} // ns impl + class PT_metadata : public Metadata { QString name() { return QString(QCoreApplication::translate("PT_metadata", "PointTracker 1.1")); } QIcon icon() { return QIcon(":/Resources/Logo_IR.png"); } }; -#endif // FTNOIR_TRACKER_PT_H +using impl::Tracker_PT; +using impl::TrackerDialog_PT; diff --git a/tracker-pt/ftnoir_tracker_pt_settings.cpp b/tracker-pt/ftnoir_tracker_pt_settings.cpp index 5d4b598f..8a5257d3 100644 --- a/tracker-pt/ftnoir_tracker_pt_settings.cpp +++ b/tracker-pt/ftnoir_tracker_pt_settings.cpp @@ -1,6 +1,6 @@ -#include "ftnoir_tracker_pt_settings.h" +#include "numeric.hpp" -namespace pt_types { +namespace types { constexpr f constants::eps; diff --git a/tracker-pt/ftnoir_tracker_pt_settings.h b/tracker-pt/ftnoir_tracker_pt_settings.h index e742fbbc..85f4ea68 100644 --- a/tracker-pt/ftnoir_tracker_pt_settings.h +++ b/tracker-pt/ftnoir_tracker_pt_settings.h @@ -8,29 +8,6 @@ #pragma once -#include <limits> -#include <opencv2/core.hpp> - -#include <cmath> - -namespace pt_types { - using f = double; - - struct constants final - { - constants() = delete; - static constexpr f eps = std::numeric_limits<f>::epsilon(); - }; - - template<int n> using vec = cv::Vec<f, n>; - using vec2 = vec<2>; - using vec3 = vec<3>; - - template<int y, int x> using mat = cv::Matx<f, y, x>; - using mat33 = mat<3, 3>; - using mat22 = mat<2, 2>; -} - #include "options/options.hpp" using namespace options; diff --git a/tracker-pt/numeric.hpp b/tracker-pt/numeric.hpp new file mode 100644 index 00000000..9d37086d --- /dev/null +++ b/tracker-pt/numeric.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include <opencv2/core.hpp> +#include <limits> + +namespace types { + using f = double; + + struct constants final + { + constants() = delete; + static constexpr f eps = std::numeric_limits<f>::epsilon(); + }; + + template<int n> using vec = cv::Vec<f, n>; + using vec2 = vec<2>; + using vec3 = vec<3>; + + template<int y, int x> using mat = cv::Matx<f, y, x>; + using mat33 = mat<3, 3>; + using mat22 = mat<2, 2>; +} diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp index 3b75cb1a..a9f431d9 100644 --- a/tracker-pt/point_extractor.cpp +++ b/tracker-pt/point_extractor.cpp @@ -7,8 +7,6 @@ */ #include "point_extractor.h" -#include <QDebug> - #include "compat/util.hpp" #include <opencv2/videoio.hpp> @@ -17,6 +15,10 @@ #include <algorithm> #include <cinttypes> +#include <QDebug> + +using namespace types; + PointExtractor::PointExtractor() { blobs.reserve(max_blobs); diff --git a/tracker-pt/point_extractor.h b/tracker-pt/point_extractor.h index a0afa45d..775e4292 100644 --- a/tracker-pt/point_extractor.h +++ b/tracker-pt/point_extractor.h @@ -8,14 +8,17 @@ #pragma once +#include "ftnoir_tracker_pt_settings.h" +#include "numeric.hpp" + #include <opencv2/core.hpp> #include <opencv2/imgproc.hpp> -#include "ftnoir_tracker_pt_settings.h" - #include <vector> -using namespace pt_types; +namespace impl { + +using namespace types; class PointExtractor final { @@ -47,3 +50,7 @@ private: std::vector<blob> blobs; }; + +} // ns impl + +using impl::PointExtractor; diff --git a/tracker-pt/point_tracker.cpp b/tracker-pt/point_tracker.cpp index 990ec512..7c0367d0 100644 --- a/tracker-pt/point_tracker.cpp +++ b/tracker-pt/point_tracker.cpp @@ -6,12 +6,10 @@ */ #include "point_tracker.h" - -#include "ftnoir_tracker_pt_settings.h" -using namespace pt_types; - #include "compat/nan.hpp" +using namespace types; + #include <vector> #include <algorithm> #include <cmath> @@ -353,3 +351,4 @@ vec2 PointTracker::project(const vec3& v_M, f focal_length, const Affine& X_CM) vec3 v_C = X_CM * v_M; return vec2(focal_length*v_C[0]/v_C[2], focal_length*v_C[1]/v_C[2]); } + diff --git a/tracker-pt/point_tracker.h b/tracker-pt/point_tracker.h index 79344076..0bac05ab 100644 --- a/tracker-pt/point_tracker.h +++ b/tracker-pt/point_tracker.h @@ -8,9 +8,9 @@ #pragma once #include "compat/timer.hpp" - #include "ftnoir_tracker_pt_settings.h" -using namespace pt_types; +#include "affine.hpp" +#include "numeric.hpp" #include <opencv2/core.hpp> #include <cstddef> @@ -19,44 +19,17 @@ using namespace pt_types; #include <array> #include <QObject> -class Affine final -{ -public: - Affine() : R(mat33::eye()), t(0,0,0) {} - Affine(const mat33& R, const vec3& t) : R(R),t(t) {} - - mat33 R; - vec3 t; -}; - -inline Affine operator*(const Affine& X, const Affine& Y) -{ - return Affine(X.R*Y.R, X.R*Y.t + X.t); -} - -inline Affine operator*(const mat33& X, const Affine& Y) -{ - return Affine(X*Y.R, X*Y.t); -} - -inline Affine operator*(const Affine& X, const mat33& Y) -{ - return Affine(X.R*Y, X.t); -} - -inline vec3 operator*(const Affine& X, const vec3& v) -{ - return X.R*v + X.t; -} +namespace impl { // ---------------------------------------------------------------------------- // Describes a 3-point model // nomenclature as in // [Denis Oberkampf, Daniel F. DeMenthon, Larry S. Davis: "Iterative Pose Estimation Using Coplanar Feature Points"] -class PointModel final + +using namespace types; + +struct PointModel final { - friend class PointTracker; -public: static constexpr unsigned N_POINTS = 3; vec3 M01; // M01 in model frame @@ -102,3 +75,8 @@ private: Timer t; bool init_phase; }; + +} // ns types + +using impl::PointTracker; +using impl::PointModel; |