sorce code .py
sorce code .py
import numpy as np
import pytesseract
import matplotlib.pyplot as plt
from PIL import Image
# Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Apply thresholding
_, thresh = cv2.threshold(gray, 150, 255,
cv2.THRESH_BINARY_INV)
return grid
return True
def solve_sudoku(board):
"""
Solves the Sudoku puzzle using the backtracking algorithm.
"""
for row in range(9):
for col in range(9):
if board[row][col] == 0: # Find empty spot
for num in range(1, 10): # Try digits 1-9ss
board[row][col] = num
if solve_sudoku(board):
return True
board[row][col] = 0 # Backtrack
return False
return True # Puzzle solved
def print_board(board):
"""
Prints the Sudoku board in a readable format.
"""
for row in board:
print(" ".join(str(num) for num in row))