diff options
Diffstat (limited to 'tracker-pt/module/camera.cpp')
-rw-r--r-- | tracker-pt/module/camera.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/tracker-pt/module/camera.cpp b/tracker-pt/module/camera.cpp index e2edfcb6..1afecc92 100644 --- a/tracker-pt/module/camera.cpp +++ b/tracker-pt/module/camera.cpp @@ -18,7 +18,7 @@ #include <cstdlib> -using namespace pt_module; +namespace pt_module { Camera::Camera(const QString& module_name) : s { module_name } { @@ -56,16 +56,16 @@ Camera::result Camera::get_frame(pt_frame& frame_) { cv::Mat& frame = frame_.as<Frame>()->mat; - const bool new_frame = _get_frame(frame); + const bool new_frame = get_frame_(frame); if (new_frame) { - const double dt = t.elapsed_seconds(); + const f dt = (f)t.elapsed_seconds(); t.start(); // measure fps of valid frames - constexpr double RC = .1; // seconds - const double alpha = dt/(dt + RC); + constexpr f RC = f{1}/10; // seconds + const f alpha = dt/(dt + RC); if (dt_mean < dt_eps) dt_mean = dt; @@ -88,7 +88,7 @@ bool Camera::start(int idx, int fps, int res_x, int res_y) if (idx >= 0 && fps >= 0 && res_x >= 0 && res_y >= 0) { if (cam_desired.idx != idx || - cam_desired.fps != fps || + (int)cam_desired.fps != fps || cam_desired.res_x != res_x || cam_desired.res_y != res_y || !cap || !cap->isOpened() || !cap->grab()) @@ -104,10 +104,12 @@ bool Camera::start(int idx, int fps, int res_x, int res_y) cap = camera_ptr(new cv::VideoCapture(idx)); - if (cam_desired.res_x) + if (cam_desired.res_x > 0 && cam_desired.res_y > 0) + { cap->set(cv::CAP_PROP_FRAME_WIDTH, res_x); - if (cam_desired.res_y) cap->set(cv::CAP_PROP_FRAME_HEIGHT, res_y); + } + if (fps > 0) cap->set(cv::CAP_PROP_FPS, fps); @@ -120,7 +122,7 @@ bool Camera::start(int idx, int fps, int res_x, int res_y) cv::Mat tmp; - if (_get_frame(tmp)) + if (get_frame_(tmp)) { t.start(); return true; @@ -141,13 +143,13 @@ bool Camera::start(int idx, int fps, int res_x, int res_y) void Camera::stop() { cap = nullptr; - desired_name = QString(); - active_name = QString(); - cam_info = pt_camera_info(); - cam_desired = pt_camera_info(); + desired_name = QString{}; + active_name = QString{}; + cam_info = {}; + cam_desired = {}; } -bool Camera::_get_frame(cv::Mat& frame) +bool Camera::get_frame_(cv::Mat& frame) { if (cap && cap->isOpened()) { @@ -171,3 +173,4 @@ void Camera::camera_deleter::operator()(cv::VideoCapture* cap) } } +} // ns pt_module |