The program analyzes picture of our office's table football game
and outputs the score as JSON
{
"leftScore": 9,
"rightScore": 3
}
For example, we're finding score from this image
The images were originally in 800x600 resolution but they were resized to fit this document better.
We have a blue football table which has score "boards" for both players. Left score blocks are white and they have small orange labels on them. Right score blocks are blue and they have small white labels on them.
Goal is to count score for each player based on the score blocks' positions. In the example image left score is 1 and right score is 3.
This will prevent OpenCV from cutting image edges when rotating.
This contains a few steps
- Take the canvas
- Find blue table with HSV threshold for blue hue
- Find table corners from the binary(black and white) image
- Calculate the lower long side of table of corner points
- Rotate image with the found line to straighten table
Since the table is straightened, ordering corner points to top left, bottom left .. etc. is possible.
Left score blocks. HSV threshold for orange hue is applied.
Right score blocks. Normal threshold which finds bright areas is applied.
The outermost blocks are not actual score blocks. They are blocks which hold the actual score blocks in place.
Find separate objects and their centers from black and white image
Now that we have 12 center coordinates for objects, we can find where the biggest gap between blocks is. From that information it is possible to count score.
You need Python and a few dependencies:
- OpenCV >= 2.4.4
- Numpy
- Scipy
These might be tricky to install. I created new Ubuntu 13.10 vagrant box and installed dependencies with apt-get:
sudo apt-get install git python-opencv python-pip python-scipy