diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-12-19 20:43:24 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-12-19 20:46:26 +0100 |
commit | 90138a999b4c95afeb9a49d355b0234b6145e221 (patch) | |
tree | ec1c749b9837dc3dee7d37dbb8facb38aee4a854 | |
parent | a2ceed01e32fd941e20e1362b6c44af8db05b5b2 (diff) |
tracker/pt: don't allocate temporary frame
-rw-r--r-- | tracker-pt/camera.cpp | 13 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.cpp | 14 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.h | 1 |
3 files changed, 12 insertions, 16 deletions
diff --git a/tracker-pt/camera.cpp b/tracker-pt/camera.cpp index ff721557..600ab26a 100644 --- a/tracker-pt/camera.cpp +++ b/tracker-pt/camera.cpp @@ -110,19 +110,14 @@ bool CVCamera::_get_frame(cv::Mat* frame) { if (cap && cap->isOpened()) { - cv::Mat img; - for (int i = 0; i < 100 && !cap->read(img); i++) + for (int i = 0; i < 100 && !cap->read(*frame); i++) ;; - if (img.empty()) + if (frame->empty()) return false; - if (frame->rows != img.rows || frame->cols != img.cols) - *frame = cv::Mat(); - - *frame = img; - cam_info.res_x = img.cols; - cam_info.res_y = img.rows; + cam_info.res_x = frame->cols; + cam_info.res_y = frame->rows; return true; } return false; diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index 80227a39..9a4fa037 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -14,6 +14,7 @@ #include <QCoreApplication> #include "opentrack-compat/camera-names.hpp" #include "opentrack-compat/sleep.hpp" +#include <functional> //#define PT_PERF_LOG //log performance @@ -78,7 +79,7 @@ void Tracker_PT::run() #endif apply_settings(); - cv::Mat frame; + cv::Mat frame_; while((commands & ABORT) == 0) { @@ -89,9 +90,12 @@ void Tracker_PT::run() { QMutexLocker l(&camera_mtx); new_frame = camera.get_frame(dt, &frame); + if (frame.rows != frame_.rows || frame.cols != frame_.cols) + frame_ = cv::Mat(frame.rows, frame.cols, CV_8UC3); + frame.copyTo(frame_); } - if (new_frame && !frame.empty()) + if (new_frame && !frame_.empty()) { std::vector<cv::Vec2f> points = point_extractor.extract_points(frame); @@ -142,11 +146,6 @@ void Tracker_PT::run() video_widget->update_image(frame); } -#ifdef PT_PERF_LOG - log_stream<<"dt: "<<dt; - if (!frame.empty()) log_stream<<" fps: "<<camera.get_info().fps; - log_stream<<"\n"; -#endif } qDebug()<<"Tracker:: Thread stopping"; } @@ -160,6 +159,7 @@ void Tracker_PT::apply_settings() camera.set_res(s.cam_res_x, s.cam_res_y); camera.set_fps(s.cam_fps); camera.start(); + frame = cv::Mat(); qDebug()<<"Tracker::apply ends"; } diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h index 5ec7ea91..dff0c30a 100644 --- a/tracker-pt/ftnoir_tracker_pt.h +++ b/tracker-pt/ftnoir_tracker_pt.h @@ -69,6 +69,7 @@ private: settings_pt s; Timer time; + cv::Mat frame; volatile bool ever_success; |