Skip to content

Commit 08a2ce0

Browse files
committed
Use color for k-means clusters
1 parent 271334b commit 08a2ce0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

go_capture/sgf/find_stones.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def draw_patches(image, coords, color):
5555

5656

5757
def get_clusters(board):
58-
gray = cv2.cvtColor(board, cv2.COLOR_BGR2GRAY)
59-
width, height = gray.shape
60-
pixels = np.float32(gray.reshape((width * height)))
58+
pixels = np.float32(board.reshape(-1, 3))
6159
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
6260
flags = cv2.KMEANS_RANDOM_CENTERS
6361
_, labels, palette = cv2.kmeans(pixels, 5, None, criteria, 10, flags)
64-
return labels.reshape(gray.shape), np.argmin(palette), np.argmax(palette)
62+
width, height, _ = board.shape
63+
means = np.mean(palette, axis=1)
64+
return labels.reshape(width, height), np.argmin(means), np.argmax(means)

0 commit comments

Comments
 (0)