From 0a92bc147f91f3ecacdf66d995f01f9577107a86 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 15 Feb 2018 09:06:13 +0100 Subject: clean up "static" and "constexpr" types - use `static constexpr inline' to avoid requiring explicit declarations in object code - use `const Foo* const' to maybe put into readonly binary segment (at least for ELF DSOs) - `constexpr' in function scope has storage, avoid `static' - don't use `constexpr' where there's no advantage, like arrays We'd like to avoid overhead of atomic initialization for each function call. No idea how `static constexpr' requiring storage in the standard plays with atomic initialization requirement. Hearsay points that `constexpr' without `static' in block scope behaves more to our liking. It's all hazy though. I'm not 100% sure if `static inline constexpr' has any storage. Hopefully none, like a #define, and stuff bigger than registers gets coalesced within the same module, with small stuff being immediates. --- tracker-pt/ftnoir_tracker_pt.h | 2 +- tracker-pt/ftnoir_tracker_pt_dialog.cpp | 2 +- tracker-pt/point_tracker.cpp | 2 -- tracker-pt/point_tracker.h | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) (limited to 'tracker-pt') diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h index d1f7e1d7..3cb5f67b 100644 --- a/tracker-pt/ftnoir_tracker_pt.h +++ b/tracker-pt/ftnoir_tracker_pt.h @@ -81,7 +81,7 @@ private: std::atomic point_count = 0; std::atomic ever_success = false; - static constexpr f rad2deg = f(180/M_PI); + static constexpr inline f rad2deg = f(180/M_PI); //static constexpr float deg2rad = float(M_PI/180); }; diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp index 10a2c6cb..5bd1a4c8 100644 --- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp +++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp @@ -90,7 +90,7 @@ TrackerDialog_PT::TrackerDialog_PT(const QString& module_name) : connect(this, &TrackerDialog_PT::poll_tracker_info, this, &TrackerDialog_PT::poll_tracker_info_impl, Qt::DirectConnection); - static constexpr pt_color_type color_types[] = { + constexpr pt_color_type color_types[] = { pt_color_average, pt_color_natural, pt_color_red_only, diff --git a/tracker-pt/point_tracker.cpp b/tracker-pt/point_tracker.cpp index 5efbbfe8..6116bec5 100644 --- a/tracker-pt/point_tracker.cpp +++ b/tracker-pt/point_tracker.cpp @@ -16,8 +16,6 @@ using namespace types; #include -constexpr unsigned PointModel::N_POINTS; - static void get_row(const mat33& m, int i, vec3& v) { v[0] = m(i,0); diff --git a/tracker-pt/point_tracker.h b/tracker-pt/point_tracker.h index 6abe5df9..5e741c75 100644 --- a/tracker-pt/point_tracker.h +++ b/tracker-pt/point_tracker.h @@ -32,7 +32,7 @@ using namespace types; struct PointModel final { - static constexpr unsigned N_POINTS = 3; + static constexpr inline unsigned N_POINTS = 3; vec3 M01; // M01 in model frame vec3 M02; // M02 in model frame -- cgit v1.2.3 From e42a0361c986c39a9456226f1465a7fb721fe111 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 16 Feb 2018 11:07:57 +0100 Subject: tracker/{pt,wii}: simplify api Remove useless abstract member functions, simplify some. Issue: #718 --- tracker-pt/ftnoir_tracker_pt.cpp | 21 ++++++--------------- tracker-pt/ftnoir_tracker_pt.h | 2 +- tracker-pt/module/camera.cpp | 33 +++++++++++++++++---------------- tracker-pt/module/camera.h | 6 +----- tracker-pt/pt-api.cpp | 1 - tracker-pt/pt-api.hpp | 6 +----- tracker-wii/wii_camera.cpp | 11 ++++++++--- tracker-wii/wii_camera.h | 6 ++---- 8 files changed, 36 insertions(+), 50 deletions(-) (limited to 'tracker-pt') 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 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 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(); 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 m_pDev; static void on_state_change(wiimote &remote, -- cgit v1.2.3 From c5de9269b73a8750a9eba7fb10d3388ed27051ca Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 16 Feb 2018 11:08:35 +0100 Subject: tracker/wii: fix Chinese translation The file must be in tracker-pt/ since it translates .ui file located there. Issue: #748 --- tracker-pt/lang/zh_CN.ts | 191 +++++++++++++++--------------- tracker-wii/lang/zh_CN.ts | 291 +--------------------------------------------- 2 files changed, 100 insertions(+), 382 deletions(-) (limited to 'tracker-pt') diff --git a/tracker-pt/lang/zh_CN.ts b/tracker-pt/lang/zh_CN.ts index 2a8e9ca0..07d8c469 100644 --- a/tracker-pt/lang/zh_CN.ts +++ b/tracker-pt/lang/zh_CN.ts @@ -1,6 +1,6 @@ - + TrackerDialog_PT @@ -29,7 +29,7 @@ Start calibration - + 开始校准 %1x%2 @ %3 FPS @@ -52,227 +52,234 @@ UICPTClientControls PointTracker Settings - - - - Status - - - - Extracted Points: - - - - Camera Info: - + PointTracker设置 Camera - + 摄像头 Camera settings - + 摄像头设置 ° - + Diagonal field of view - + 对角线 Width - + FPS - + 帧数 Desired capture height - + 期望高度 px - + 像素点 Dynamic pose timeout - + 动态姿态超时时间 Desired capture framerate - + 期望帧数 Hz - + 赫兹 Desired capture width - + 期望宽度 Height - + 高度 ms - + 毫秒 Device - + 设备名称 Open - + 打开 Camera settings (when available) - - - - Color channels used - + 摄像头设置 (连接时) - Average - - - - Natural - - - - Red only - - - - Blue only - - - - Dynamic pose (for caps only, never clips) - + Point extraction + 跟踪点解析 - Point extraction - + Max size + 最大 Threshold - + 大小门限值 Min size - - - - Max size - + 最小 Intensity threshold for point extraction - + 点密度 - Enable, slider sets point size - + Automatic threshold + 自动门限值 - Automatic threshold - + Enable, slider sets point size + 激活,滑动,设置跟踪点大小 Maximum point diameter - + 最大点直径 Minimum point diameter - - - - Value - + 最小点直径 Model - + 点模式 Clip - + 夹子式 Model Dimensions - + 尺寸 mm - + 毫米 Side - + 侧面 Front - + 正面 Cap - + 帽子式 Custom - + 自定义模式 z: - + Z: x: - + X: <html><head/><body><p>Location of the two remaining model points<br/>with respect to the reference point in default pose</p><p>Use any units you want, not necessarily centimeters.</p></body></html> - + <html><head/><body><p>三点中的两点位置是相对第一个点的</p><p>单位不一定要用厘米</p></body></html> y: - + Y: <html><head/><body><p><span style=" font-size:16pt;">P</span><span style=" font-size:16pt; vertical-align:sub;">3</span></p></body></html> - + <html><head/><body><p><span style=" font-size:16pt;">P</span><span style=" font-size:16pt; vertical-align:sub;">3</span></p></body></html> <html><head/><body><p><span style=" font-size:16pt;">P</span><span style=" font-size:16pt; vertical-align:sub;">2</span></p></body></html> - + <html><head/><body><p><span style=" font-size:16pt;">P</span><span style=" font-size:16pt; vertical-align:sub;">2</span></p></body></html> Model position + 姿态空间位置 + + + Start calibration + 开始校准 + + + About + 关于 + + + <html><head/><body><p><span style=" font-weight:600;">FTNoIR PointTracker Plugin<br/>Version 1.1</span></p><p><span style=" font-weight:600;">by Patrick Ruoff</span></p><p><a href="http://ftnoirpt.sourceforge.net/"><span style=" font-weight:600; text-decoration: underline; color:#0000ff;">Manual (external)</span></a></p></body></html> + <html><head/><body><p><span style=" font-weight:600;">FTNoIR PointTracker Plugin<br/>Version 1.1</span></p><p><span style=" font-weight:600;">Patrick Ruoff</span></p><p><a href="http://ftnoirpt.sourceforge.net/"><span style=" font-weight:600; text-decoration: underline; color:#0000ff;">参考手册 (外部链接)</span></a></p></body></html> + + + Status + 状态 + + + Extracted Points: + 解析出的点: + + + Camera Info: + 设备信息: + + + Color channels used - Use only yaw and pitch while calibrating. -Don't roll or change position. + Average - Start calibration + Natural - About + Red only - <html><head/><body><p><span style=" font-weight:600;">FTNoIR PointTracker Plugin<br/>Version 1.1</span></p><p><span style=" font-weight:600;">by Patrick Ruoff</span></p><p><a href="http://ftnoirpt.sourceforge.net/"><span style=" font-weight:600; text-decoration: underline; color:#0000ff;">Manual (external)</span></a></p></body></html> + Blue only + + + + Dynamic pose (for caps only, never clips) + + + + Value + + + + Use only yaw and pitch while calibrating. +Don't roll or change position. + + + + + pt_module::Tracker_PT + + Can't open camera diff --git a/tracker-wii/lang/zh_CN.ts b/tracker-wii/lang/zh_CN.ts index 3f3131d8..6401616d 100644 --- a/tracker-wii/lang/zh_CN.ts +++ b/tracker-wii/lang/zh_CN.ts @@ -1,293 +1,4 @@ - - - PT_metadata - - - PointTracker 1.1 - - - - - UICPTClientControls - - - PointTracker Settings - PointTracker设置 - - - - Camera - 摄像头 - - - - Camera settings - 摄像头设置 - - - - ° - - - - - Diagonal field of view - 对角线 - - - - Width - - - - - FPS - 帧数 - - - - Desired capture height - 期望高度 - - - - - - - px - 像素点 - - - - Dynamic pose timeout - 动态姿态超时时间 - - - - Desired capture framerate - 期望帧数 - - - - Hz - 赫兹 - - - - Desired capture width - 期望宽度 - - - - Height - 高度 - - - - ms - 毫秒 - - - - Dynamic pose resolution - 动态姿态分辨率 - - - - Device - 设备名称 - - - - Open - 打开 - - - - Camera settings (when available) - 摄像头设置 (连接时) - - - - Point extraction - 跟踪点解析 - - - - Max size - 最大 - - - - Threshold - 大小门限值 - - - - Min size - 最小 - - - - Intensity threshold for point extraction - 点密度 - - - - Automatic threshold - 自动门限值 - - - - Enable, slider sets point size - 激活,滑动,设置跟踪点大小 - - - - Maximum point diameter - 最大点直径 - - - - Minimum point diameter - 最小点直径 - - - - Model - 点模式 - - - - Clip - 夹子式 - - - - - - Model Dimensions - 尺寸 - - - - - - - - - - - - - - - - - - - mm - 毫米 - - - - - Side - 侧面 - - - - - Front - 正面 - - - - Cap - 帽子式 - - - - Custom - 自定义模式 - - - - - - z: - Z: - - - - - - x: - X: - - - - <html><head/><body><p>Location of the two remaining model points<br/>with respect to the reference point in default pose</p><p>Use any units you want, not necessarily centimeters.</p></body></html> - <html><head/><body><p>三点中的两点位置是相对第一个点的</p><p>单位不一定要用厘米</p></body></html> - - - - - - y: - Y: - - - - <html><head/><body><p><span style=" font-size:16pt;">P</span><span style=" font-size:16pt; vertical-align:sub;">3</span></p></body></html> - <html><head/><body><p><span style=" font-size:16pt;">P</span><span style=" font-size:16pt; vertical-align:sub;">3</span></p></body></html> - - - - <html><head/><body><p><span style=" font-size:16pt;">P</span><span style=" font-size:16pt; vertical-align:sub;">2</span></p></body></html> - <html><head/><body><p><span style=" font-size:16pt;">P</span><span style=" font-size:16pt; vertical-align:sub;">2</span></p></body></html> - - - - Model position - 姿态空间位置 - - - - <html><head/><body><p><a href="https://github.com/opentrack/opentrack/wiki/model-calibration-for-PT-and-Aruco-trackers"><span style=" text-decoration: underline; color:#0000ff;">Instructions on the opentrack wiki</span></a></p></body></html> - <html><head/><body><p><a href="https://github.com/opentrack/opentrack/wiki/model-calibration-for-PT-and-Aruco-trackers"><span style=" text-decoration: underline; color:#0000ff;">参考opentrack维基</span></a></p></body></html> - - - - Start calibration - 开始校准 - - - - About - 关于 - - - - <html><head/><body><p><span style=" font-weight:600;">FTNoIR PointTracker Plugin<br/>Version 1.1</span></p><p><span style=" font-weight:600;">by Patrick Ruoff</span></p><p><a href="http://ftnoirpt.sourceforge.net/"><span style=" font-weight:600; text-decoration: underline; color:#0000ff;">Manual (external)</span></a></p></body></html> - <html><head/><body><p><span style=" font-weight:600;">FTNoIR PointTracker Plugin<br/>Version 1.1</span></p><p><span style=" font-weight:600;">Patrick Ruoff</span></p><p><a href="http://ftnoirpt.sourceforge.net/"><span style=" font-weight:600; text-decoration: underline; color:#0000ff;">参考手册 (外部链接)</span></a></p></body></html> - - - - Status - 状态 - - - - Extracted Points: - 解析出的点: - - - - Camera Info: - 设备信息: - - + -- cgit v1.2.3 From 4fbfe466e7b4f84e66fc0549f76f4255b3c41f53 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 16 Feb 2018 11:09:14 +0100 Subject: tracker/pt: add new string --- tracker-pt/lang/nl_NL.ts | 7 +++++++ tracker-pt/lang/ru_RU.ts | 7 +++++++ tracker-pt/lang/stub.ts | 7 +++++++ 3 files changed, 21 insertions(+) (limited to 'tracker-pt') diff --git a/tracker-pt/lang/nl_NL.ts b/tracker-pt/lang/nl_NL.ts index 16aaa82e..34f88c88 100644 --- a/tracker-pt/lang/nl_NL.ts +++ b/tracker-pt/lang/nl_NL.ts @@ -276,4 +276,11 @@ Don't roll or change position. + + pt_module::Tracker_PT + + Can't open camera + + + diff --git a/tracker-pt/lang/ru_RU.ts b/tracker-pt/lang/ru_RU.ts index 88f3cb4a..63b4847a 100644 --- a/tracker-pt/lang/ru_RU.ts +++ b/tracker-pt/lang/ru_RU.ts @@ -281,4 +281,11 @@ ROLL или X/Y-смещения. Параметры камеры: + + pt_module::Tracker_PT + + Can't open camera + + + diff --git a/tracker-pt/lang/stub.ts b/tracker-pt/lang/stub.ts index a3377c2e..e83487a9 100644 --- a/tracker-pt/lang/stub.ts +++ b/tracker-pt/lang/stub.ts @@ -276,4 +276,11 @@ Don't roll or change position. + + pt_module::Tracker_PT + + Can't open camera + + + -- cgit v1.2.3