After playing Sudoku for a while, it becomes repetitive. That’s why I’ve created a device that solves Sudoku puzzles for me. It uses a camera to read the location of the given numbers in the puzzle, then solves it in the way I would do it by hand.
The setup
- Sudoku Puzzle.
The one in this example is from Denksport, please visit them at https://www.denksport.com/puzzel/sudoku if you like puzzles. - Simple webcam to get an image of the puzzle.
- Plotter to write the numbers of the solution.
- Computer with software to control the whole process.
How it’s done
1. Read input
The webcam is used to capture an image.
To prepare the image for reading the numbers, it is rotated, cropped, converted to black and white and the horizontal and vertical lines of the Sudoku grid are removed. Image processing with OpenCV did the trick.
Once the input image is cleaned up, Tesseract OCR is used to read the number from each of the cells.
2. Compute
Now we have a list with all the input values in rows and columns.
To solve the Sudoku, I wrote a Python script that follows the same steps that I would take to solve the Sudoku.
I think solving the puzzle in this way makes plotting the solution more natural. The pen moves all over the grid instead of starting at the top left cell and writing the values row by row.
3. Write output
The plotter writes the numbers in my handwriting, so it looks like I actually did something to solve it.
The whole process from capturing the image to writing the last number takes about five minutes.