def __init__(self, radius, image, center=None, position=None):
     """
     Arguments: *radius* is 3 or 5, *image* is an OpenCV Mat, optional args
     are (x, y) tuples.
     
     Note: *center* takes precedence over conflicting *position*.
     """
     self.radius = radius
     self.height = self.width = radius + 1 + radius
     self.image = image
     
     if center != None:
         self.center = center
         self.position = Point(get_x(center) - radius, get_y(center) - radius)
     elif position != None:
         self.position = position
         self.center = Point(get_x(position) + radius, get_y(position) + radius)
     else:
         self.position = Point(0, 0)
         self.center = Point(radius, radius)
     
     if(radius==3):
         self.points = [ Point( 6,  3),
                         Point( 5,  1),
                         Point( 3,  0),
                         Point( 1,  1),
                         Point( 0,  3),
                         Point( 1,  5),
                         Point( 3,  6),
                         Point( 5,  5)  ]
     elif(radius==5):
         self.points = [ Point(10,  5),
                         Point(10,  3),
                         Point( 9,  1),
                         Point( 7,  0),
                         Point( 5,  0),
                         Point( 3,  0),
                         Point( 1,  1),
                         Point( 0,  3),
                         Point( 0,  5),
                         Point( 0,  7),
                         Point( 1,  9),
                         Point( 3, 10),
                         Point( 5, 10),
                         Point( 7, 10),
                         Point( 9,  9),
                         Point(10,  7)  ]
     else:
         print('Error: radius value' + radius + 'unsupported')
         exit()
 def at3(self, x, y):
     """
     Returns intensity of pixel in *self.image* corresponding to (*x*, *y*) in
     sample window.
     """
     absx = x + get_x(self.position)
     absy = y + get_y(self.position)
     return sum(self.image[absy][absx])
    def cornerfind_from_ChESS(self):
        """
        todo
        """
        points = [Point(x, y, sum(self.img[y][x])) for y in range(self.rows) for x in range(self.cols)]

        clusters = kmeans_tc(points, [Point(0, 0), Point(self.cols - 1, 0)])

        identify_boards(clusters)

        for cluster in clusters:
            print str(cluster.size())
            for corner in cluster.corners:
                print "\t" + str(get_x(corner)) + "," + str(get_y(corner))
 def savetxt(self, fstem):
     (rowlen, nrows) = self.dims
     P = []
     i = 0
     for rownum in range(nrows):
         row = []
         for pos in range(rowlen):
             point = self.points[i]
             x = get_x(point)
             y = get_y(point)
             row.append([x, y])
             i += 1
         P.insert(0, row)
     
     np.save(fstem, np.asarray(P))
     
     np.savetxt(fstem+"hom.txt", self.H)
 def calc_center(self):
     """
     Finds the average coordinates of *self.points*, weighted by pixel intensity,
     and saves them in *self.center*.
     """
     N = 0
     Ex = 0
     Ey = 0
     for point in self.points:
         x = get_x(point)
         y = get_y(point)
         z = get_z(point)
         N += z
         Ex += z*x
         Ey += z*y
     self.prevcenter = self.center
     self.center = Point(Ex/N, Ey/N)
 def at2(self, point):
     """
     Returns intensity of pixel in *self.image* corresponding to tuple *point*
     in sample window.
     """
     return self.at3(get_x(point), get_y(point))