I have to solve a seemingly simple task but I’m struggleing a bit.
Basically I want to create a script that given a screenshot of the Classic Tetris board gives as a output a 2d numpy array were each cell is set to 0 if it’s empty and to 1 if it’s not.
This is an example of the board:
https://imgur.com/a/DFGyfad
I tried using OpenCV and template matching by creating templates from the single tiles, it somewhat works but there’s two main problems:
- The color of the tiles change during the game and I want to be able to find the tiles regardless of their color
- It is slow. The idea is to use this to process a video, but the way I’m currently doing it is pretty slow it would seem.
Given that the board is a 20 by 10 grid I thought I could average the pixels of each cell and if their average value is >0 it is a 1, otherwise a 0, since the empty cells are always black.
But how would I do this efficiently? Do you have any other ideas?