slice a scrabble board?

63 Views Asked by At

I'm working on a project that requires me to get information(letters present) from a scrabble game board.

EDIT: I must get the position of the letters too

For now I successfully detected the board game and get an image containing the board inside (only the squares where the letters should be placed i.e. the play-zone, without the extra-border that the game board has) and now I have to get the positions of each letter placed. My question is, how should I approach this? Should I slice the image for every square? Should I use some feature matching algorithm? Also, I must not use artificial neural networks.

Here is my code for detecting, and getting the contour of the initial image and then returning only the playable portion of the board:

def get_contour(img):
    grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(grey, (3, 3), 0)
    edges = cv2.Canny(blur, 120, 300, apertureSize=3)
    kernel = np.ones((3, 3), np.uint8)
    dilation = cv2.dilate(edges, kernel, iterations=2)
    contours, hierarchy = cv2.findContours(
        dilation,
        cv2.RETR_EXTERNAL,
        cv2.CHAIN_APPROX_SIMPLE)
    
    cnt = max(contours, key=cv2.contourArea)
    x, y, w, h = cv2.boundingRect(cnt)
    

    img2 = img[y:y + h, x:x + w]
    return img2, cnt

and here's the result:

from this: before: to this: after:

0

There are 0 best solutions below