2019-04-04 10:59:37 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2019-04-05 01:31:30 +00:00
|
|
|
import cv2
|
2019-04-04 10:59:37 +00:00
|
|
|
|
2019-04-05 01:31:30 +00:00
|
|
|
import runner
|
|
|
|
from util import FILE, RANK, PIECE, COLOR, imwrite, POSITION
|
2019-04-04 10:59:37 +00:00
|
|
|
|
2019-04-05 01:31:30 +00:00
|
|
|
cap = cv2.VideoCapture(0)
|
2019-04-04 10:59:37 +00:00
|
|
|
|
2019-04-05 01:31:30 +00:00
|
|
|
color = COLOR.BLACK
|
|
|
|
rank = RANK.EIGHT
|
2019-04-04 10:59:37 +00:00
|
|
|
pieces = {
|
2019-04-05 01:31:30 +00:00
|
|
|
PIECE.rook: [POSITION(FILE.A, rank), POSITION(FILE.F, rank)],
|
|
|
|
PIECE.knight: [POSITION(FILE.E, rank), POSITION(FILE.H, rank)],
|
|
|
|
PIECE.bishop: [POSITION(FILE.C, rank), POSITION(FILE.D, rank)],
|
|
|
|
PIECE.queen: [POSITION(FILE.B, rank)],
|
|
|
|
PIECE.king: [POSITION(FILE.G, rank)],
|
2019-04-04 10:59:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 01:31:30 +00:00
|
|
|
while True:
|
2019-04-04 10:59:37 +00:00
|
|
|
# Capture frame-by-frame
|
|
|
|
ret, frame = cap.read()
|
|
|
|
|
|
|
|
# Display the resulting frame
|
2019-04-05 01:31:30 +00:00
|
|
|
cv2.imshow("frame", frame)
|
2019-04-04 10:59:37 +00:00
|
|
|
|
2019-04-05 01:31:30 +00:00
|
|
|
if cv2.waitKey(100) & 0xFF == ord("c"):
|
2019-04-04 10:59:37 +00:00
|
|
|
print(f"capturing frame")
|
2019-04-05 01:31:30 +00:00
|
|
|
imwrite(f"whole_boards/boards_for_empty/board_{datetime.utcnow().timestamp()}_.png", frame)
|
2019-04-04 10:59:37 +00:00
|
|
|
warped = runner.warp_board(frame)
|
|
|
|
|
|
|
|
runner.save_empty_fields(warped, skip_rank=rank)
|
|
|
|
|
|
|
|
for piece, positions in pieces.items():
|
|
|
|
for position in positions:
|
2019-04-05 01:31:30 +00:00
|
|
|
square = runner.get_square(warped, *position)
|
2019-04-04 10:59:37 +00:00
|
|
|
x, y = position
|
2019-04-05 01:31:30 +00:00
|
|
|
imwrite(f"training_images/{piece}/{position.color}_square/training_{x}{str(y)}_{datetime.utcnow().timestamp()}.png", square)
|
2019-04-04 10:59:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
# When everything done, release the capture
|
|
|
|
cap.release()
|
|
|
|
cv2.destroyAllWindows()
|