pls
48
main.py
|
@ -11,6 +11,9 @@ import os
|
||||||
import heapq
|
import heapq
|
||||||
import math
|
import math
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import sys
|
||||||
|
|
||||||
|
np.set_printoptions(threshold=sys.maxsize)
|
||||||
|
|
||||||
pieces = ['rook', 'knight']
|
pieces = ['rook', 'knight']
|
||||||
#pieces = ['rook', 'knight']
|
#pieces = ['rook', 'knight']
|
||||||
|
@ -405,16 +408,13 @@ def load_classifier(filename):
|
||||||
return joblib.load(filename)
|
return joblib.load(filename)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
board = cv2.imread("whole_boards/boards_for_empty/board_1554288951.972197_.png")
|
board = cv2.imread("whole_boards/boards_for_empty/board_1554286488.605142_.png")
|
||||||
warped = runner.warp_board(board)
|
warped = runner.warp_board(board)
|
||||||
|
|
||||||
empty = 0
|
empty = 0
|
||||||
|
|
||||||
|
|
||||||
files = "ABCDEFGH"
|
files = "ABCDEFGH"
|
||||||
ranks = [1, 2, 3, 4, 5, 6, 7, 8]
|
ranks = [1, 2, 3, 4, 5, 6, 7, 8]
|
||||||
|
|
||||||
|
@ -423,24 +423,58 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
for rank in ranks:
|
for rank in ranks:
|
||||||
|
counter = 0
|
||||||
|
|
||||||
src = runner.get_square(warped, file, rank)
|
src = runner.get_square(warped, file, rank)
|
||||||
#src = cv2.GaussianBlur(src, (5, 5), 0)
|
width, height, _ = src.shape
|
||||||
segmentator = cv2.ximgproc.segmentation.createGraphSegmentation(sigma=0.75, k=175, min_size=750)
|
src = src[width//25:, height//25:]
|
||||||
|
# src = src[:-width//200, :-height//200]
|
||||||
|
segmentator = cv2.ximgproc.segmentation.createGraphSegmentation(sigma=0.8, k=150, min_size=700)
|
||||||
segment = segmentator.processImage(src)
|
segment = segmentator.processImage(src)
|
||||||
|
|
||||||
mask = segment.reshape(list(segment.shape) + [1]).repeat(3, axis=2)
|
mask = segment.reshape(list(segment.shape) + [1]).repeat(3, axis=2)
|
||||||
masked = np.ma.masked_array(src, fill_value=0)
|
masked = np.ma.masked_array(src, fill_value=0)
|
||||||
|
pls = []
|
||||||
for i in range(np.max(segment)):
|
for i in range(np.max(segment)):
|
||||||
masked.mask = mask != i
|
masked.mask = mask != i
|
||||||
|
|
||||||
y, x = np.where(segment == i)
|
y, x = np.where(segment == i)
|
||||||
|
|
||||||
top, bottom, left, right = min(y), max(y), min(x), max(x)
|
top, bottom, left, right = min(y), max(y), min(x), max(x)
|
||||||
|
|
||||||
dst = masked.filled()[top: bottom + 1, left: right + 1]
|
dst = masked.filled()[top: bottom + 1, left: right + 1]
|
||||||
|
lel = (bottom - top) * (right - left)
|
||||||
|
#print(f"this is lel: {lel} ")
|
||||||
|
#print(f"this is meh: {np.sum(mask[:,:,0])} ")
|
||||||
|
if f"{file}{rank}" == "H7":
|
||||||
|
print("--"*20)
|
||||||
|
print("H7")
|
||||||
|
print(lel)
|
||||||
|
print(len(y))
|
||||||
|
print(np.max(segment))
|
||||||
|
# print(lel)
|
||||||
|
# print(np.sum(mask[:, :, 0]))
|
||||||
|
print("--"*20)
|
||||||
|
|
||||||
|
|
||||||
|
pls.append(len(y))
|
||||||
|
if len(y) < (164**2)*0.65:
|
||||||
|
counter += 1
|
||||||
|
|
||||||
cv2.imwrite(f"segment_test/segment_{datetime.utcnow().timestamp()}_{file}{rank}.jpg", dst)
|
cv2.imwrite(f"segment_test/segment_{datetime.utcnow().timestamp()}_{file}{rank}.jpg", dst)
|
||||||
|
|
||||||
if np.max(segment) >= 2:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if np.max(segment) > 0 and not np.all([x < (164**2)*0.2 for x in pls]) and (np.max(segment) >= 3 or np.all([x < (164**2)*0.942 for x in pls])):
|
||||||
print(f"{file}{rank} is nonempty")
|
print(f"{file}{rank} is nonempty")
|
||||||
non_empties.append([f"{file}{rank}", src])
|
non_empties.append([f"{file}{rank}", src])
|
||||||
|
print(counter)
|
||||||
print(np.max(segment))
|
print(np.max(segment))
|
||||||
empty += 1
|
empty += 1
|
||||||
|
print("++"*20)
|
||||||
|
print(counter)
|
||||||
print(64-empty)
|
print(64-empty)
|
||||||
|
|
||||||
for non_empty in non_empties:
|
for non_empty in non_empties:
|
||||||
|
|
BIN
whole_boards/boards_for_empty/.DS_Store
vendored
Normal file
Before Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.5 MiB After Width: | Height: | Size: 2.5 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.5 MiB After Width: | Height: | Size: 2.5 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.5 MiB After Width: | Height: | Size: 2.5 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.2 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |