summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-07-25 14:29:44 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-07-25 14:29:44 +0200
commit3bfbf03e7d5f9cf1684c270fd0522ec789c64c88 (patch)
treea5e5a2b88e9d8ab1b68e6aa490b5dae44ab978fc
parentb1eaaf0e41089183b77979622b36946ae46a6553 (diff)
tracker/pt: compute blob weight
The formula is total brightness over sqrt(radius).
-rw-r--r--tracker-pt/point_extractor.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp
index d12b61a0..29f68bdb 100644
--- a/tracker-pt/point_extractor.cpp
+++ b/tracker-pt/point_extractor.cpp
@@ -41,7 +41,7 @@ corresponding location is a good candidate for the extracted point.
The idea similar to the window scaling suggested in Berglund et al. "Fast, bias-free
algorithm for tracking single particles with variable size and shape." (2008).
*/
-static cv::Vec2d MeanShiftIteration(const cv::Mat &frame_gray, const vec2 &current_center, f filter_width)
+static cv::Vec2d MeanShiftIteration(const cv::Mat &frame_gray, const vec2 &current_center, f filter_width, f& m_)
{
// Most amazingling this function runs faster with doubles than with floats.
const f s = 1 / filter_width;
@@ -66,6 +66,9 @@ static cv::Vec2d MeanShiftIteration(const cv::Mat &frame_gray, const vec2 &curre
com[1] += i * val;
}
}
+
+ m_ = m;
+
if (m > f(.1))
{
com *= 1 / m;
@@ -137,9 +140,9 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame
blobs.clear();
- // -----
- // start code borrowed from OpenCV's modules/features2d/src/blobdetector.cpp
- // -----
+// -----
+// start code borrowed from OpenCV's modules/features2d/src/blobdetector.cpp
+// -----
contours.clear();
@@ -169,12 +172,13 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame
if (!cv::Point2d(center).inside(cv::Rect2d(rect)))
continue;
- const double value = radius;
-
- blob b(radius, center, value, rect);
-
+ blob b(radius, center, 0, rect);
blobs.push_back(b);
+// -----
+// end of code borrowed from OpenCV's modules/features2d/src/blobdetector.cpp
+// -----
+
static const f offx = 10, offy = 7.5;
const f cx = preview_frame.cols / f(frame.cols),
cy = preview_frame.rows / f(frame.rows),
@@ -199,11 +203,6 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame
cv::Scalar(0, 0, 255),
1);
}
- // -----
- // end of code borrowed from OpenCV's modules/features2d/src/blobdetector.cpp
- // -----
-
- std::sort(blobs.begin(), blobs.end(), [](const blob& b1, const blob& b2) { return b2.value < b1.value; });
const int W = frame.cols;
const int H = frame.rows;
@@ -227,15 +226,19 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame
cv::Vec2d pos_(pos);
#endif
+ f norm;
+
for (int iter = 0; iter < 10; ++iter)
{
- cv::Vec2d com_new = MeanShiftIteration(frame_roi, pos, kernel_radius);
+ cv::Vec2d com_new = MeanShiftIteration(frame_roi, pos, kernel_radius, norm);
cv::Vec2d delta = com_new - pos;
pos = com_new;
if (delta.dot(delta) < 1e-3)
break;
}
+ b.value = norm / sqrt(b.radius);
+
#if defined DEBUG_MEANSHIFT
meanshift_total += sqrt((pos_ - pos).dot(pos_ - pos));
#endif
@@ -251,6 +254,8 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame
qDebug() << "meanshift adjust total" << meanshift_total;
#endif
+ std::sort(blobs.begin(), blobs.end(), [](const blob& b1, const blob& b2) { return b2.value < b1.value; });
+
// End of mean shift code. At this point, blob positions are updated with hopefully less noisy, less biased values.
points.reserve(max_blobs);
points.clear();