@@ -17,8 +17,7 @@ def categorize(patch, label_black, label_white):
17
17
18
18
19
19
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 )
22
21
height , width , _ = board .shape
23
22
dx = width // 18
24
23
dy = height // 18
@@ -55,10 +54,11 @@ def draw_patches(image, coords, color):
55
54
cv2 .rectangle (image , (left , top ), (right , bottom ), color , 2 )
56
55
57
56
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 )))
61
61
criteria = (cv2 .TERM_CRITERIA_EPS + cv2 .TERM_CRITERIA_MAX_ITER , 200 , .1 )
62
62
flags = cv2 .KMEANS_RANDOM_CENTERS
63
63
_ , 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