From a17ffab5dd59d2d1035b9ca45120a8bbb22b57ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20B=C3=BCrki?= Date: Mon, 17 Aug 2020 11:32:06 +0200 Subject: [PATCH] Add filtering before blob detection --- src/BlobFinder.cpp | 27 +++++++++++++++++++++++---- src/BlobFinder.h | 2 ++ src/ofApp.cpp | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/BlobFinder.cpp b/src/BlobFinder.cpp index 3dd9eba..5d410dc 100644 --- a/src/BlobFinder.cpp +++ b/src/BlobFinder.cpp @@ -207,6 +207,26 @@ void BlobFinder::loadMask() { maskFbo.end(); } +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(); +} + void BlobFinder::update(){ ofColor white = ofColor::white; ofColor black = ofColor::black; @@ -223,7 +243,7 @@ void BlobFinder::update(){ minID = (blobEvents[e].mID >= minID) ? blobEvents[e].mID + 1 : minID; } - if (true || useMask.get()) { + if (useMask.get()) { fbo.begin(); // Cleaning everthing with alpha mask on 0 in order to make it transparent for default ofClear(0, 0, 0, 0); @@ -246,8 +266,7 @@ void BlobFinder::update(){ // load grayscale captured depth image from the color source grayImage.setFromColorImage(colorImg); - - //grayImage.blurHeavily(); + filterTrailingPixels(); ofPixelsRef blobRefPixls = blobRef.getPixels(); @@ -283,7 +302,7 @@ void BlobFinder::update(){ detectedHeads.clear(); - contourFinder.findContours(grayImage, minBlobSize, maxBlobSize, countBlob.get(), false); + contourFinder.findContours(filteredImage, minBlobSize, maxBlobSize, countBlob.get(), false); for (int i = 0; i < contourFinder.nBlobs; i++){ ofRectangle bounds = contourFinder.blobs[i].boundingRect; diff --git a/src/BlobFinder.h b/src/BlobFinder.h index 1533b3f..dc6eb2a 100644 --- a/src/BlobFinder.h +++ b/src/BlobFinder.h @@ -46,6 +46,7 @@ public: void loadMask(); void saveMask(); + void filterTrailingPixels(); void update(); bool hasParamUpdate(); @@ -91,6 +92,7 @@ public: ofxCvGrayscaleImage blobRef; // body blob reference image ofxCvGrayscaleImage grayImage; // grayscale depth image + ofxCvGrayscaleImage filteredImage; // grayscale depth image with trailing pixels filtered out ofxCvGrayscaleImage grayEyeLevel; // the eyelevel thresholded image ofxCvGrayscaleImage grayThreshFar; // the far thresholded image diff --git a/src/ofApp.cpp b/src/ofApp.cpp index 6015778..87dedd4 100644 --- a/src/ofApp.cpp +++ b/src/ofApp.cpp @@ -420,7 +420,7 @@ void ofApp::drawCapturePointCloud(bool _mask) { } else { shader.setUniform1i("mask", 0); - glPointSize(6 * 2); + glPointSize(2); } shader.setUniform1f("lowerLimit", lowerLimit); shader.setUniform1f("upperLimit", upperLimit); -- GitLab