diff options
| -rw-r--r-- | compat/util.hpp | 6 | ||||
| -rw-r--r-- | tracker-pt/camera.cpp | 14 | ||||
| -rw-r--r-- | tracker-pt/camera.h | 13 | 
3 files changed, 22 insertions, 11 deletions
diff --git a/compat/util.hpp b/compat/util.hpp index abcc9ba2..3a28ce90 100644 --- a/compat/util.hpp +++ b/compat/util.hpp @@ -112,3 +112,9 @@ auto run_in_thread_sync(QObject* obj, F&& fun)          cvar.wait(guard);      return traits::pass(std::move(ret));  } + +#if defined(_MSC_VER) && !defined(Q_CREATOR_RUN) +#   define DEFUN_WARN_UNUSED _Check_return_ +#else +#   define DEFUN_WARN_UNUSED __attribute__((warn_unused_result)) +#endif diff --git a/tracker-pt/camera.cpp b/tracker-pt/camera.cpp index f2fdb283..82f4a6fe 100644 --- a/tracker-pt/camera.cpp +++ b/tracker-pt/camera.cpp @@ -10,6 +10,8 @@  #include <string>  #include <QDebug> +Camera::~Camera() {} +  void Camera::set_device(const QString& name)  {      const int index = camera_name_to_index(name); @@ -52,7 +54,7 @@ void Camera::set_res(int x_res, int y_res)      }  } -bool Camera::get_info(CamInfo& ret) +DEFUN_WARN_UNUSED bool Camera::get_info(CamInfo& ret)  {      if (cam_info.res_x == 0 || cam_info.res_y == 0)      { @@ -66,12 +68,16 @@ bool Camera::get_frame(double dt, cv::Mat* frame)  {      bool new_frame = _get_frame(frame);      // measure fps of valid frames -    static constexpr double dt_smoothing_const = 0.95; +    static constexpr double RC = 1; // second +    const double alpha = dt/(dt + RC);      dt_valid += dt;      if (new_frame)      { -        dt_mean = dt_smoothing_const * dt_mean + (1 - dt_smoothing_const) * dt_valid; -        cam_info.fps = int(std::round(dt_mean > 1e-3 ? 1 / dt_mean : 0)); +        if (dt_mean < 2e-3) +            dt_mean = dt; +        else +            dt_mean = alpha * dt_mean + (1 - alpha) * dt_valid; +        cam_info.fps = int(std::round(dt_mean > 2e-3 ? 1 / dt_mean : 0));          dt_valid = 0;      }      else diff --git a/tracker-pt/camera.h b/tracker-pt/camera.h index 323ea647..be7d35c4 100644 --- a/tracker-pt/camera.h +++ b/tracker-pt/camera.h @@ -7,6 +7,8 @@  #pragma once +#include "compat/util.hpp" +  #include <opencv2/core/core.hpp>  #include <memory>  #include <opencv2/videoio.hpp> @@ -41,16 +43,15 @@ public:          void set_res(int x_res, int y_res);          // gets a frame from the camera, dt: time since last call in seconds -        bool get_frame(double dt, cv::Mat* frame); +        DEFUN_WARN_UNUSED bool get_frame(double dt, cv::Mat* frame);          // WARNING: returned references are valid as long as object -        bool get_info(CamInfo &ret); +        DEFUN_WARN_UNUSED bool get_info(CamInfo &ret);          CamInfo get_desired() const { return cam_desired; } -          QString get_desired_name() const;  protected:          // get a frame from the camera -        virtual bool _get_frame(cv::Mat* frame) = 0; +        DEFUN_WARN_UNUSED virtual bool _get_frame(cv::Mat* frame) = 0;          // update the camera using cam_desired, write res and f to cam_info if successful          virtual void _set_device_index() = 0; @@ -66,11 +67,10 @@ protected:          int desired_index;          int active_index;  }; -inline Camera::~Camera() {}  // ----------------------------------------------------------------------------  // camera based on OpenCV's videoCapture -class CVCamera : public Camera +class CVCamera final : public Camera  {  public:      CVCamera() : cap(NULL) {} @@ -80,7 +80,6 @@ public:      void stop() override;      operator cv::VideoCapture*() { return cap; } -  protected:      bool _get_frame(cv::Mat* frame) override;      void _set_fps() override;  | 
