diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-06-10 12:50:25 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-06-10 12:50:25 +0200 |
commit | d415d383db1e1cf8038ffb34459864e3b6e19f39 (patch) | |
tree | 888cfaaab4733269b4342ea0337460f774c87023 /tracker-pt | |
parent | 1a4ad209341b7ef2364f7b6bc8195a4ac93838d0 (diff) |
minor cleanup only
Diffstat (limited to 'tracker-pt')
-rw-r--r-- | tracker-pt/camera.cpp | 35 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.cpp | 14 |
2 files changed, 26 insertions, 23 deletions
diff --git a/tracker-pt/camera.cpp b/tracker-pt/camera.cpp index 6a724fc7..b68fd107 100644 --- a/tracker-pt/camera.cpp +++ b/tracker-pt/camera.cpp @@ -7,6 +7,7 @@ #include "camera.h" #include "compat/sleep.hpp" +#include "compat/camera-names.hpp" constexpr double Camera::dt_eps; @@ -46,7 +47,7 @@ DEFUN_WARN_UNUSED Camera::result Camera::get_info() const DEFUN_WARN_UNUSED Camera::result Camera::get_frame(cv::Mat& frame) { - bool new_frame = _get_frame(frame); + const bool new_frame = _get_frame(frame); if (new_frame) { @@ -66,23 +67,26 @@ DEFUN_WARN_UNUSED Camera::result Camera::get_frame(cv::Mat& frame) cam_info.res_x = frame.cols; cam_info.res_y = frame.rows; cam_info.fov = fov; + + return result(true, cam_info); } else - qDebug() << "pt camera: can't get frame"; - - return result(new_frame, cam_info); + return result(false, CamInfo()); } DEFUN_WARN_UNUSED Camera::open_status Camera::start(int idx, int fps, int res_x, int res_y) { if (idx >= 0 && fps >= 0 && res_x >= 0 && res_y >= 0) { - if (!cap || !cap->isOpened() || - cam_desired.idx != idx || + if (cam_desired.idx != idx || cam_desired.fps != fps || cam_desired.res_x != res_x || - cam_desired.res_y != res_y) + cam_desired.res_y != res_y || + !cap || !cap->isOpened() || !cap->grab()) { + stop(); + + desired_name = get_camera_names().value(idx); cam_desired.idx = idx; cam_desired.fps = fps; cam_desired.res_x = res_x; @@ -98,15 +102,14 @@ DEFUN_WARN_UNUSED Camera::open_status Camera::start(int idx, int fps, int res_x, if (cam_desired.fps) cap->set(cv::CAP_PROP_FPS, cam_desired.fps); - if (cap->isOpened()) + if (cap->isOpened() && cap->grab()) { - qDebug() << "pt: opening camera"; - cam_info = CamInfo(); active_name = QString(); cam_info.idx = -1; dt_mean = 0; active_name = desired_name; + t.start(); return open_ok_change; @@ -117,14 +120,12 @@ DEFUN_WARN_UNUSED Camera::open_status Camera::start(int idx, int fps, int res_x, return open_error; } } - } - else - { - stop(); - return open_error; + + return open_ok_no_change; } - return open_ok_no_change; + stop(); + return open_error; } void Camera::stop() @@ -144,7 +145,7 @@ DEFUN_WARN_UNUSED bool Camera::_get_frame(cv::Mat& frame) { if (cap->read(frame)) return true; - portable::sleep(14); + portable::sleep(1); } } return false; diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index 36eabcc9..2862efdb 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -59,16 +59,16 @@ void Tracker_PT::run() QTextStream log_stream(&log_file); #endif - maybe_reopen_camera(); - while((commands & ABORT) == 0) { CamInfo cam_info; - bool new_frame; + bool new_frame = false; { QMutexLocker l(&camera_mtx); - std::tie(new_frame, cam_info) = camera.get_frame(frame); + + if (likely(camera)) + std::tie(new_frame, cam_info) = camera.get_frame(frame); } if (new_frame) @@ -136,7 +136,6 @@ void Tracker_PT::maybe_reopen_camera() switch (status) { case Camera::open_error: - qDebug() << "can't start camera" << s.camera_name; break; case Camera::open_ok_change: frame = cv::Mat(); @@ -167,7 +166,10 @@ void Tracker_PT::start_tracker(QFrame* video_frame) video_frame->setLayout(layout.data()); //video_widget->resize(video_frame->width(), video_frame->height()); video_frame->show(); - start(); + + maybe_reopen_camera(); + + start(QThread::HighPriority); } void Tracker_PT::data(double *data) |