Adaptive Threshold in ofxCv?

Very quick question - Is there a way to do an adaptive threshold in ofxCv? @kylemcdonald :heart:

Or just generally even out the lighting in an image before blob detection?

ofxCv has autothreshold and it also has the RunningBackground class. Did you try these?

I think auto threshold just picks the mid point, I don’t think it’s the same as adaptive threshold. ofxCvGreyScaleImage has adaptive threshold but my understanding of opencv along with how ofxCv relates to ofxOpenCv is confused to say the least :sweat_smile:

In this case background removal isn’t what I want I don’t think.

Hey @seb_ly ofxOpenCv has:

ofxCvGrayscaleImage::adaptiveThreshold

That said I have done my own adaptive threshold by basically doing a absolute difference between a heavily blurred version of the live video ( usually I will resize it down, blur, then resize it up ) and the Iive video itself. Usually with sliders for the blur amount and the thresholding.

Something like this:

        bgFull = result;
        if( bgSmall.getWidth() == 0 ){
            bgSmall.allocate(bgFull.getWidth()/8, bgFull.getHeight()/8);
        }
        bgSmall.scaleIntoMe(bgFull, CV_INTER_LINEAR);
        bgSmall.blurGaussian(1 + adaptThreshBlur*2);
        bgFull.scaleIntoMe(bgSmall, CV_INTER_LINEAR);
        result -= bgFull;

These are all ofxCvGrayscaleImage objects.

There is also:
https://docs.opencv.org/4.x/d7/d1b/group__imgproc__misc.html#ga72b913f352e4a1b1b397736707afcde3

Which is the modern OpenCV way to do it.
You would just use the Mats from ofxCv as your src and dst.

This is really helpful, thanks so much @Theo, hope you’re doing well!