diff --git a/board_detector.py b/board_detector.py index e58d0c385398e47fbf92a506503003a89104b78d..32ca613b6e821e68b7e165e82a186e6ec016f48a 100644 --- a/board_detector.py +++ b/board_detector.py @@ -283,7 +283,7 @@ prev_masked_hsv_after = None prev_largest_contour = None # prev_bounding_box_array = None -def find_pieces(warped_img, sorted_warped_points, img_idx): +def find_pieces(warped_img, sorted_warped_points, reader, img_idx): global prev_warped_img global prev_hsv_img global prev_hsv_mask_sat @@ -357,9 +357,6 @@ def find_pieces(warped_img, sorted_warped_points, img_idx): warped_img_pil = cv2_to_pil(warped_img) warped_img_draw = ImageDraw.Draw(warped_img_pil) - if compare_prev_warped: - reader = easyocr.Reader(['en'], gpu=False, verbose=False) - filled_contour_mask = np.zeros_like(hsv_after) diff_contour_mask = np.zeros_like(hsv_after) # if compare_prev_warped: diff --git a/game.py b/game.py index a58f63ed4ed310fd71ba2adc0b8a4f73a5e903d0..0c33ba87686574810d2964b93f570e055f19efac 100644 --- a/game.py +++ b/game.py @@ -10,6 +10,7 @@ import move_translator import cv2 import os import time +import easyocr # was having issues installing picamera2 on my PC # if the raspi runs this code (with picamera2 installed), skip_camera will be false @@ -38,6 +39,8 @@ class ChessGame: else: self.img_idx = 1 + self.reader = easyocr.Reader(['en'], gpu=False, verbose=False) + # hard-coded borders to crop image self.left_cut = 0 self.right_cut = 280 @@ -179,7 +182,7 @@ class ChessGame: return # get the pieces based on color thresholding and easyocr - color_grid = find_pieces(warped_img, sorted_warped_points, self.img_idx - 1) + color_grid = find_pieces(warped_img, sorted_warped_points, self.reader, self.img_idx - 1) # convert color_grid to board, which we can get fen string from if self.color_scheme == 'p/y':