Skip to content
Snippets Groups Projects
Commit d0258642 authored by zalonzo2's avatar zalonzo2
Browse files

Assume no castling (only 2 largest contours in diff). Also pushing test images

parent 18d6bc41
No related branches found
No related tags found
No related merge requests found
Showing
with 24 additions and 16 deletions
......@@ -360,7 +360,8 @@ def find_pieces(warped_img, prev_warped_img, sorted_warped_points, reader, img_i
diff_contours, hierarchy = cv2.findContours(diff_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
diff_contours_sorted = sorted(diff_contours, reverse=True, key=cv2.contourArea)
diff_contours_sorted = diff_contours_sorted[0:5]
num_contours = 2 # was 4 to enable castling
diff_contours_sorted = diff_contours_sorted[0:num_contours]
cv2.drawContours(diff_mask_contours, diff_contours_sorted, -1, (255), thickness=cv2.FILLED)
if show_cv:
......@@ -625,7 +626,8 @@ def find_pieces(warped_img, prev_warped_img, sorted_warped_points, reader, img_i
letter1, confidence1 = ("X (remove)", 0)
letter2, confidence2 = ("X (remove)", 0)
display_img([img_to_read])
if show_cv:
display_img([img_to_read])
# if contour_found:
......@@ -667,7 +669,8 @@ def find_pieces(warped_img, prev_warped_img, sorted_warped_points, reader, img_i
# display_img([img_to_read,img_to_read_bigger])
img_to_read = deepcopy(img_to_read_bigger)
display_img([img_to_read])
if show_cv:
display_img([img_to_read])
# print("Not found on first try")
# display_img([img_to_read])
result2 = reader.readtext(
......@@ -696,7 +699,8 @@ def find_pieces(warped_img, prev_warped_img, sorted_warped_points, reader, img_i
if show_cv or show_board:
coord = letter_dict[j] + str(8 - i)
print(letter, confidence, coord)
display_img([img_to_read])
if show_cv:
display_img([img_to_read])
for color, (lower, upper) in hue_thresh_dict.items(): # for each color threshold
if lower <= avg_hue < upper:
......
......@@ -246,8 +246,8 @@ void movePiece(){
stepperX.run();
stepperY1.run();
stepperY2.run();
if (count > 200) {
vTaskDelay(10);
if (count > 600) {
vTaskDelay(1);
count = 0;
}
}
......@@ -268,8 +268,8 @@ void movePiece(){
stepperY1.run();
stepperY2.run();
count++;
if (count > 200) {
vTaskDelay(10);
if (count > 600) {
vTaskDelay(1);
count = 0;
}
}
......
......@@ -131,7 +131,7 @@ def Stockfish_eval(FEN_string):
parameters={"Skill Level":19}) # range: 0-19? 20 might exist or rounds to 19, https://github.com/vondele/Stockfish/blob/master/src/search.cpp
else:
# print("RASPI STOCKFISH")
stockfish = Stockfish( path = "/home/Team33/Documents/Stockfish/arm_stockfish/stockfish/stockfish-android-armv7", # install Stockfish and input path to .exe here
stockfish = Stockfish( path = "/home/Team33/Documents/Stockfish/arm_stockfish/stockfish/stockfish-android-armv8", # install Stockfish and input path to .exe here
depth = 15, # 20 is good but slower, 15 is fine
parameters={"Skill Level":19})
......
......@@ -50,6 +50,8 @@ class ChessGame:
self.reader = easyocr.Reader(['en'], gpu=False, verbose=False)
self.best_move = None
# hard-coded borders to crop image
self.left_cut = 0
self.right_cut = 280
......@@ -171,9 +173,9 @@ class ChessGame:
def ai_turn(self):
print("\n--- CHESS ROBOT'S TURN ---")
# print("Board before chess_AI:", self.board.fen())
ESP_input, best_move = chess_AI(self.board.fen(), self.prev_board.fen(), 0)
ESP_input, self.best_move = chess_AI(self.board.fen(), self.prev_board.fen(), 0)
print("Best Move: ", best_move)
print("Best Move: ", self.best_move)
# convert best move to coordinates to send
# ----------------------------ADD JOSE MOVE MAGNET STUFF
......@@ -356,11 +358,13 @@ class ChessGame:
if self.prev_board.turn == chess.WHITE: # if player just went, they cheated
self.player_cheating = True
else: # chess robot just went
print("Did NOT find chess robot's move.")
if self.img_idx != 2:
print("Detected Board: ")
print(temp_board)
print("\nPrevious Board: ",)
print("!")
self.board.push(chess.Move.from_uci(self.best_move))
# print("Did NOT find chess robot's move.")
# if self.img_idx != 2:
# print("Detected Board: ")
# print(temp_board)
# print("\nPrevious Board: ",)
# print("PREVIOUS BOARD:")
# print(self.prev_board)
......
ocr_test_images/didn't work 8-55 (magnet test 3)/board1.jpg

1 MiB

ocr_test_images/didn't work 8-55 (magnet test 3)/board2.jpg

1.01 MiB

ocr_test_images/didn't work 8-55 (magnet test 3)/board3.jpg

1020 KiB

ocr_test_images/didn't work 8-55 (magnet test 3)/board4.jpg

1010 KiB

ocr_test_images/didn't work 8-55 (magnet test 3)/board5.jpg

1010 KiB

ocr_test_images/magnet test 8 (camera died)/board1.jpg

1000 KiB

ocr_test_images/magnet test 8 (camera died)/board2.jpg

1010 KiB

ocr_test_images/magnet test 8 (camera died)/board3.jpg

1000 KiB

ocr_test_images/magnet test 8 (camera died)/board4.jpg

994 KiB

ocr_test_images/magnet test 8 (camera died)/board5.jpg

989 KiB

ocr_test_images/magnet test 8 (camera died)/board6.jpg

1010 KiB

ocr_test_images/magnet test 8 (camera died)/board7.jpg

1010 KiB

ocr_test_images/magnet test 9/board1.jpg

1010 KiB

ocr_test_images/magnet test 9/board2.jpg

1010 KiB

ocr_test_images/magnet test 9/board3.jpg

1000 KiB

ocr_test_images/magnet test 9/board4.jpg

1000 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment