title: grouping motion vectors
body: <p>I am using -Lucas-kanade algorithm to calculate the optical flow of a video sequences with openCV. I got the motion vectors. Now I want to group those motion vectors in some clusters.
  the vectors which are near by each other I want to group them together. Some thing like nearest neighbor approach. But I don't know how I can implement the same. any help will be appreciated.</p>
  
  <p>Thank you.</p>
  
  <p>I used cvKMeans2() to group the corner points after running the optical flow algorithm...</p>
  
  <p>I have the clusters in a vector of vectors clustercontainer. Now I want to draw a boundary line around every clusters..I am not sure how can I do so...if anybody knows please help.</p>
  
  <p>Using the below code from openCV manual I draw the circle around every cluster..but I want to draw rectangle rather than a  circle..any body please help me.</p>
  
  <pre><code>    for(int h = 0; h &lt; clusterContainer.size(); h++ )
          {
  
             CvPoint pt1,pt2;
                 CvMat box[100];
  
             pt1.x=(int)points-&gt;data.fl[h*2];
             pt1.y=(int)points-&gt;data.fl[h*2+1];
                cvCircle( frame1, pt1, 20, CV_RGB(255,255,0),4);
  
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/3zgmF.jpg" alt="enter image description here"></p>