diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-03-06 09:11:19 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-03-07 00:35:36 +0100 |
commit | 99fb0282ba5cdfdb2b889df8916b36207d21ded0 (patch) | |
tree | 2281ba7bf6dd94e2e5ddfab94c7bc12873df4776 | |
parent | 68132ca8a66d5757bc42aebeb64a9e2bea53f5ac (diff) |
tracker/pt: less malloc/free each frame
-rw-r--r-- | tracker-pt/point_extractor.cpp | 29 | ||||
-rw-r--r-- | tracker-pt/point_extractor.h | 19 |
2 files changed, 24 insertions, 24 deletions
diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp index da05feb3..a1294c1e 100644 --- a/tracker-pt/point_extractor.cpp +++ b/tracker-pt/point_extractor.cpp @@ -15,6 +15,8 @@ PointExtractor::PointExtractor() { + blobs.reserve(max_blobs); + points.reserve(max_blobs); } const std::vector<cv::Vec2f>& PointExtractor::extract_points(cv::Mat& frame) @@ -34,23 +36,10 @@ const std::vector<cv::Vec2f>& PointExtractor::extract_points(cv::Mat& frame) const double region_size_min = s.min_point_size; const double region_size_max = s.max_point_size; - struct blob - { - double radius; - cv::Vec2d pos; - double confid; - blob(double radius, const cv::Vec2d& pos, double confid) : radius(radius), pos(pos), confid(confid) - { - //qDebug() << "radius" << radius << "pos" << pos[0] << pos[1] << "confid" << confid; - } - }; - - // mask for everything that passes the threshold (or: the upper threshold of the hysteresis) - - std::vector<blob> blobs; - std::vector<std::vector<cv::Point>> contours; - const int thres = s.threshold; + + contours.clear(); + if (!s.auto_threshold) { cv::threshold(frame_gray, frame_bin, thres, 255, cv::THRESH_BINARY); @@ -88,13 +77,10 @@ const std::vector<cv::Vec2f>& PointExtractor::extract_points(cv::Mat& frame) cv::findContours(frame_bin, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); } - int cnt = 0; + blobs.clear(); for (auto& c : contours) { - if (cnt++ > 30) - break; - const auto m = cv::moments(cv::Mat(c)); const cv::Vec2d pos(m.m10 / m.m00, m.m01 / m.m00); @@ -139,8 +125,6 @@ const std::vector<cv::Vec2f>& PointExtractor::extract_points(cv::Mat& frame) blobs.push_back(blob(radius, pos, confid)); - enum { max_blobs = 16 }; - if (blobs.size() == max_blobs) break; } @@ -149,7 +133,6 @@ const std::vector<cv::Vec2f>& PointExtractor::extract_points(cv::Mat& frame) std::sort(blobs.begin(), blobs.end(), [](b& b1, b& b2) {return b1.confid > b2.confid;}); QMutexLocker l(&mtx); - points.reserve(blobs.size()); points.clear(); for (auto& b : blobs) diff --git a/tracker-pt/point_extractor.h b/tracker-pt/point_extractor.h index ab51762d..3e4661f9 100644 --- a/tracker-pt/point_extractor.h +++ b/tracker-pt/point_extractor.h @@ -12,9 +12,10 @@ #include <opencv2/imgproc/imgproc.hpp> #include "ftnoir_tracker_pt_settings.h" - #include <QMutex> +#include <vector> + class PointExtractor { public: @@ -33,6 +34,22 @@ private: cv::Mat frame_gray; cv::Mat frame_bin; cv::Mat hist; + + enum { max_blobs = 16 }; + + struct blob + { + double radius; + cv::Vec2d pos; + double confid; + blob(double radius, const cv::Vec2d& pos, double confid) : radius(radius), pos(pos), confid(confid) + { + //qDebug() << "radius" << radius << "pos" << pos[0] << pos[1] << "confid" << confid; + } + }; + + std::vector<blob> blobs; + std::vector<std::vector<cv::Point>> contours; }; #endif //POINTEXTRACTOR_H |