From 514883c9b3dfb5821afff579a0aa37731a39156d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20B=C3=BCrki?= Date: Mon, 17 Aug 2020 15:12:18 +0200 Subject: [PATCH 1/2] Add filtering parameter --- src/BlobFinder.cpp | 28 ++++++++++------------------ src/BlobFinder.h | 4 ++-- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/BlobFinder.cpp b/src/BlobFinder.cpp index 5d410dc..85d0cdd 100644 --- a/src/BlobFinder.cpp +++ b/src/BlobFinder.cpp @@ -44,9 +44,9 @@ void BlobFinder::initGUI(ofxGui &gui){ sensorBoxGuiGroup->add(sensorBoxBottom.set("bottom", 1000)); blobGuiGroup = panel->addGroup("Blobs"); + blobGuiGroup->add(filteringRounds.set("FilteringRounds", 1, 0, 3)); blobGuiGroup->add(blobAreaMax.set("AreaMax", 5, 0, 255)); - blobGuiGroup->add(blobAreaMinStp1.set("AreaMinStp1", 10, 0, 255)); - blobGuiGroup->add(blobAreaMinStp2.set("AreaMinStp2", 10, 0, 255)); + blobGuiGroup->add(blobAreaMin.set("AreaMin", 10, 0, 255)); blobGuiGroup->add(countBlob.set("MaxBlobs", 5, 1, N_MAX_BLOBS)); blobGuiGroup->add(eyeLevel.set("EyeLevel", 140, 0, 200)); blobGuiGroup->add(eyeInset.set("EyeInset", .8, 0, 1)); @@ -210,21 +210,13 @@ void BlobFinder::loadMask() { void BlobFinder::filterTrailingPixels() { filteredImage = grayImage; - // close - filteredImage.dilate(); - filteredImage.erode(); - - // open - filteredImage.erode(); - filteredImage.dilate(); - - // close - filteredImage.dilate(); - filteredImage.erode(); - - // open - filteredImage.erode(); - filteredImage.dilate(); + filteredImage.dilate_3x3(); + for (int i = 0; i <= filteringRounds.get(); i++) { + filteredImage.erode_3x3(); + } + for (int i = 0; i <= filteringRounds.get(); i++) { + filteredImage.dilate_3x3(); + } } void BlobFinder::update(){ @@ -297,7 +289,7 @@ void BlobFinder::update(){ FIND BODY CONTOURS *****************************************************************/ - int minBlobSize = pow(blobAreaMinStp1.get() * sensorFboSize.get(), 2); + int minBlobSize = pow(blobAreaMin.get() * sensorFboSize.get(), 2); int maxBlobSize = pow(blobAreaMax.get() * sensorFboSize.get(), 2); detectedHeads.clear(); diff --git a/src/BlobFinder.h b/src/BlobFinder.h index dc6eb2a..f34f0c2 100644 --- a/src/BlobFinder.h +++ b/src/BlobFinder.h @@ -124,8 +124,8 @@ public: ofParameter nearFrustum; ofParameter farFrustum; - ofParameter blobAreaMinStp2; - ofParameter blobAreaMinStp1; + ofParameter filteringRounds; + ofParameter blobAreaMin; ofParameter blobAreaMax; ofParameter countBlob; -- GitLab From df32b6ef645b95e901f573a4afbc36df17208eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20B=C3=BCrki?= Date: Tue, 18 Aug 2020 13:51:00 +0200 Subject: [PATCH 2/2] Add thresholding option --- src/BlobFinder.cpp | 3 +++ src/BlobFinder.h | 1 + 2 files changed, 4 insertions(+) diff --git a/src/BlobFinder.cpp b/src/BlobFinder.cpp index 85d0cdd..a4ef553 100644 --- a/src/BlobFinder.cpp +++ b/src/BlobFinder.cpp @@ -44,6 +44,7 @@ void BlobFinder::initGUI(ofxGui &gui){ sensorBoxGuiGroup->add(sensorBoxBottom.set("bottom", 1000)); blobGuiGroup = panel->addGroup("Blobs"); + blobGuiGroup->add(threshold.set("Threshold", false)); blobGuiGroup->add(filteringRounds.set("FilteringRounds", 1, 0, 3)); blobGuiGroup->add(blobAreaMax.set("AreaMax", 5, 0, 255)); blobGuiGroup->add(blobAreaMin.set("AreaMin", 10, 0, 255)); @@ -210,6 +211,8 @@ void BlobFinder::loadMask() { void BlobFinder::filterTrailingPixels() { filteredImage = grayImage; + if (threshold.get()) filteredImage.threshold(0); + filteredImage.dilate_3x3(); for (int i = 0; i <= filteringRounds.get(); i++) { filteredImage.erode_3x3(); diff --git a/src/BlobFinder.h b/src/BlobFinder.h index f34f0c2..4bd91f6 100644 --- a/src/BlobFinder.h +++ b/src/BlobFinder.h @@ -124,6 +124,7 @@ public: ofParameter nearFrustum; ofParameter farFrustum; + ofParameter threshold; ofParameter filteringRounds; ofParameter blobAreaMin; ofParameter blobAreaMax; -- GitLab