From cd7a0ea05cdc8fba78fde89a5c8365f9919b75bd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 9 Jan 2016 02:18:09 +0100 Subject: tracker/pt: remove unused blob struct members --- tracker-pt/point_extractor.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'tracker-pt') diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp index 0208b11d..0be600f5 100644 --- a/tracker-pt/point_extractor.cpp +++ b/tracker-pt/point_extractor.cpp @@ -39,17 +39,10 @@ const std::vector& PointExtractor::extract_points(cv::Mat& frame) double radius; cv::Vec2d pos; double confid; - bool taken; - double area; - blob(double radius, const cv::Vec2d& pos, double confid, double area) : radius(radius), pos(pos), confid(confid), taken(false), area(area) + 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; } - bool inside(const blob& other) - { - cv::Vec2d tmp = pos - other.pos; - return sqrt(tmp.dot(tmp)) < radius; - } }; // mask for everything that passes the threshold (or: the upper threshold of the hysteresis) @@ -103,9 +96,6 @@ const std::vector& PointExtractor::extract_points(cv::Mat& frame) break; const auto m = cv::moments(cv::Mat(c)); - const double area = m.m00; - if (area == 0.) - continue; const cv::Vec2d pos(m.m10 / m.m00, m.m01 / m.m00); double radius; @@ -147,7 +137,7 @@ const std::vector& PointExtractor::extract_points(cv::Mat& frame) cv::putText(frame, buf, cv::Point(pos[0]+30, pos[1]+20), cv::FONT_HERSHEY_DUPLEX, 1, cv::Scalar(0, 0, 255), 1); } - blobs.push_back(blob(radius, pos, confid, area)); + blobs.push_back(blob(radius, pos, confid)); enum { max_blobs = 16 }; -- cgit v1.2.3 From fc90d78e179fbc8b1c87a64e49eabffda19fb871 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 9 Feb 2016 23:57:15 +0100 Subject: gui: scale properly on high-DPI screens Previously high DPI made the main screen all out of whack, unreadable and unusable. --- gui/images/no-feed.png | Bin 4471 -> 4145 bytes gui/main.ui | 375 +++++++++++++++++++++------------------ tracker-pt/FTNoIR_PT_Controls.ui | 6 + 3 files changed, 213 insertions(+), 168 deletions(-) (limited to 'tracker-pt') diff --git a/gui/images/no-feed.png b/gui/images/no-feed.png index 02aa227a..80c68f16 100644 Binary files a/gui/images/no-feed.png and b/gui/images/no-feed.png differ diff --git a/gui/main.ui b/gui/main.ui index 689c4c23..3a034ab0 100644 --- a/gui/main.ui +++ b/gui/main.ui @@ -7,8 +7,8 @@ 0 0 - 646 - 492 + 652 + 498 @@ -72,7 +72,7 @@ - + 0 0 @@ -159,7 +159,7 @@ :/images/no-feed.png - true + false @@ -853,168 +853,6 @@ 6 - - - - - 4 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 2 - - - 3 - - - 2 - - - 3 - - - 8 - - - - - Tracker - - - - 4 - - - 0 - - - 4 - - - 0 - - - 3 - - - 0 - - - - - - - - true - - - ... - - - false - - - - - - - - - - Protocol - - - - 4 - - - 0 - - - 4 - - - 0 - - - 3 - - - 0 - - - - - - - - true - - - ... - - - false - - - - - - - - - - Filter - - - - 4 - - - 0 - - - 4 - - - 0 - - - 3 - - - 0 - - - - - - - - true - - - ... - - - false - - - - - - - - - @@ -1165,7 +1003,7 @@ - + 0 0 @@ -1181,7 +1019,7 @@ false - + 0 0 @@ -1197,6 +1035,207 @@ + + + + + 4 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 2 + + + 3 + + + 2 + + + 3 + + + 8 + + + + + Tracker + + + + 4 + + + 0 + + + 4 + + + 0 + + + 3 + + + 0 + + + + + + 0 + 0 + + + + + + + + true + + + + 0 + 0 + + + + ... + + + false + + + + + + + + + + Protocol + + + + 4 + + + 0 + + + 4 + + + 0 + + + 3 + + + 0 + + + + + + 0 + 0 + + + + + + + + true + + + + 0 + 0 + + + + ... + + + false + + + + + + + + + + Filter + + + + 4 + + + 0 + + + 4 + + + 0 + + + 3 + + + 0 + + + + + + 0 + 0 + + + + + + + + true + + + + 0 + 0 + + + + ... + + + false + + + + + + + + + diff --git a/tracker-pt/FTNoIR_PT_Controls.ui b/tracker-pt/FTNoIR_PT_Controls.ui index 88575644..75190a5e 100644 --- a/tracker-pt/FTNoIR_PT_Controls.ui +++ b/tracker-pt/FTNoIR_PT_Controls.ui @@ -331,6 +331,12 @@ + + + 0 + 0 + + Intensity threshold for point extraction -- cgit v1.2.3 From 925c0811d6b24069eb9f527c2c02301cc1ba5ca4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 17 Feb 2016 04:36:31 +0100 Subject: tracker/pt: cover all "points" usages by a mutex --- tracker-pt/point_extractor.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tracker-pt') diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp index 0be600f5..da05feb3 100644 --- a/tracker-pt/point_extractor.cpp +++ b/tracker-pt/point_extractor.cpp @@ -148,10 +148,8 @@ const std::vector& PointExtractor::extract_points(cv::Mat& frame) using b = const blob; std::sort(blobs.begin(), blobs.end(), [](b& b1, b& b2) {return b1.confid > b2.confid;}); - points.reserve(blobs.size()); - QMutexLocker l(&mtx); - + points.reserve(blobs.size()); points.clear(); for (auto& b : blobs) -- cgit v1.2.3 From 38306b389951c69d050e3e4b929b442b5bd0ada5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 17 Feb 2016 04:40:53 +0100 Subject: tracker/pt: protect get_n_points() There's a race here since further accesses to the points array aren't protected by a mutex in the extractor class. There's no race in "get_points()" in the extractor since it's only used in same thread where updates take place. --- tracker-pt/ftnoir_tracker_pt.h | 2 +- tracker-pt/point_extractor.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'tracker-pt') diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h index dff0c30a..5f30c66f 100644 --- a/tracker-pt/ftnoir_tracker_pt.h +++ b/tracker-pt/ftnoir_tracker_pt.h @@ -41,7 +41,7 @@ public: void data(double* data) override; Affine pose() { return point_tracker.pose(); } - int get_n_points() { return point_extractor.get_points().size(); } + int get_n_points() { return point_extractor.get_n_points(); } bool get_cam_info(CamInfo* info) { QMutexLocker lock(&camera_mtx); return camera.get_info(*info); } public slots: void apply_settings(); diff --git a/tracker-pt/point_extractor.h b/tracker-pt/point_extractor.h index 030251ff..8bcc2437 100644 --- a/tracker-pt/point_extractor.h +++ b/tracker-pt/point_extractor.h @@ -23,6 +23,7 @@ public: // WARNING: returned reference is valid as long as object const std::vector &extract_points(cv::Mat &frame); const std::vector& get_points() { QMutexLocker l(&mtx); return points; } + int get_n_points() const { QMutexLocker l(&mtx); return points.size(); } PointExtractor(); settings_pt s; -- cgit v1.2.3 From bf4e8b10ad916b6451dc32b9be2b86d42452e7e8 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 17 Feb 2016 04:42:20 +0100 Subject: tracker/pt: retire get_points() in the extractor --- tracker-pt/point_extractor.h | 1 - 1 file changed, 1 deletion(-) (limited to 'tracker-pt') diff --git a/tracker-pt/point_extractor.h b/tracker-pt/point_extractor.h index 8bcc2437..479b6844 100644 --- a/tracker-pt/point_extractor.h +++ b/tracker-pt/point_extractor.h @@ -22,7 +22,6 @@ public: // dt: time since last call in seconds // WARNING: returned reference is valid as long as object const std::vector &extract_points(cv::Mat &frame); - const std::vector& get_points() { QMutexLocker l(&mtx); return points; } int get_n_points() const { QMutexLocker l(&mtx); return points.size(); } PointExtractor(); -- cgit v1.2.3 From 1a6b611b2fa64cc730f8f8ea7a716d6b5af1461e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 17 Feb 2016 04:42:56 +0100 Subject: tracker/pt: fix build --- tracker-pt/point_extractor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tracker-pt') diff --git a/tracker-pt/point_extractor.h b/tracker-pt/point_extractor.h index 479b6844..ab51762d 100644 --- a/tracker-pt/point_extractor.h +++ b/tracker-pt/point_extractor.h @@ -22,7 +22,7 @@ public: // dt: time since last call in seconds // WARNING: returned reference is valid as long as object const std::vector &extract_points(cv::Mat &frame); - int get_n_points() const { QMutexLocker l(&mtx); return points.size(); } + int get_n_points() { QMutexLocker l(&mtx); return points.size(); } PointExtractor(); settings_pt s; -- cgit v1.2.3 From 99fb0282ba5cdfdb2b889df8916b36207d21ded0 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 6 Mar 2016 09:11:19 +0100 Subject: tracker/pt: less malloc/free each frame --- tracker-pt/point_extractor.cpp | 29 ++++++----------------------- tracker-pt/point_extractor.h | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'tracker-pt') 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& PointExtractor::extract_points(cv::Mat& frame) @@ -34,23 +36,10 @@ const std::vector& 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 blobs; - std::vector> 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& 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& 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& 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 #include "ftnoir_tracker_pt_settings.h" - #include +#include + 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 blobs; + std::vector> contours; }; #endif //POINTEXTRACTOR_H -- cgit v1.2.3 From 611a6df71f8ec2a0f742ad09a89668f684806d39 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 6 Mar 2016 09:12:46 +0100 Subject: tracker/pt: remove branching that's frequently mispredicted --- tracker-pt/point_tracker.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tracker-pt') diff --git a/tracker-pt/point_tracker.cpp b/tracker-pt/point_tracker.cpp index aa6feb5b..599ce2d3 100644 --- a/tracker-pt/point_tracker.cpp +++ b/tracker-pt/point_tracker.cpp @@ -202,7 +202,8 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float else { rho = sqrt(sqrt( (JJ0-II0)*(JJ0-II0) + 4*IJ0*IJ0 )); theta = atan( -2*IJ0 / (JJ0-II0) ); - if (JJ0 - II0 < 0) theta += PI; + // avoid branch misprediction + theta += (JJ0 - II0 < 0) * PI; theta /= 2; } -- cgit v1.2.3 From a40a557caddad5285bd03b79dca5f7a94d1f44c5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 6 Mar 2016 09:13:49 +0100 Subject: tracker/pt: don't use exact float comparison in POSIT --- tracker-pt/point_tracker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tracker-pt') diff --git a/tracker-pt/point_tracker.cpp b/tracker-pt/point_tracker.cpp index 599ce2d3..25240635 100644 --- a/tracker-pt/point_tracker.cpp +++ b/tracker-pt/point_tracker.cpp @@ -194,7 +194,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float float IJ0 = I0.dot(J0); float JJ0 = J0.dot(J0); float rho, theta; - if (JJ0 == II0) { + if (std::abs(JJ0 - II0) < 1e-6f) { rho = std::sqrt(std::abs(2*IJ0)); theta = -PI/4; if (IJ0<0) theta *= -1; -- cgit v1.2.3