[SOLVED] Smoothing position coordinates

Hello,

I am using a Kinect and openCV to detect blobs.
I grab the position of the blob (centroid) but because of noise in the image detection, this position is noisy and unstable.

what would be the way to smooth values ?
(i saw ofLerp but i don’t undertand how this works)

thanks

position = position * 0.9 + newCentroid * 0.1;

or any other low pass filter, but this is probably the simplest.

i was looking for something with Lerp but this one is pretty straightforward and works pretty nice !

Thanks arturo !

I have a similar problem but I didn’t manage to sort it yet. HOw do I get the correct position1 and newPosition?

I have a stream of position from ofxFaceTracker. what I am doing is
in setup();

//initialise buffer Position
        bufferPositionSize = 16; // also tried 1, 2,4,512
        bufferPosition = new ofVec2f[bufferPositionSize];
        tempindexPos = new int[bufferPositionSize];
        
        //all indices start from 0
        for (int i = 0; i<bufferPositionSize; i++) {
            tempindexPos [i] = NULL;
            
        }

in update();
I am cycling the stream in the buffer.

//ring buffer for smoothing the scale 
        for (int i = 0; i<bufferPositionSize; i++) {
            bufferPosition[tempindexPos[i]] = ofVec2f ( anchor ); // anchor is the anchor point
            tempindexPos[i]++;
            
            if (tempindexPos[i] == bufferPositionSize) {
                tempindexPos[i]= 0;
            }
        }

and then in draw I translate the position using this function

ofVec2f testApp::fadePos(int bufferSize, ofVec2f *buffer){
    ofVec2f result;
    for (int i=0; i<bufferSize; i++) {
        result = ofVec2f( buffer[i]*0.9 + buffer[i%1]*0.1 );
    }
     return result;
}

I was expecting to have a smoother transition with a bigger buffer, instead I get the contrary. If the buffer is 1 is more fluid if is 2,4,16, it’s more and more jittery. if it’s 512 doesn’t even start…

Any suggestion?

cheers!

Hi @arturo, could you explain how this works? I see it does some kind ot smoothing value in time, but I’m just curious how it works.

BTW, maybe it’s a good idea to implement some native OFX smooth functions like Vuo has… What do you think?

Cheers, Teo

Ok, I got it :slight_smile: For anyone who is curious this is some kind of simplified exponential moving average: