diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-09-25 09:02:07 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-09-25 09:10:46 +0200 |
commit | 39a4e610f0b29f80ff619c93e1e1e6424c896dd6 (patch) | |
tree | d82bd6e4fdc07e57494b137488f63b929c41a674 /tracker-pt | |
parent | ed3dbca662b9d282589d04464ed4ea5ee9d6efc7 (diff) |
tracker/pt: square the center weight
Follow original implementation.
Diffstat (limited to 'tracker-pt')
-rw-r--r-- | tracker-pt/point_extractor.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp index 274c0ccb..ce3edb4a 100644 --- a/tracker-pt/point_extractor.cpp +++ b/tracker-pt/point_extractor.cpp @@ -108,9 +108,13 @@ void PointExtractor::extract_points(cv::Mat& frame, std::vector<vec2>& points) cv::Scalar(0), cv::Scalar(0), 8); - int m00 = 0; - int m10 = 0; - int m01 = 0; + + // these are doubles since m10 and m01 could overflow theoretically + // log2(255^2 * 640^2 * pi) > 36 + double m10 = 0; + double m01 = 0; + // norm can't overflow since there's no 640^2 component + int norm = 0; int cnt = 0; for (int i=rect.y; i < (rect.y+rect.height); i++) @@ -119,22 +123,26 @@ void PointExtractor::extract_points(cv::Mat& frame, std::vector<vec2>& points) const unsigned char* ptr_gray = frame_gray.ptr(i); for (int j=rect.x; j < (rect.x+rect.width); j++) { - if (ptr_blobs[j] != idx) continue; + if (ptr_blobs[j] != idx) + continue; + ptr_blobs[j] = 0; - const int val = int(ptr_gray[j]); - m00 += val; + + // square as a weight gives better results + const int val(int(ptr_gray[j]) * int(ptr_gray[j])); + + norm += val; m01 += i * val; m10 += j * val; cnt++; } } - if (m00 > 0) + if (norm > 1e0) { const double radius = sqrt(cnt / M_PI); if (radius > region_size_max || radius < region_size_min) continue; - const double norm = double(m00); - blob b(radius, cv::Vec2d(m10 / norm, m01 / norm), m00/sqrt(double(cnt))); + blob b(radius, cv::Vec2d(m10 / norm, m01 / norm), norm/sqrt(double(cnt))); blobs.push_back(b); { char buf[64]; |