From f4647a9960f531829f1add40554442a7c84d82a6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 19 Dec 2015 20:46:10 +0100 Subject: tracker/pt: don't allocate temporary dynamic size arrays --- tracker-pt/point_extractor.cpp | 7 +------ tracker-pt/point_extractor.h | 4 ++++ 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'tracker-pt') diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp index 3808c408..655e1412 100644 --- a/tracker-pt/point_extractor.cpp +++ b/tracker-pt/point_extractor.cpp @@ -29,7 +29,6 @@ const std::vector& PointExtractor::extract_points(cv::Mat& frame) } // convert to grayscale - cv::Mat frame_gray; cv::cvtColor(frame, frame_gray, cv::COLOR_RGB2GRAY); const double region_size_min = s.min_point_size; @@ -61,14 +60,11 @@ const std::vector& PointExtractor::extract_points(cv::Mat& frame) const int thres = s.threshold; if (!s.auto_threshold) { - cv::Mat frame_bin; cv::threshold(frame_gray, frame_bin, thres, 255, cv::THRESH_BINARY); cv::findContours(frame_bin, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); } else { - cv::Mat hist; - constexpr int hist_c = 8; cv::calcHist(std::vector { frame_gray }, std::vector { 0 }, cv::Mat(), @@ -76,7 +72,7 @@ const std::vector& PointExtractor::extract_points(cv::Mat& frame) std::vector { 256/hist_c }, std::vector { 0, 256/hist_c }, false); - const int sz = hist.rows*hist.cols; + const int sz = hist.cols * hist.rows; int val = 0; int cnt = 0; constexpr int min_pixels = 250; @@ -95,7 +91,6 @@ const std::vector& PointExtractor::extract_points(cv::Mat& frame) val *= 240./256.; //qDebug() << "val" << val; - cv::Mat frame_bin; cv::threshold(frame_gray, frame_bin, val, 255, CV_THRESH_BINARY); cv::findContours(frame_bin, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); } diff --git a/tracker-pt/point_extractor.h b/tracker-pt/point_extractor.h index 979cc8b6..ad8955fc 100644 --- a/tracker-pt/point_extractor.h +++ b/tracker-pt/point_extractor.h @@ -27,8 +27,12 @@ public: settings_pt s; private: + enum { hist_c = 8 }; std::vector points; QMutex mtx; + cv::Mat frame_gray; + cv::Mat frame_bin; + cv::Mat hist; }; #endif //POINTEXTRACTOR_H -- cgit v1.2.3