Skip to content

Commit 271334b

Browse files
committed
Move code into get_clusters() to apply gray scale to the image
1 parent d5ff8cb commit 271334b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

go_capture/sgf/find_stones.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def categorize(patch, label_black, label_white):
1717

1818

1919
def find_stones(board):
20-
gray = cv2.cvtColor(board, cv2.COLOR_BGR2GRAY)
21-
labeled_image, label_black, label_white = get_clusters(gray)
20+
labeled_image, label_black, label_white = get_clusters(board)
2221
height, width, _ = board.shape
2322
dx = width // 18
2423
dy = height // 18
@@ -55,10 +54,11 @@ def draw_patches(image, coords, color):
5554
cv2.rectangle(image, (left, top), (right, bottom), color, 2)
5655

5756

58-
def get_clusters(image):
59-
width, height = image.shape
60-
pixels = np.float32(image.reshape((width*height)))
57+
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)))
6161
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
6262
flags = cv2.KMEANS_RANDOM_CENTERS
6363
_, labels, palette = cv2.kmeans(pixels, 5, None, criteria, 10, flags)
64-
return labels.reshape(image.shape), np.argmin(palette), np.argmax(palette)
64+
return labels.reshape(gray.shape), np.argmin(palette), np.argmax(palette)

0 commit comments

Comments
 (0)