diff options
author | Stéphane Lenclud <github@lenclud.com> | 2019-03-10 17:10:02 +0100 |
---|---|---|
committer | Stéphane Lenclud <github@lenclud.com> | 2019-03-10 17:10:02 +0100 |
commit | 8a9d143523fddbf8ee9cb1c58cb281ac380d3ae0 (patch) | |
tree | ae5cabae1134456eff8260ff6e7c30639c9ef42c | |
parent | c90f8fbd1a83ffeed6b0bb9d55e91f4a4a9b8641 (diff) |
Kinect Point Tracker: Working on basic architecture.
-rw-r--r-- | compat/camera-names.cpp | 15 | ||||
-rw-r--r-- | compat/camera-names.hpp | 5 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.cpp | 40 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.h | 13 | ||||
-rw-r--r-- | tracker-pt/module/camera.cpp | 6 | ||||
-rw-r--r-- | tracker-pt/module/camera.h | 3 | ||||
-rw-r--r-- | tracker-pt/module/module.cpp | 17 | ||||
-rw-r--r-- | tracker-pt/module/point_extractor.cpp | 9 | ||||
-rw-r--r-- | tracker-pt/pt-api.hpp | 5 | ||||
-rw-r--r-- | tracker-wii/wii_module.cpp | 9 |
10 files changed, 106 insertions, 16 deletions
diff --git a/compat/camera-names.cpp b/compat/camera-names.cpp index 246d76ee..c30e4b33 100644 --- a/compat/camera-names.cpp +++ b/compat/camera-names.cpp @@ -49,6 +49,7 @@ QList<QString> get_camera_names() // Enumerate the monikers. IMoniker *pMoniker = nullptr; ULONG cFetched; + bool hasKinect = true; while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) { IPropertyBag *pPropBag; @@ -63,12 +64,26 @@ QList<QString> get_camera_names() // Display the name in your UI somehow. QString str((QChar*)var.bstrVal, int(std::wcslen(var.bstrVal))); ret.append(str); + if (!hasKinect && str.compare(KKinectVideoSensor)==0) + { + // We do have a Kinect V2 connected + hasKinect = true; + } } VariantClear(&var); pPropBag->Release(); } pMoniker->Release(); } + + if (hasKinect) + { + // Add Kinect V2 IR Sensor as an option then + ret.append(QString(KKinectIRSensor)); + // We made sure that extra camera is added at the end of our array so as not to mess up genuine camera indices... + // ...which we relly on to create our OpenCV VideoCapture object in Camera::start. + } + pEnumCat->Release(); } else diff --git a/compat/camera-names.hpp b/compat/camera-names.hpp index 97184c8c..4d9b023c 100644 --- a/compat/camera-names.hpp +++ b/compat/camera-names.hpp @@ -13,6 +13,11 @@ #include "export.hpp" +// Hard coding name of standard Kinect camera as returned from Windows API as used in ::get_camera_names +static const char KKinectVideoSensor[] = "Kinect V2 Video Sensor"; +// Defining camera name for Kinect IR Sensor +static const char KKinectIRSensor[] = "Kinect V2 IR Sensor"; + OTR_COMPAT_EXPORT QList<QString> get_camera_names(); OTR_COMPAT_EXPORT int camera_name_to_index(const QString &name); diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index 3854e531..1f4afe46 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -22,14 +22,29 @@ using namespace options; namespace pt_impl { +/// @deprecated Consider removing it Tracker_PT::Tracker_PT(pointer<pt_runtime_traits> const& traits) : - traits { traits }, - s { traits->get_module_name() }, - point_extractor { traits->make_point_extractor() }, - camera { traits->make_camera() }, - frame { traits->make_frame() }, - preview_frame { traits->make_preview(preview_width, preview_height) } + s { traits->get_module_name() } { + init(traits); +} + +Tracker_PT::Tracker_PT(const QString& aModuleName) : + traits{ nullptr}, + s { aModuleName } +{ + +} + +void Tracker_PT::init(pointer<pt_runtime_traits> const& aTraits) +{ + traits = aTraits; + + point_extractor = traits->make_point_extractor(); + camera = traits->make_camera(); + frame = traits->make_frame(); + preview_frame = traits->make_preview(preview_width, preview_height); + cv::setBreakOnError(true); cv::setNumThreads(1); @@ -40,6 +55,7 @@ Tracker_PT::Tracker_PT(pointer<pt_runtime_traits> const& traits) : set_fov(s.fov); } + Tracker_PT::~Tracker_PT() { requestInterruption(); @@ -132,9 +148,17 @@ void Tracker_PT::set_fov(int value) } module_status Tracker_PT::start_tracker(QFrame* video_frame) -{ - //video_frame->setAttribute(Qt::WA_NativeWindow); +{ + if (traits == nullptr) + { + // Create traits according to settings + traits = create_traits(); + init(traits); + } + + //video_frame->setAttribute(Qt::WA_NativeWindow); + widget = std::make_unique<video_widget>(video_frame); layout = std::make_unique<QHBoxLayout>(video_frame); layout->setContentsMargins(0, 0, 0, 0); diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h index 210c6a01..37f5bfef 100644 --- a/tracker-pt/ftnoir_tracker_pt.h +++ b/tracker-pt/ftnoir_tracker_pt.h @@ -36,8 +36,14 @@ struct Tracker_PT : QThread, ITracker template<typename t> using pointer = pt_pointer<t>; + /// @deprecated Consider removing it explicit Tracker_PT(pointer<pt_runtime_traits> const& pt_runtime_traits); + Tracker_PT(const QString& aModuleName); ~Tracker_PT() override; + + void init(pointer<pt_runtime_traits> const& traits); + virtual pointer<pt_runtime_traits> create_traits()=0; + module_status start_tracker(QFrame* parent_window) override; void data(double* data) override; bool center() override; @@ -46,6 +52,9 @@ struct Tracker_PT : QThread, ITracker [[nodiscard]] bool get_cam_info(pt_camera_info& info); Affine pose() const; +protected: + pt_settings s; + private: void run() override; @@ -56,9 +65,7 @@ private: QMutex camera_mtx; - PointTracker point_tracker; - - pt_settings s; + PointTracker point_tracker; std::unique_ptr<QLayout> layout; std::vector<vec2> points; diff --git a/tracker-pt/module/camera.cpp b/tracker-pt/module/camera.cpp index 1afecc92..816f5baf 100644 --- a/tracker-pt/module/camera.cpp +++ b/tracker-pt/module/camera.cpp @@ -85,6 +85,7 @@ Camera::result Camera::get_frame(pt_frame& frame_) bool Camera::start(int idx, int fps, int res_x, int res_y) { + if (idx >= 0 && fps >= 0 && res_x >= 0 && res_y >= 0) { if (cam_desired.idx != idx || @@ -96,6 +97,11 @@ bool Camera::start(int idx, int fps, int res_x, int res_y) stop(); desired_name = get_camera_names().value(idx); + bool kinectIRSensor = false; + if (desired_name.compare(KKinectIRSensor) == 0) + { + kinectIRSensor = true; + } cam_desired.idx = idx; cam_desired.fps = fps; cam_desired.res_x = res_x; diff --git a/tracker-pt/module/camera.h b/tracker-pt/module/camera.h index 2ea633d0..644eead7 100644 --- a/tracker-pt/module/camera.h +++ b/tracker-pt/module/camera.h @@ -19,6 +19,9 @@ namespace pt_module { +/// +/// Implement our camera interface using OpenCV VideoCapture. +/// struct Camera final : pt_camera { Camera(const QString& module_name); diff --git a/tracker-pt/module/module.cpp b/tracker-pt/module/module.cpp index f665face..db3e8fac 100644 --- a/tracker-pt/module/module.cpp +++ b/tracker-pt/module/module.cpp @@ -2,6 +2,7 @@ #include "module.hpp" #include "camera.h" +#include "compat/camera-names.hpp" #include "frame.hpp" #include "point_extractor.h" #include "ftnoir_tracker_pt_dialog.h" @@ -18,6 +19,7 @@ static const QString module_name = "tracker-pt"; namespace pt_module { +// Traits for OpenCV VideoCapture camera struct pt_module_traits final : pt_runtime_traits { pointer<pt_camera> make_camera() const override @@ -48,9 +50,22 @@ struct pt_module_traits final : pt_runtime_traits struct tracker_pt : Tracker_PT { - tracker_pt() : Tracker_PT(pointer<pt_runtime_traits>(new pt_module_traits)) + tracker_pt() : Tracker_PT(module_name) { } + + pointer<pt_runtime_traits> create_traits() override + { + // Create different traits according to settings + if (s.camera_name().compare(KKinectIRSensor) == 0) + { + // Use Kinect IR trait + return pointer<pt_runtime_traits>(new pt_module_traits); + } + + return pointer<pt_runtime_traits>(new pt_module_traits); + } + }; struct dialog_pt : TrackerDialog_PT diff --git a/tracker-pt/module/point_extractor.cpp b/tracker-pt/module/point_extractor.cpp index 298d8752..049f4acd 100644 --- a/tracker-pt/module/point_extractor.cpp +++ b/tracker-pt/module/point_extractor.cpp @@ -235,9 +235,12 @@ static void draw_blobs(cv::Mat& preview_frame, const blob* blobs, unsigned nblob : cv::Scalar(0, 0, 255); cv::Point pos(iround(b.pos[0]*cx+offx), iround(b.pos[1]*cy+offy)); - cv::putText(preview_frame, buf, pos, - cv::FONT_HERSHEY_PLAIN, overlay_size, text_color, - 1); + + // That crashes in debug x64 on my dev machine when using Kinect V2 Video Sensor + // Seems to work fine with official beta 3 though + //cv::putText(preview_frame, buf, pos, + // cv::FONT_HERSHEY_PLAIN, overlay_size, text_color, + // 1); } } diff --git a/tracker-pt/pt-api.hpp b/tracker-pt/pt-api.hpp index b44cfea2..a7fc464b 100644 --- a/tracker-pt/pt-api.hpp +++ b/tracker-pt/pt-api.hpp @@ -66,6 +66,11 @@ struct pt_preview : pt_frame virtual void draw_head_center(f x, f y) = 0; }; +/// +/// Defines a camera interface. +/// A camera can be started and stopped. +/// Once started one can obtain frames through this interface. +/// struct pt_camera { using result = std::tuple<bool, pt_camera_info>; diff --git a/tracker-wii/wii_module.cpp b/tracker-wii/wii_module.cpp index c4884f22..57e7cd6d 100644 --- a/tracker-wii/wii_module.cpp +++ b/tracker-wii/wii_module.cpp @@ -57,9 +57,16 @@ struct wii_pt_module_traits final : pt_runtime_traits struct wii_tracker_pt : Tracker_PT { - wii_tracker_pt() : Tracker_PT(pointer<pt_runtime_traits>(new wii_pt_module_traits)) + wii_tracker_pt() : Tracker_PT(module_name) { + + } + + pointer<pt_runtime_traits> create_traits() override + { + return pointer<pt_runtime_traits>(new wii_pt_module_traits); } + }; |