OpenCV Question

Can someone help me with an OpenCV question?

I’m looking to find out and use the velocity and position of blobs detected with OpenCV, can anyone recommend a good way of doing this?


The ofxCVBlob class has a parameter called “centroid” which returns the position at the center of the blob rectangle. With each openCV blob you could track the position of the centroid every frame and compare it with the previous frame, this should get you the speed of the blob relative to the center.

Here’s some pseudo code that should help to understand, if not I can create an example but that will take me a little longer. If you are finding that the speeds are not in easily working numbers you could tweak the speed sensitivity a bit. In the code below it would exaggerate the speed by 2x it’s actual value.

ofPoint lastCentroid ;   
ofPoint speed ;   
float speedSensitivity= 2.0f ;   
update( )   
   //Get the value of the centroid somehow   
   ofPoint centroid = blob.centroid ;   
   speed = centroid - lastCentroid ;   
   lastCentroid = centroid ;   
   speed *= speedSensitivity ;   

The ofxCVBlob documentation might be helpful to you as well for all the parameters and functions.

Hope that helps !

Thank you for your help,

I found a solution to what I wanted to achieve by using optical flow, the same way this guy did it,

I’ll now plough on to the next hurdle!