Using k means for image clustering

asked 2016-03-24 06:29:19 -0500

Giorgos_ts gravatar image

I am using c++,OpenCV library and in my software, I have estimated the optical flow in a video. Now, I want to group some moving objects, e.g. moving cars. I have used a dense optical flow algorithm (Farneback).

My first thoughts so far are to use "k means" algorithm to do the clustering.

I have thought of using the results of the Farneback optical flow to compute the displacement of the frames in each direction as following :

E.g. :

Let Dx be the displacement in x direction( either positive or negative) and Dy the displacement in y direction(either positive or negative) .

Then i pass the array [Dx,Dy] as an input to k means with k=2 clusters. I hope this will give a rough background / foreground substraction .

However i am facing problems in computing the displacemet because the output of calcOpticalFlowFarneback is InputOutputArray flow . Should I access this array using a function like that for example ? :

findDisplacements(const Mat& flow, int step) {

const Point2f& Dx,Dy;

const Point2f& fxy =<point2f>(y, x);




edit retag flag offensive close merge delete