title: OpenCV C++ usage of cv::Moments
body: <p>I try to find centroid using OpenCV C++'s cv::Moments. Whatever arguments I submit to it, All I receive back are zeros. Clearly I do something very simply wrong. Output of code:</p>
  
  <pre><code>23 of 500 elements in unit 3
  point values 2.976444 18.248287
  matrix size 23
  moments 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
  moments 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
  </code></pre>
  
  <p>And code:</p>
  
  <pre><code>printf("%d of %d elements in unit %d\n",k,number_of_features,i);
  cv::Mat x(k, 1, cv::DataType&lt;cv::Point2f&gt;::type);
  k=0;
  for(int j=0;j &lt;number_of_features;j++) {
      if(i  == labels.at&lt;int&gt;(j)) {
          x.at&lt;cv::Point2f&gt;(k++) = samples.at&lt;cv::Point2f&gt;(i); 
      }
  }
  printf("point values %f %f\n", x.at&lt;cv::Point2f&gt;(0).x,x.at&lt;cv::Point2f&gt;(0).y);
  cv::Size s=x.size();
  printf("matrix size %d\n",s.height);
  cv::Moments m=cv::moments(x);
  printf("moments %f %f %f %f %f %f %f %f\n",m.m00,m.m01,m.m20,m.m11,m.m02,m.m30,m.m21,m.m03);
  double h[7];
  cv::HuMoments(m,h);
  printf("moments %f %f %f %f %f %f %f\n",h[0],h[1],h[2],h[3],h[4],h[5],h[6]);
  </code></pre>
  
  <p>Strangely I cannot find any identical code sample from Google. All I see are C style approaches.</p>