diff options
author | Stéphane Lenclud <github@lenclud.com> | 2019-04-12 23:19:54 +0200 |
---|---|---|
committer | Stéphane Lenclud <github@lenclud.com> | 2019-04-24 18:46:12 +0200 |
commit | 7e357fcb6c143a61c4f87ffda502f8be021674f0 (patch) | |
tree | 147bcd90d7ac414ef9ff1e024abba37f085c950d | |
parent | f20687d2d5f9b0542fedf0f45291024846d30d28 (diff) |
Easy Tracker: removing legacy point tracker camera architecture.
-rw-r--r-- | tracker-easy/camera.cpp | 151 | ||||
-rw-r--r-- | tracker-easy/camera.h | 57 | ||||
-rw-r--r-- | tracker-easy/frame.cpp | 10 | ||||
-rw-r--r-- | tracker-easy/frame.hpp | 25 | ||||
-rw-r--r-- | tracker-easy/lang/nl_NL.ts | 12 | ||||
-rw-r--r-- | tracker-easy/lang/ru_RU.ts | 12 | ||||
-rw-r--r-- | tracker-easy/lang/stub.ts | 12 | ||||
-rw-r--r-- | tracker-easy/lang/zh_CN.ts | 12 | ||||
-rw-r--r-- | tracker-easy/module.cpp | 15 | ||||
-rw-r--r-- | tracker-easy/point_extractor.cpp | 5 | ||||
-rw-r--r-- | tracker-easy/point_extractor.h | 2 | ||||
-rw-r--r-- | tracker-easy/tracker-easy-api.cpp | 19 | ||||
-rw-r--r-- | tracker-easy/tracker-easy-api.h | 66 | ||||
-rw-r--r-- | tracker-easy/tracker-easy-dialog.cpp | 9 | ||||
-rw-r--r-- | tracker-easy/tracker-easy.cpp | 56 | ||||
-rw-r--r-- | tracker-easy/tracker-easy.h | 12 | ||||
-rw-r--r-- | video/camera.hpp | 1 |
17 files changed, 54 insertions, 422 deletions
diff --git a/tracker-easy/camera.cpp b/tracker-easy/camera.cpp deleted file mode 100644 index 25f1f8d5..00000000 --- a/tracker-easy/camera.cpp +++ /dev/null @@ -1,151 +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 "camera.h" -#include "frame.hpp" - -#include "compat/math-imports.hpp" - -#include <opencv2/core.hpp> - -namespace pt_module { - -Camera::Camera(const QString& module_name) : s { module_name } -{ -} - -QString Camera::get_desired_name() const -{ - return cam_desired.name; -} - -QString Camera::get_active_name() const -{ - return cam_info.name; -} - -void Camera::show_camera_settings() -{ - if (cap) - (void)cap->show_dialog(); -} - -Camera::result Camera::get_info() const -{ - if (cam_info.res_x == 0 || cam_info.res_y == 0) - return { false, pt_camera_info() }; - else - return { true, cam_info }; -} - -Camera::result Camera::get_frame(pt_frame& frame_) -{ - cv::Mat& frame = frame_.as<Frame>()->mat; - - const bool new_frame = get_frame_(frame); - - if (new_frame) - { - const f dt = (f)t.elapsed_seconds(); - t.start(); - - // measure fps of valid frames - constexpr f RC = f{1}/10; // seconds - const f alpha = dt/(dt + RC); - - if (dt_mean < dt_eps) - dt_mean = dt; - else - dt_mean = (1-alpha) * dt_mean + alpha * dt; - - cam_info.fps = dt_mean > dt_eps ? 1 / dt_mean : 0; - cam_info.res_x = frame.cols; - cam_info.res_y = frame.rows; - cam_info.fov = fov; - - return { true, cam_info }; - } - else - return { false, {} }; -} - -bool Camera::start(const QString& name, int fps, int res_x, int res_y) -{ - if (fps >= 0 && res_x >= 0 && res_y >= 0) - { - if (cam_desired.name != name || - (int)cam_desired.fps != fps || - cam_desired.res_x != res_x || - cam_desired.res_y != res_y || - !cap || !cap->is_open()) - { - stop(); - - cam_desired.name = name; - cam_desired.fps = fps; - cam_desired.res_x = res_x; - cam_desired.res_y = res_y; - cam_desired.fov = fov; - - cap = video::make_camera(name); - - if (!cap) - goto fail; - - info.fps = fps; - info.width = res_x; - info.height = res_y; - - if (!cap->start(info)) - goto fail; - - cam_info = pt_camera_info(); - cam_info.name = name; - dt_mean = 0; - - cv::Mat tmp; - - if (!get_frame_(tmp)) - goto fail; - - t.start(); - } - } - - return true; - -fail: - stop(); - return false; -} - -void Camera::stop() -{ - cap = nullptr; - cam_info = {}; - cam_desired = {}; -} - -bool Camera::get_frame_(cv::Mat& img) -{ - if (cap && cap->is_open()) - { - auto [ frame, ret ] = cap->get_frame(); - if (ret) - { - int stride = frame.stride; - if (stride == 0) - stride = cv::Mat::AUTO_STEP; - img = cv::Mat(frame.height, frame.width, CV_8UC(frame.channels), (void*)frame.data, stride); - return true; - } - } - - return false; -} - -} // ns pt_module diff --git a/tracker-easy/camera.h b/tracker-easy/camera.h deleted file mode 100644 index 5fec9a19..00000000 --- a/tracker-easy/camera.h +++ /dev/null @@ -1,57 +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 "tracker-easy-api.h" -#include "compat/timer.hpp" -#include "video/camera.hpp" - -#include <memory> - -#include <opencv2/core.hpp> - -#include <QString> - -namespace pt_module { - -struct Camera final : pt_camera -{ - Camera(const QString& module_name); - - bool start(const QString& name, int fps, int res_x, int res_y) override; - void stop() override; - - result get_frame(pt_frame& Frame) override; - result get_info() const override; - - pt_camera_info get_desired() const override { return cam_desired; } - QString get_desired_name() const override; - QString get_active_name() const override; - - void set_fov(f value) override { fov = value; } - void show_camera_settings() override; - - -private: - using camera = typename video::impl::camera; - - [[nodiscard]] bool get_frame_(cv::Mat& frame); - - f dt_mean = 0, fov = 30; - Timer t; - pt_camera_info cam_info; - pt_camera_info cam_desired; - - std::unique_ptr<camera> cap; - - pt_settings s; - - static constexpr f dt_eps = f{1}/256; -}; - -} // ns pt_module diff --git a/tracker-easy/frame.cpp b/tracker-easy/frame.cpp index a045b783..b066e13b 100644 --- a/tracker-easy/frame.cpp +++ b/tracker-easy/frame.cpp @@ -4,11 +4,9 @@ #include <opencv2/imgproc.hpp> -namespace pt_module { -Preview& Preview::operator=(const pt_frame& frame_) +Preview& Preview::operator=(const cv::Mat& frame) { - const cv::Mat& frame = frame_.as_const<const Frame>()->mat; if (frame.channels() != 3) { @@ -52,9 +50,9 @@ QImage Preview::get_bitmap() QImage::Format_ARGB32); } -void Preview::draw_head_center(f x, f y) +void Preview::draw_head_center(pt_pixel_pos_mixin::f x, pt_pixel_pos_mixin::f y) { - auto [px_, py_] = to_pixel_pos(x, y, frame_copy.cols, frame_copy.rows); + auto [px_, py_] = pt_pixel_pos_mixin::to_pixel_pos(x, y, frame_copy.cols, frame_copy.rows); int px = iround(px_), py = iround(py_); @@ -76,5 +74,3 @@ void Preview::ensure_size(cv::Mat& frame, int w, int h, int type) if (frame.cols != w || frame.rows != h) frame = cv::Mat(h, w, type); } - -} // ns pt_module diff --git a/tracker-easy/frame.hpp b/tracker-easy/frame.hpp index 678665fd..807f74d2 100644 --- a/tracker-easy/frame.hpp +++ b/tracker-easy/frame.hpp @@ -5,28 +5,15 @@ #include <opencv2/core.hpp> #include <QImage> -#ifdef __clang__ -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wweak-vtables" -#endif -namespace pt_module { -struct Frame final : pt_frame -{ - cv::Mat mat; - - operator const cv::Mat&() const& { return mat; } - operator cv::Mat&() & { return mat; } -}; - -struct Preview final : pt_preview +struct Preview { Preview(int w, int h); - Preview& operator=(const pt_frame& frame) override; - QImage get_bitmap() override; - void draw_head_center(f x, f y) override; + Preview& operator=(const cv::Mat& frame); + QImage get_bitmap(); + void draw_head_center(pt_pixel_pos_mixin::f x, pt_pixel_pos_mixin::f y); operator cv::Mat&() { return frame_copy; } operator cv::Mat const&() const { return frame_copy; } @@ -37,8 +24,4 @@ private: cv::Mat frame_copy, frame_out; }; -} // ns pt_module -#ifdef __clang__ -# pragma clang diagnostic pop -#endif diff --git a/tracker-easy/lang/nl_NL.ts b/tracker-easy/lang/nl_NL.ts index d4569244..8f471ea0 100644 --- a/tracker-easy/lang/nl_NL.ts +++ b/tracker-easy/lang/nl_NL.ts @@ -264,18 +264,6 @@ Don't roll or change position.</source> <translation type="unfinished"></translation> </message> <message> - <source>%1x%2 @ %3 FPS</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>%1 OK!</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>%1 BAD!</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Tracker offline</source> <translation type="unfinished"></translation> </message> diff --git a/tracker-easy/lang/ru_RU.ts b/tracker-easy/lang/ru_RU.ts index 3fbde4a4..eb58cdc7 100644 --- a/tracker-easy/lang/ru_RU.ts +++ b/tracker-easy/lang/ru_RU.ts @@ -269,18 +269,6 @@ ROLL или X/Y-смещения.</translation> <translation type="unfinished">Начать калибровку</translation> </message> <message> - <source>%1x%2 @ %3 FPS</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>%1 OK!</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>%1 BAD!</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Tracker offline</source> <translation type="unfinished">Отслеживание отключено</translation> </message> diff --git a/tracker-easy/lang/stub.ts b/tracker-easy/lang/stub.ts index dd474b57..ced89412 100644 --- a/tracker-easy/lang/stub.ts +++ b/tracker-easy/lang/stub.ts @@ -264,18 +264,6 @@ Don't roll or change position.</source> <translation type="unfinished"></translation> </message> <message> - <source>%1x%2 @ %3 FPS</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>%1 OK!</source> - <translation type="unfinished"></translation> - </message> - <message> - <source>%1 BAD!</source> - <translation type="unfinished"></translation> - </message> - <message> <source>Tracker offline</source> <translation type="unfinished"></translation> </message> diff --git a/tracker-easy/lang/zh_CN.ts b/tracker-easy/lang/zh_CN.ts index 34a811dd..ff272fdc 100644 --- a/tracker-easy/lang/zh_CN.ts +++ b/tracker-easy/lang/zh_CN.ts @@ -264,18 +264,6 @@ Don't roll or change position.</source> <translation type="unfinished">开始校准</translation> </message> <message> - <source>%1x%2 @ %3 FPS</source> - <translation type="unfinished">%1x%2 @ %3 帧</translation> - </message> - <message> - <source>%1 OK!</source> - <translation type="unfinished">%1 正常</translation> - </message> - <message> - <source>%1 BAD!</source> - <translation type="unfinished">%1 异常</translation> - </message> - <message> <source>Tracker offline</source> <translation type="unfinished">跟踪器脱机</translation> </message> diff --git a/tracker-easy/module.cpp b/tracker-easy/module.cpp index 10d25369..4f6df056 100644 --- a/tracker-easy/module.cpp +++ b/tracker-easy/module.cpp @@ -3,7 +3,6 @@ #include "tracker-easy-api.h" #include "module.hpp" -#include "camera.h" #include "frame.hpp" #include "point_extractor.h" @@ -20,11 +19,6 @@ namespace pt_module { struct pt_module_traits final : pt_runtime_traits { - pointer<pt_camera> make_camera() const override - { - return pointer<pt_camera>(new Camera(module_name)); - } - pointer<pt_point_extractor> make_point_extractor() const override { return pointer<pt_point_extractor>(new PointExtractor(module_name)); @@ -35,15 +29,6 @@ struct pt_module_traits final : pt_runtime_traits return module_name; } - pointer<pt_frame> make_frame() const override - { - return pointer<pt_frame>(new Frame); - } - - pointer<pt_preview> make_preview(int w, int h) const override - { - return pointer<pt_preview>(new Preview(w, h)); - } }; struct tracker_pt : Tracker_PT diff --git a/tracker-easy/point_extractor.cpp b/tracker-easy/point_extractor.cpp index 0d54a66b..54803d52 100644 --- a/tracker-easy/point_extractor.cpp +++ b/tracker-easy/point_extractor.cpp @@ -238,9 +238,8 @@ static void draw_blobs(cv::Mat& preview_frame, const blob* blobs, unsigned nblob } } -void PointExtractor::extract_points(const pt_frame& frame_, pt_preview& preview_frame_, std::vector<vec2>& points, std::vector<vec2>& imagePoints) +void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame_, std::vector<vec2>& points, std::vector<vec2>& imagePoints) { - const cv::Mat& frame = frame_.as_const<Frame>()->mat; ensure_buffers(frame); color_to_grayscale(frame, frame_gray_unmasked); @@ -359,7 +358,7 @@ end: } // TODO: Do not do that if no preview. Delay blob drawing until we know where are the points? - draw_blobs(preview_frame_.as<Frame>()->mat, + draw_blobs(preview_frame_, blobs.data(), blobs.size(), frame_gray.size()); diff --git a/tracker-easy/point_extractor.h b/tracker-easy/point_extractor.h index fd0b8144..41f74493 100644 --- a/tracker-easy/point_extractor.h +++ b/tracker-easy/point_extractor.h @@ -33,7 +33,7 @@ class PointExtractor final : public pt_point_extractor public: // extracts points from frame and draws some processing info into frame, if draw_output is set // dt: time since last call in seconds - void extract_points(const pt_frame& frame, pt_preview& preview_frame, std::vector<vec2>& points, std::vector<vec2>& imagePoints) override; + void extract_points(const cv::Mat& frame, cv::Mat& preview_frame, std::vector<vec2>& points, std::vector<vec2>& imagePoints) override; PointExtractor(const QString& module_name); public: diff --git a/tracker-easy/tracker-easy-api.cpp b/tracker-easy/tracker-easy-api.cpp index 49e11759..32663a6a 100644 --- a/tracker-easy/tracker-easy-api.cpp +++ b/tracker-easy/tracker-easy-api.cpp @@ -3,24 +3,8 @@ using namespace numeric_types; -pt_camera_info::pt_camera_info() = default; -f pt_camera_info::get_focal_length(f fov, int res_x, int res_y) -{ - const f diag_len = std::sqrt(f(res_x*res_x + res_y*res_y)); - const f aspect_x = res_x / diag_len; - //const double aspect_y = res_y / diag_len; - const f diag_fov = fov * pi/180; - const f fov_x = 2*std::atan(std::tan(diag_fov*f{.5}) * aspect_x); - //const double fov_y = 2*atan(tan(diag_fov*.5) * aspect_y); - const f fx = f{.5} / std::tan(fov_x * f{.5}); - return fx; - //fy = .5 / tan(fov_y * .5); - //static bool once = false; if (!once) { once = true; qDebug() << "f" << ret << "fov" << (fov * 180/M_PI); } -} -pt_camera::pt_camera() = default; -pt_camera::~pt_camera() = default; pt_runtime_traits::pt_runtime_traits() = default; pt_runtime_traits::~pt_runtime_traits() = default; pt_point_extractor::pt_point_extractor() = default; @@ -49,6 +33,3 @@ std::tuple<f, f> pt_pixel_pos_mixin::to_screen_pos(f px, f py, int w, int h) return std::make_tuple((px - w/f{2})/w, -(py - h/f{2})/w); } -pt_frame::pt_frame() = default; - -pt_frame::~pt_frame() = default; diff --git a/tracker-easy/tracker-easy-api.h b/tracker-easy/tracker-easy-api.h index 81a52f7f..b42e4c73 100644 --- a/tracker-easy/tracker-easy-api.h +++ b/tracker-easy/tracker-easy-api.h @@ -22,20 +22,6 @@ const int KPointCount = 3; -struct pt_camera_info final -{ - using f = numeric_types::f; - - pt_camera_info(); - static f get_focal_length(f fov, int res_x, int res_y); - - f fov = 0; - f fps = 0; - - int res_x = 0; - int res_y = 0; - QString name; -}; struct pt_pixel_pos_mixin { @@ -45,54 +31,7 @@ struct pt_pixel_pos_mixin static std::tuple<f, f> to_screen_pos(f px, f py, int w, int h); }; -struct pt_frame : pt_pixel_pos_mixin -{ - pt_frame(); - virtual ~pt_frame(); - - template<typename t> - t* as() & - { - return static_cast<t*>(this); - } - - template<typename t> - t const* as_const() const& - { - return static_cast<t const*>(this); - } -}; - -struct pt_preview : pt_frame -{ - virtual pt_preview& operator=(const pt_frame&) = 0; - virtual QImage get_bitmap() = 0; - virtual void draw_head_center(f x, f y) = 0; -}; - -struct pt_camera -{ - using result = std::tuple<bool, pt_camera_info>; - using f = numeric_types::f; - - pt_camera(); - virtual ~pt_camera(); - [[nodiscard]] virtual bool start(const QString& name, int fps, int res_x, int res_y) = 0; - virtual void stop() = 0; - - virtual result get_frame(pt_frame& frame) = 0; - virtual result get_info() const = 0; - virtual pt_camera_info get_desired() const = 0; - - virtual QString get_desired_name() const = 0; - virtual QString get_active_name() const = 0; - - virtual void set_fov(f value) = 0; - virtual void show_camera_settings() = 0; - - video::impl::camera::info info; -}; struct pt_point_extractor : pt_pixel_pos_mixin { @@ -101,7 +40,7 @@ struct pt_point_extractor : pt_pixel_pos_mixin pt_point_extractor(); virtual ~pt_point_extractor(); - virtual void extract_points(const pt_frame& image, pt_preview& preview_frame, std::vector<vec2>& points, std::vector<vec2>& imagePoints) = 0; + virtual void extract_points(const cv::Mat& image, cv::Mat& preview_frame, std::vector<vec2>& points, std::vector<vec2>& imagePoints) = 0; static f threshold_radius_value(int w, int h, int threshold); }; @@ -113,10 +52,7 @@ struct pt_runtime_traits pt_runtime_traits(); virtual ~pt_runtime_traits(); - virtual pointer<pt_camera> make_camera() const = 0; virtual pointer<pt_point_extractor> make_point_extractor() const = 0; - virtual pointer<pt_frame> make_frame() const = 0; - virtual pointer<pt_preview> make_preview(int w, int h) const = 0; virtual QString get_module_name() const = 0; }; diff --git a/tracker-easy/tracker-easy-dialog.cpp b/tracker-easy/tracker-easy-dialog.cpp index 2a5654e3..b4a1dd30 100644 --- a/tracker-easy/tracker-easy-dialog.cpp +++ b/tracker-easy/tracker-easy-dialog.cpp @@ -123,7 +123,6 @@ QString EasyTrackerDialog::threshold_display_text(int threshold_value) return tr("Brightness %1/255").arg(threshold_value); else { - pt_camera_info info; int w = s.cam_res_x, h = s.cam_res_y; if (w * h <= 0) @@ -132,11 +131,14 @@ QString EasyTrackerDialog::threshold_display_text(int threshold_value) h = 480; } + //SL: sort this out + /* if (tracker && tracker->get_cam_info(info) && info.res_x * info.res_y != 0) { w = info.res_x; h = info.res_y; } + */ double value = (double)pt_point_extractor::threshold_radius_value(w, h, threshold_value); @@ -202,6 +204,8 @@ void EasyTrackerDialog::startstop_trans_calib(bool start) void EasyTrackerDialog::poll_tracker_info_impl() { + //SL: sort this out + /* pt_camera_info info; if (tracker && tracker->get_cam_info(info)) { @@ -212,6 +216,7 @@ void EasyTrackerDialog::poll_tracker_info_impl() ui.pointinfo_label->setText((n_points == 3 ? tr("%1 OK!") : tr("%1 BAD!")).arg(n_points)); } else + */ { ui.caminfo_label->setText(tr("Tracker offline")); ui.pointinfo_label->setText(QString()); @@ -228,7 +233,7 @@ void EasyTrackerDialog::show_camera_settings() if (tracker) { QMutexLocker l(&tracker->camera_mtx); - tracker->camera->show_camera_settings(); + tracker->camera->show_dialog(); } else (void)video::show_dialog(s.camera_name); diff --git a/tracker-easy/tracker-easy.cpp b/tracker-easy/tracker-easy.cpp index c30bb40f..1783ef51 100644 --- a/tracker-easy/tracker-easy.cpp +++ b/tracker-easy/tracker-easy.cpp @@ -31,9 +31,7 @@ EasyTracker::EasyTracker(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) } + iPreview{ preview_width, preview_height } { cv::setBreakOnError(true); cv::setNumThreads(1); @@ -107,26 +105,31 @@ void EasyTracker::run() maybe_reopen_camera(); while(!isInterruptionRequested()) - { - pt_camera_info info; + { bool new_frame = false; { QMutexLocker l(&camera_mtx); if (camera) - std::tie(new_frame, info) = camera->get_frame(*frame); + std::tie(iFrame, new_frame) = camera->get_frame(); } if (new_frame) { + //TODO: We should not assume channel size of 1 byte + iMatFrame = cv::Mat(iFrame.height, iFrame.width, CV_MAKETYPE(CV_8U,iFrame.channels), iFrame.data, iFrame.stride); + const bool preview_visible = check_is_visible(); if (preview_visible) - *preview_frame = *frame; + { + iPreview = iMatFrame; + } + iImagePoints.clear(); - point_extractor->extract_points(*frame, *preview_frame, points, iImagePoints); + point_extractor->extract_points(iMatFrame, iPreview, points, iImagePoints); point_count.store(points.size(), std::memory_order_relaxed); const bool success = points.size() >= KPointCount; @@ -208,23 +211,23 @@ void EasyTracker::run() cv::Mat cameraMatrix; cameraMatrix.create(3, 3, CV_64FC1); cameraMatrix.setTo(cv::Scalar(0)); - cameraMatrix.at<double>(0, 0) = camera->info.focalLengthX; - cameraMatrix.at<double>(1, 1) = camera->info.focalLengthY; - cameraMatrix.at<double>(0, 2) = camera->info.principalPointX; - cameraMatrix.at<double>(1, 2) = camera->info.principalPointY; + cameraMatrix.at<double>(0, 0) = iCameraInfo.focalLengthX; + cameraMatrix.at<double>(1, 1) = iCameraInfo.focalLengthY; + cameraMatrix.at<double>(0, 2) = iCameraInfo.principalPointX; + cameraMatrix.at<double>(1, 2) = iCameraInfo.principalPointY; cameraMatrix.at<double>(2, 2) = 1; // Create distortion cooefficients cv::Mat distCoeffs = cv::Mat::zeros(8, 1, CV_64FC1); // As per OpenCV docs they should be thus: k1, k2, p1, p2, k3, k4, k5, k6 distCoeffs.at<double>(0, 0) = 0; // Radial first order - distCoeffs.at<double>(1, 0) = camera->info.radialDistortionSecondOrder; // Radial second order + distCoeffs.at<double>(1, 0) = iCameraInfo.radialDistortionSecondOrder; // Radial second order distCoeffs.at<double>(2, 0) = 0; // Tangential first order distCoeffs.at<double>(3, 0) = 0; // Tangential second order distCoeffs.at<double>(4, 0) = 0; // Radial third order - distCoeffs.at<double>(5, 0) = camera->info.radialDistortionFourthOrder; // Radial fourth order + distCoeffs.at<double>(5, 0) = iCameraInfo.radialDistortionFourthOrder; // Radial fourth order distCoeffs.at<double>(6, 0) = 0; // Radial fith order - distCoeffs.at<double>(7, 0) = camera->info.radialDistortionSixthOrder; // Radial sixth order + distCoeffs.at<double>(7, 0) = iCameraInfo.radialDistortionSixthOrder; // Radial sixth order // Define our solution arrays // They will receive up to 4 solutions for our P3P problem @@ -287,16 +290,17 @@ void EasyTracker::run() if (topPointIndex != -1) { // Render a cross to indicate which point is the head - preview_frame->draw_head_center(points[topPointIndex][0], points[topPointIndex][1]); + iPreview.draw_head_center(points[topPointIndex][0], points[topPointIndex][1]); } - widget->update_image(preview_frame->get_bitmap()); + widget->update_image(iPreview.get_bitmap()); auto [ w, h ] = widget->preview_size(); if (w != preview_width || h != preview_height) { + // Resize preivew if widget size has changed preview_width = w; preview_height = h; - preview_frame = traits->make_preview(w, h); + iPreview = Preview(w, h); } } } @@ -307,14 +311,13 @@ bool EasyTracker::maybe_reopen_camera() { QMutexLocker l(&camera_mtx); - return camera->start(s.camera_name, - s.cam_fps, s.cam_res_x, s.cam_res_y); + return camera->start(iCameraInfo); } void EasyTracker::set_fov(int value) { QMutexLocker l(&camera_mtx); - camera->set_fov(value); + } module_status EasyTracker::start_tracker(QFrame* video_frame) @@ -329,6 +332,9 @@ module_status EasyTracker::start_tracker(QFrame* video_frame) //video_widget->resize(video_frame->width(), video_frame->height()); video_frame->show(); + // Create our camera + camera = video::make_camera(s.camera_name); + start(QThread::HighPriority); return {}; @@ -361,14 +367,6 @@ int EasyTracker::get_n_points() return (int)point_count.load(std::memory_order_relaxed); } -bool EasyTracker::get_cam_info(pt_camera_info& info) -{ - QMutexLocker l(&camera_mtx); - bool ret; - - std::tie(ret, info) = camera->get_info(); - return ret; -} } // ns pt_impl diff --git a/tracker-easy/tracker-easy.h b/tracker-easy/tracker-easy.h index fe99ba85..03e603bd 100644 --- a/tracker-easy/tracker-easy.h +++ b/tracker-easy/tracker-easy.h @@ -12,6 +12,8 @@ #include "tracker-easy-api.h" #include "cv/numeric.hpp" #include "video/video-widget.hpp" +#include "video/camera.hpp" +#include "frame.hpp" #include <atomic> #include <memory> @@ -42,7 +44,6 @@ struct EasyTracker : QThread, ITracker bool center() override; int get_n_points(); - [[nodiscard]] bool get_cam_info(pt_camera_info& info); private: void run() override; @@ -64,10 +65,13 @@ private: int preview_width = 320, preview_height = 240; pointer<pt_point_extractor> point_extractor; - pointer<pt_camera> camera; + std::unique_ptr<video::impl::camera> camera; + video::impl::camera::info iCameraInfo; pointer<video_widget> widget; - pointer<pt_frame> frame; - pointer<pt_preview> preview_frame; + + video::frame iFrame; + cv::Mat iMatFrame; + Preview iPreview; std::atomic<unsigned> point_count { 0 }; std::atomic<bool> ever_success = false; diff --git a/video/camera.hpp b/video/camera.hpp index be9ef711..c8eff3b9 100644 --- a/video/camera.hpp +++ b/video/camera.hpp @@ -23,6 +23,7 @@ struct frame final // the `stride' member can have a special value of zero, // signifying equal to width * element size int width = 0, height = 0, stride = 0, channels = 0; + // TODO: Add channel size instead of assuming 1 byte }; } // ns video |