advancedskrald/opencv_video.py

48 lines
1.4 KiB
Python
Raw Normal View History

2019-04-04 10:59:37 +00:00
from datetime import datetime
import cv2
2019-04-04 10:59:37 +00:00
import runner
from util import FILE, RANK, PIECE, COLOR, imwrite, POSITION
2019-04-04 10:59:37 +00:00
cap = cv2.VideoCapture(0)
2019-05-18 15:12:35 +00:00
#cap.set(cv2.CAP_PROP_FRAME_WIDTH, 4096)
#cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 2160)
2019-04-04 10:59:37 +00:00
2019-05-18 15:12:35 +00:00
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
color = COLOR.WHITE
rank = RANK.FIVE
2019-04-04 10:59:37 +00:00
pieces = {
2019-05-18 15:12:35 +00:00
PIECE.PAWN: [POSITION((FILE.A, rank)), POSITION((FILE.B, rank)), POSITION((FILE.C, rank)), POSITION((FILE.D, rank)),
POSITION((FILE.E, rank)), POSITION((FILE.F, rank)), POSITION((FILE.G, rank)), POSITION((FILE.H, rank))]
2019-04-04 10:59:37 +00:00
}
while True:
2019-04-04 10:59:37 +00:00
# Capture frame-by-frame
ret, frame = cap.read()
# Display the resulting frame
cv2.imshow("frame", frame)
2019-04-04 10:59:37 +00:00
if cv2.waitKey(100) & 0xFF == ord("c"):
2019-04-04 10:59:37 +00:00
print(f"capturing frame")
2019-05-18 15:12:35 +00:00
#imwrite(f"whole_boards/boards_for_empty/board_{datetime.utcnow().timestamp()}_.png", frame)
imwrite("whole_boards/boards_for_empty/lol_gg_xD.png", frame)
break
2019-04-04 10:59:37 +00:00
warped = runner.warp_board(frame)
2019-05-18 15:12:35 +00:00
#runner.save_empty_fields(warped, skip_rank=rank)
2019-04-04 10:59:37 +00:00
for piece, positions in pieces.items():
for position in positions:
2019-05-18 15:12:35 +00:00
square = runner.get_square(warped, position)
imwrite(f"training_images/{piece}/{position.color}_square/training_{position}_{datetime.utcnow().timestamp()}.png", square)
2019-04-04 10:59:37 +00:00
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()