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

ocr with text instead of painted letters

parent 36552a6f
No related branches found
No related tags found
No related merge requests found
Showing
with 21 additions and 15 deletions
......@@ -7,7 +7,7 @@ from PIL import ImageDraw
import psutil
import time
import chess
import easyocr
# import easyocr
# global show_cv because I didn't want to have show_cv as an input to every function
# also need skip_camera so I can use cv2.imshow if I'm using my PC
......@@ -408,16 +408,18 @@ def find_pieces(warped_img, sorted_warped_points):
size = img_size * scale
img_to_read = cv2.resize(gray_masked, (int(size), int(size)))
reader = easyocr.Reader(['en'])
print("before reading")
results = reader.readtext(
image=img_to_read,
allowlist="PKQRBN",
rotation_info=[180],
batch_size=12,
batch_size=500,
text_threshold=0.3,
link_threshold = 1000000,
slope_ths=0.0,
min_size=int(size/100)
)
print("after reading")
img_to_read = cv2.cvtColor(img_to_read, cv2.COLOR_GRAY2BGR)
img_to_read = cv2.resize(img_to_read, (img_size, img_size))
......
......@@ -5,7 +5,7 @@ from board_detector import find_board
from board_detector import find_pieces
from board_detector import init_global
from board_detector import display_img
from chess_ai import *
# from chess_ai import *
import move_translator
import cv2
import os
......@@ -36,16 +36,18 @@ class ChessGame:
# hard-coded borders to crop image
self.left_cut = 0
self.right_cut = 290
self.right_cut = 280
self.top_cut = 0
self.bottom_cut = 290
self.bottom_cut = 280
self.img_size = 512
if not skip_camera:
self.picam2 = Picamera2()
else:
self.picam2 = None
# if not skip_camera:
# print("hi")
# self.picam2 = Picamera2()
# else:
# self.picam2 = None
self.picam2 = Picamera2()
def start_game(self):
......@@ -105,13 +107,15 @@ class ChessGame:
self.color_grid_to_fen(color_grid, 'yellow', 'pink')
if not FEN_check(self.board.fen()):
print("Bad FEN.")
return
# if not FEN_check(self.board.fen()):
# print("Bad FEN.")
# return
if self.show_cv:
print(self.board)
print(self.board.fen())
# if self.show_cv:
print(self.board)
print(self.board.fen())
while(1): # game loop
self.player_turn()
......
ocr_test_images/ocr_alt_game1-1.jpg

936 KiB

ocr_test_images/ocr_alt_game1-2.jpg

949 KiB

ocr_test_images/ocr_alt_game1-3.jpg

947 KiB

ocr_test_images/ocr_alt_game1-4.jpg

943 KiB

ocr_test_images/ocr_alt_game1-5.jpg

939 KiB

ocr_test_images/ocr_alt_game2-1.jpg

928 KiB

ocr_test_images/ocr_alt_game2-2.jpg

939 KiB

ocr_test_images/ocr_alt_game2-3.jpg

937 KiB

ocr_test_images/ocr_alt_game2-4.jpg

934 KiB

ocr_test_images/ocr_alt_game2-5.jpg

935 KiB

ocr_test_images/ocr_alt_game2-6.jpg

934 KiB

ocr_test_images/ocr_alt_game2-7.jpg

933 KiB

ocr_test_images/ocr_alt_game2-8.jpg

928 KiB

ocr_test_images/ocr_alt_game2b-1.jpg

935 KiB

ocr_test_images/ocr_alt_game2b-2.jpg

941 KiB

ocr_test_images/ocr_alt_game2b-3.jpg

931 KiB

ocr_test_images/ocr_alt_game2b-4.jpg

916 KiB

ocr_test_images/ocr_reg_text1.jpg

934 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