diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-02-16 11:07:57 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-02-16 12:55:48 +0100 |
commit | e42a0361c986c39a9456226f1465a7fb721fe111 (patch) | |
tree | 67120790e85b977be6c5a5578293a6b3c31888af | |
parent | 5a8c8f1d45997165396502e9404ed371e5ae59fe (diff) |
tracker/{pt,wii}: simplify api
Remove useless abstract member functions, simplify
some.
Issue: #718
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.cpp | 21 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.h | 2 | ||||
-rw-r--r-- | tracker-pt/module/camera.cpp | 33 | ||||
-rw-r--r-- | tracker-pt/module/camera.h | 6 | ||||
-rw-r--r-- | tracker-pt/pt-api.cpp | 1 | ||||
-rw-r--r-- | tracker-pt/pt-api.hpp | 6 | ||||
-rw-r--r-- | tracker-wii/wii_camera.cpp | 11 | ||||
-rw-r--r-- | tracker-wii/wii_camera.h | 6 |
8 files changed, 36 insertions, 50 deletions
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index af086e5c..243fbd60 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -120,22 +120,12 @@ void Tracker_PT::run() qDebug() << "pt: thread stopped"; } -void Tracker_PT::maybe_reopen_camera() +bool Tracker_PT::maybe_reopen_camera() { QMutexLocker l(&camera_mtx); - pt_camera_open_status status = camera->start(camera_name_to_index(s.camera_name), - s.cam_fps, s.cam_res_x, s.cam_res_y); - - switch (status) - { - case cam_open_error: - break; - case cam_open_ok_change: - break; - case cam_open_ok_no_change: - break; - } + return camera->start(camera_name_to_index(s.camera_name), + s.cam_fps, s.cam_res_x, s.cam_res_y); } void Tracker_PT::set_fov(int value) @@ -156,11 +146,12 @@ module_status Tracker_PT::start_tracker(QFrame* video_frame) //video_widget->resize(video_frame->width(), video_frame->height()); video_frame->show(); - maybe_reopen_camera(); + if (!maybe_reopen_camera()) + return { tr("Can't open camera") }; start(QThread::HighPriority); - return status_ok(); + return {}; } void Tracker_PT::data(double *data) diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h index 3cb5f67b..03812092 100644 --- a/tracker-pt/ftnoir_tracker_pt.h +++ b/tracker-pt/ftnoir_tracker_pt.h @@ -53,7 +53,7 @@ public: int get_n_points(); bool get_cam_info(pt_camera_info* info); public slots: - void maybe_reopen_camera(); + bool maybe_reopen_camera(); void set_fov(int value); protected: void run() override; diff --git a/tracker-pt/module/camera.cpp b/tracker-pt/module/camera.cpp index ba4583da..9c62e8a3 100644 --- a/tracker-pt/module/camera.cpp +++ b/tracker-pt/module/camera.cpp @@ -36,19 +36,18 @@ void Camera::show_camera_settings() { const int idx = camera_name_to_index(s.camera_name); - if (bool(*this)) + if (cap && cap->isOpened()) video_property_page::show_from_capture(*cap, idx); else - { video_property_page::show(idx); - } } Camera::result Camera::get_info() const { if (cam_info.res_x == 0 || cam_info.res_y == 0) - return result(false, pt_camera_info()); - return result(true, cam_info); + return { false, pt_camera_info() }; + else + return { true, cam_info }; } Camera::result Camera::get_frame(pt_frame& frame_) @@ -82,7 +81,7 @@ Camera::result Camera::get_frame(pt_frame& frame_) return result(false, pt_camera_info()); } -pt_camera_open_status Camera::start(int idx, int fps, int res_x, int res_y) +bool Camera::start(int idx, int fps, int res_x, int res_y) { if (idx >= 0 && fps >= 0 && res_x >= 0 && res_y >= 0) { @@ -110,7 +109,7 @@ pt_camera_open_status Camera::start(int idx, int fps, int res_x, int res_y) if (cam_desired.fps) cap->set(cv::CAP_PROP_FPS, cam_desired.fps); - if (cap->isOpened() && cap->grab()) + if (cap->isOpened()) { cam_info = pt_camera_info(); active_name = QString(); @@ -118,22 +117,24 @@ pt_camera_open_status Camera::start(int idx, int fps, int res_x, int res_y) dt_mean = 0; active_name = desired_name; - t.start(); + cv::Mat tmp; - return cam_open_ok_change; - } - else - { - stop(); - return cam_open_error; + if (_get_frame(tmp)) + { + t.start(); + return true; + } } + + cap = nullptr; + return false; } - return cam_open_ok_no_change; + return true; } stop(); - return cam_open_error; + return false; } void Camera::stop() diff --git a/tracker-pt/module/camera.h b/tracker-pt/module/camera.h index 96234840..79e3dca0 100644 --- a/tracker-pt/module/camera.h +++ b/tracker-pt/module/camera.h @@ -26,7 +26,7 @@ struct Camera final : pt_camera { Camera(const QString& module_name); - pt_camera_open_status start(int idx, int fps, int res_x, int res_y) override; + bool start(int idx, int fps, int res_x, int res_y) override; void stop() override; result get_frame(pt_frame& Frame) override; @@ -36,8 +36,6 @@ struct Camera final : pt_camera QString get_desired_name() const override; QString get_active_name() const override; - operator bool() const override { return cap && cap->isOpened(); } - void set_fov(double value) override { fov = value; } void show_camera_settings() override; @@ -45,9 +43,7 @@ private: warn_result_unused bool _get_frame(cv::Mat& Frame); double dt_mean = 0, fov = 30; - Timer t; - pt_camera_info cam_info; pt_camera_info cam_desired; QString desired_name, active_name; diff --git a/tracker-pt/pt-api.cpp b/tracker-pt/pt-api.cpp index 298f405a..596590dc 100644 --- a/tracker-pt/pt-api.cpp +++ b/tracker-pt/pt-api.cpp @@ -57,7 +57,6 @@ double pt_point_extractor::threshold_radius_value(int w, int h, int threshold) return radius; } - std::tuple<double, double> pt_pixel_pos_mixin::to_pixel_pos(double x, double y, int w, int h) { return std::make_tuple(w*(x+.5), .5*(h - 2*y*w)); diff --git a/tracker-pt/pt-api.hpp b/tracker-pt/pt-api.hpp index e946c5d0..de097a04 100644 --- a/tracker-pt/pt-api.hpp +++ b/tracker-pt/pt-api.hpp @@ -30,8 +30,6 @@ struct OTR_PT_EXPORT pt_camera_info final int idx = -1; }; -enum pt_camera_open_status : unsigned { cam_open_error, cam_open_ok_no_change, cam_open_ok_change }; - struct OTR_PT_EXPORT pt_pixel_pos_mixin { static std::tuple<double, double> to_pixel_pos(double x, double y, int w, int h); @@ -73,7 +71,7 @@ struct OTR_PT_EXPORT pt_camera pt_camera(); virtual ~pt_camera(); - virtual warn_result_unused pt_camera_open_status start(int idx, int fps, int res_x, int res_y) = 0; + virtual warn_result_unused bool start(int idx, int fps, int res_x, int res_y) = 0; virtual void stop() = 0; virtual warn_result_unused result get_frame(pt_frame& frame) = 0; @@ -84,8 +82,6 @@ struct OTR_PT_EXPORT pt_camera virtual QString get_active_name() const = 0; virtual void set_fov(double value) = 0; - virtual operator bool() const = 0; - virtual void show_camera_settings() = 0; }; diff --git a/tracker-wii/wii_camera.cpp b/tracker-wii/wii_camera.cpp index 251ab33a..2af3eca3 100644 --- a/tracker-wii/wii_camera.cpp +++ b/tracker-wii/wii_camera.cpp @@ -33,7 +33,12 @@ WIICamera::WIICamera(const QString& module_name) : s { module_name } cam_info.res_x = 1024; cam_info.res_y = 768; cam_info.fov = 42.0f; - cam_info.idx = 0; + cam_info.idx = 0; +} + +WIICamera::~WIICamera() +{ + stop(); } QString WIICamera::get_desired_name() const @@ -81,14 +86,14 @@ WIICamera::result WIICamera::get_frame(pt_frame& frame_) return result(true, cam_info); } -pt_camera_open_status WIICamera::start(int idx, int fps, int res_x, int res_y) +bool WIICamera::start(int idx, int fps, int res_x, int res_y) { m_pDev = std::make_unique<wiimote>(); m_pDev->ChangedCallback = on_state_change; m_pDev->CallbackTriggerFlags = (state_change_flags)(CONNECTED | EXTENSION_CHANGED | MOTIONPLUS_CHANGED); - return cam_open_ok_no_change; + return true; } void WIICamera::stop() diff --git a/tracker-wii/wii_camera.h b/tracker-wii/wii_camera.h index d0d7f6dd..55def206 100644 --- a/tracker-wii/wii_camera.h +++ b/tracker-wii/wii_camera.h @@ -29,8 +29,9 @@ namespace pt_module { struct WIICamera final : pt_camera { WIICamera(const QString& module_name); + ~WIICamera() override; - pt_camera_open_status start(int idx, int fps, int res_x, int res_y) override; + bool start(int idx, int fps, int res_x, int res_y) override; void stop() override; result get_frame(pt_frame& Frame) override; @@ -40,12 +41,9 @@ struct WIICamera final : pt_camera QString get_desired_name() const override; QString get_active_name() const override; - operator bool() const override { return m_pDev && (!m_pDev->ConnectionLost()); } - void set_fov(double value) override {} void show_camera_settings() override; - private: std::unique_ptr<wiimote> m_pDev; static void on_state_change(wiimote &remote, |