Commit a17ffab5 authored by Pierre Bürki's avatar Pierre Bürki
Browse files

Add filtering before blob detection

parent cda2ecaf
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -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;
+2 −0
Original line number Diff line number Diff line
@@ -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
 
+1 −1
Original line number Diff line number Diff line
@@ -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);