Sudoku, the popular number puzzle game, is not just a test of logic but also a great exercise in problem-solving for programmers. As someone deeply passionate about software development and AI, I took on the challenge of creating a program that could solve any Sudoku puzzle.
Tesseract is an OCR engine that uses LSTM-based neural networks to recognize character patterns. Pytesseract is excellent at reading printed text, which means there is no need to build custom models unless you are going for scanning hand-crafted Sudokus
text = pytesseract.image_to_string(img, lang="eng",config='--psm 6 --oem 3')
It's easy to implement a four-point perspective transform using OpenCV and correct the skewed grid into a perfect square. This transformation greatly improves the OCR's accuracy
def four_point_transform(self, image, rect, dst, width, height):
M = cv.getPerspectiveTransform(rect, dst)
warped = cv.warpPerspective(image, M, (width, height))
return warped
Turns out there are many ways to automatically solve a Sudoku. I like the back-propagation algorithm as it is simple and works every time. It also makes the animation on Pygame very interesting.