From 0d16a9befb05858d1857bb2e06912a28b1c3e805 Mon Sep 17 00:00:00 2001 From: gpsinghsandhu Date: Sat, 30 Mar 2013 00:33:22 +0530 Subject: [PATCH 1/2] In response to Bug #2927 change to reject contours with moms.m00 = 0.0 --- modules/features2d/src/blobdetector.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/features2d/src/blobdetector.cpp b/modules/features2d/src/blobdetector.cpp index 3f50f3c1af..7b633eef48 100644 --- a/modules/features2d/src/blobdetector.cpp +++ b/modules/features2d/src/blobdetector.cpp @@ -240,6 +240,13 @@ void SimpleBlobDetector::findBlobs(const cv::Mat &image, const cv::Mat &binaryIm continue; } + bool blob_valid = true; + + if (moms.m00 == 0.0) + { + blob_valid = false; + } + center.location = Point2d(moms.m10 / moms.m00, moms.m01 / moms.m00); if (params.filterByColor) @@ -260,7 +267,10 @@ void SimpleBlobDetector::findBlobs(const cv::Mat &image, const cv::Mat &binaryIm center.radius = (dists[(dists.size() - 1) / 2] + dists[dists.size() / 2]) / 2.; } - centers.push_back(center); + if (blob_valid) + { + centers.push_back(center); + } #ifdef DEBUG_BLOB_DETECTOR // circle( keypointsImage, center.location, 1, Scalar(0,0,255), 1 ); From 77e51ff9c4a49306aa741a79bef153ca804f6ae3 Mon Sep 17 00:00:00 2001 From: gpsinghsandhu Date: Sun, 31 Mar 2013 16:13:40 +0530 Subject: [PATCH 2/2] contours with zero area rejected reject contours with zero area by using the "continue" statement to be in sync with the condition checking style used in the whole file --- modules/features2d/src/blobdetector.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/modules/features2d/src/blobdetector.cpp b/modules/features2d/src/blobdetector.cpp index 7b633eef48..785651fe38 100644 --- a/modules/features2d/src/blobdetector.cpp +++ b/modules/features2d/src/blobdetector.cpp @@ -239,13 +239,6 @@ void SimpleBlobDetector::findBlobs(const cv::Mat &image, const cv::Mat &binaryIm if (ratio < params.minConvexity || ratio >= params.maxConvexity) continue; } - - bool blob_valid = true; - - if (moms.m00 == 0.0) - { - blob_valid = false; - } center.location = Point2d(moms.m10 / moms.m00, moms.m01 / moms.m00); @@ -267,10 +260,10 @@ void SimpleBlobDetector::findBlobs(const cv::Mat &image, const cv::Mat &binaryIm center.radius = (dists[(dists.size() - 1) / 2] + dists[dists.size() / 2]) / 2.; } - if (blob_valid) - { - centers.push_back(center); - } + if(moms.m00 == 0.0) + continue; + centers.push_back(center); + #ifdef DEBUG_BLOB_DETECTOR // circle( keypointsImage, center.location, 1, Scalar(0,0,255), 1 );