Skip to content

Commit 2e67c1a

Browse files
authored
Merge pull request #33 from codeguru42/5-use-color
5 use color
2 parents d5ff8cb + bd6fc7c commit 2e67c1a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

expected/20230121_140756.sgf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(;FF[4]
2+
GM[1]
3+
;AB[cj][cn][dd][df][dg][dp][gd][gg][gh][gi][gj][gr][hc][he][hf][hq][ir][jc][jd][je][jq][ke][ki][kp][kq][mq][oo][ph][pj][pk][pl][qi][ql][qo][ri][rl][rn][rq]
4+
;AW[ej][fc][fd][fe][fg][fh][fi][fl][fo][fq][gf][hg][hp][if][ig][ip][iq][jp][kc][kd][ko][le][lf][nn][no][np][oi][oj][ok][ol][pd][pg][pi][pm][pq][qh][qm]
5+
)

go_capture/sgf/find_stones.py

Lines changed: 7 additions & 7 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+
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
63-
_, labels, palette = cv2.kmeans(pixels, 5, None, criteria, 10, flags)
64-
return labels.reshape(image.shape), np.argmin(palette), np.argmax(palette)
61+
_, labels, palette = cv2.kmeans(pixels, 6, None, criteria, 10, flags)
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)