title: python-opencv, finding centroid of an image
body: <p>I am studying pattern recognition. For study purpose, I extracted faces from bunch of images, and get meaningful features out of them. So I tried to find the centroid of each face image. However, for some of images, I get centroid with coordinate (0,0). The part of code I used to find the centroid is following:</p>
  
  <pre><code>################# find the centroid of each faces #################
  ret, threshold = cv2.threshold(image, 255/2, 255, cv2.THRESH_BINARY)
  cont, hier = cv2.findContours(threshold, 1, 2)
  moment = cv2.moments(cont[0])
  if moment['m00'] == 0:
      m00 = 0.01
  else:
      m00 = moment['m00']
  cx, cy = int(moment['m10']/m00), int(moment['m01']/m00)
  ###################################################################
  </code></pre>
  
  <p>I am assigning m00 = 0.01 because some of the value moment['m00'] gives zero. 
  My question is am I doing correct to find the centroid of an image?? And if it is, why some of the centroid is (0,0)?? I thought since each image is not just blank image, the centroid coordinate should be non-zero coordinate.
  Thanks. </p>