summaryrefslogtreecommitdiffhomepage
path: root/tracker-pt/camera.h
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-12-16 11:54:21 +0100
committerStanislaw Halik <sthalik@misaki.pl>2016-12-16 11:54:21 +0100
commit4d62adf8bc4f78f8dca8196c7f52a6a44cc5829a (patch)
tree8b07b851c334ed80054d53e11ab1f9258c76bc02 /tracker-pt/camera.h
parentfc24671937724beb3fde6c6edfc1c124fbb0ef75 (diff)
tracker/pt: refactor camera info handling
- Pass `struct CamInfo' rather than several elements separately - Reformat - Return `struct CamInfo' together with the frame since then it's always valid - Move the focal length formula into `struct CamInfo' - Remove incorrect focal length formula rather than #if 0 - Pass some stuff by reference and not by pointer
Diffstat (limited to 'tracker-pt/camera.h')
-rw-r--r--tracker-pt/camera.h75
1 files changed, 46 insertions, 29 deletions
diff --git a/tracker-pt/camera.h b/tracker-pt/camera.h
index 3f5a8f43..1d3b332c 100644
--- a/tracker-pt/camera.h
+++ b/tracker-pt/camera.h
@@ -10,17 +10,27 @@
#undef NDEBUG
#include <cassert>
+#include "numeric.hpp"
+#include "ftnoir_tracker_pt_settings.h"
+
#include "compat/util.hpp"
#include <opencv2/core/core.hpp>
-#include <memory>
#include <opencv2/videoio.hpp>
-#include <string>
+
+#include <memory>
#include <QString>
-struct CamInfo
+namespace impl {
+
+using namespace types;
+
+struct CamInfo final
{
- CamInfo() : res_x(0), res_y(0), fps(-1), idx(-1) {}
+ CamInfo() : fov(0), res_x(0), res_y(0), fps(-1), idx(-1) {}
+ void get_focal_length(f& fx) const;
+
+ double fov;
int res_x;
int res_y;
@@ -31,40 +41,47 @@ struct CamInfo
class Camera final
{
public:
- Camera() : dt_valid(0), dt_mean(0) {}
+ Camera() : dt_valid(0), dt_mean(0) {}
- DEFUN_WARN_UNUSED bool start(int idx, int fps, int res_x, int res_y);
- void stop();
+ DEFUN_WARN_UNUSED bool start(int idx, int fps, int res_x, int res_y);
+ void stop();
- DEFUN_WARN_UNUSED bool get_frame(double dt, cv::Mat* frame);
- DEFUN_WARN_UNUSED bool get_info(CamInfo &ret);
+ DEFUN_WARN_UNUSED bool get_frame(double dt, cv::Mat& frame, CamInfo& info);
+ DEFUN_WARN_UNUSED bool get_info(CamInfo &ret) const;
- CamInfo get_desired() const { return cam_desired; }
- QString get_desired_name() const;
- QString get_active_name() const;
+ CamInfo get_desired() const { return cam_desired; }
+ QString get_desired_name() const;
+ QString get_active_name() const;
- cv::VideoCapture& operator*() { assert(cap); return *cap; }
- const cv::VideoCapture& operator*() const { assert(cap); return *cap; }
- cv::VideoCapture* operator->() { assert(cap); return cap.get(); }
- const cv::VideoCapture* operator->() const { return cap.get(); }
- operator bool() const { return cap && cap->isOpened(); }
+ cv::VideoCapture& operator*() { assert(cap); return *cap; }
+ const cv::VideoCapture& operator*() const { assert(cap); return *cap; }
+ cv::VideoCapture* operator->() { assert(cap); return cap.get(); }
+ const cv::VideoCapture* operator->() const { return cap.get(); }
+ operator bool() const { return cap && cap->isOpened(); }
private:
- DEFUN_WARN_UNUSED bool _get_frame(cv::Mat* frame);
+ DEFUN_WARN_UNUSED bool _get_frame(cv::Mat& frame);
+
+ settings_pt s;
- double dt_valid;
- double dt_mean;
+ double dt_valid;
+ double dt_mean;
- CamInfo cam_info;
- CamInfo cam_desired;
- QString desired_name, active_name;
+ CamInfo cam_info;
+ CamInfo cam_desired;
+ QString desired_name, active_name;
- struct camera_deleter final
- {
- void operator()(cv::VideoCapture* cap);
- };
+ struct camera_deleter final
+ {
+ void operator()(cv::VideoCapture* cap);
+ };
- using camera_ptr = std::unique_ptr<cv::VideoCapture, camera_deleter>;
+ using camera_ptr = std::unique_ptr<cv::VideoCapture, camera_deleter>;
- camera_ptr cap;
+ camera_ptr cap;
};
+
+} // ns impl
+
+using impl::Camera;
+using impl::CamInfo;