import cv2 import numpy as np img = cv2.imread('cuadro.jpg',0) img2 = cv2.imread('cuadro.jpg') ret,thresh = cv2.threshold(img,127,255,0) contours,hierarchy = cv2.findContours(thresh, 1, 2) for i in range(0,len(contours)): cnt = contours[i] M = cv2.moments(cnt) cx = int(M['m10']/M['m00']) cy = int(M['m01']/M['m00']) # cv2.circle(img2,(cx,cy), 5, (0,0,255), 1) print cx,cy epsilon = 0.05*cv2.arcLength(contours[12],True) approx = cv2.approxPolyDP(contours[12],epsilon,True) cnt=contours[12] for i in range(0,len(cnt)): cx=cnt[i][0][0] cy=cnt[i][0][1] cv2.circle(img2,(cx,cy), 1, (255,0,255), -1) for i in range(0,len(approx)): print approx[i] cx=approx[i][0][0] cy=approx[i][0][1] cv2.circle(img2,(cx,cy), 3, (0,0,255), -1) cv2.imwrite("cuadro2_centros.jpg",img2)