def findMove(image, circles): # Returns the opponent's move. # convert coordinates to integer circles = np.round(circles[0, :]).astype("int") opponentMove = 0 # iterate all circles found for (x, y, r) in circles: isMoved = True # check which region the circle belongs to if((x >= regions.minX) and (x <= regions.maxX)) and ((y >= regions.minY) and (y <= regions.maxY)): region = regions.checkRegion(x,y) else: break # iterate all available moves for move in board.availableMoves(): # if the region hasn't been occupied, take it as the opponent's move if move + 1 == region: isMoved = False break # do nothing if the region has been occupied before else: pass if not isMoved: opponentMove = region - 1 isMoved = True return opponentMove
def findMove(image, circles): # Returns the move of the opponent. # convert coordinates to integer circles = np.round(circles[0, :]).astype("int") opponentMove = 0 # iterate all circles found for (x, y, r) in circles: isMoved = True # check which region the found circle belongs to if ((x >= regions.minX) and (x <= regions.maxX)) and ((y >= regions.minY) and (y <= regions.maxY)): region = regions.checkRegion(x, y) else: break # iterate all available moves for move in board.availableMoves(): # if the region has'nt been occupied, take it as the opponent's move if move + 1 == region: isMoved = False break # do nothing if the region has been occupied before else: pass if not isMoved: opponentMove = region - 1 isMoved = True return opponentMove
circles = cv2.HoughCircles(gray, cv2.cv.CV_HOUGH_GRADIENT, 1.4, 30) # ensure at least some circles were founds if circles is not None: # convert the (x, y) coordinates and radius of the circles to integers circles = np.round(circles[0, :]).astype("int") # loop over the (x, y) coordinates and radius of the circles for (x, y, r) in circles: # draw the circle in the output image, then draw a rectangle # corresponding to the center of the circle cv2.circle(image, (x, y), r, (0, 255, 0), 4) cv2.rectangle(image, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1) print "Region", regions.checkRegion(x, y) print "X: ", x, "Y: ", y # show the output image fontIndex = 0 #draw all the regions for i in xrange(regions.totalYintercepts - 1): for ii in xrange(regions.totalXintercepts - 1): x1 = regions.xIntercepts()[ii] x2 = regions.xIntercepts()[ii + 1] y1 = regions.yIntercepts()[i] y2 = regions.yIntercepts()[i + 1] cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2) fontIndex = fontIndex + 1