Skip to content

Commit

Permalink
added display_sudoku function
Browse files Browse the repository at this point in the history
  • Loading branch information
aakashjhawar committed Dec 19, 2018
1 parent d1e72b5 commit 5066035
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ cd SolveSudoku
python3 sudoku.py <path/to/input_image>
```

### Prerequisites
## Prerequisites

- Python 3.5
- OpenCV
```
sudo apt-get install python-opencv
```
### Procedure
## Procedure
> 1. Image preprocessing (Thresholding).
> 2. Find the largest contour (sudoku square).
> 3. Get the cordinates of **largest contour**.
Expand All @@ -29,7 +29,7 @@ sudo apt-get install python-opencv
> 7. Remove noise in block.
> 8. Send the number to pre trained Digit Recogition model.
> 9. Send the grid to Sudoku Solver to perform the final step.
### Working
## Working

#### Input image of Sudoku-
![Input image of sudoku](https://github.com/aakashjhawar/SolveSudoku/blob/master/images/sudoku.jpg)
Expand All @@ -45,3 +45,10 @@ sudo apt-get install python-opencv

#### Final output of ExtractSudoku-
![Final image of sudoku](https://github.com/aakashjhawar/SolveSudoku/blob/master/images/final.jpg)


#### Extracted grid-
![extracted grid](https://github.com/aakashjhawar/SolveSudoku/blob/master/images/extracted_grid.jpg)

#### Solved grid-
![Solved grid](https://github.com/aakashjhawar/SolveSudoku/blob/master/images/solved_gird.jpg)
6 changes: 3 additions & 3 deletions SolveSudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
def print_grid(arr):
for i in range(9):
for j in range(9):
print (arr[i][j])
# print ('n')
# print (arr[i][j])

# Function to Find the entry in the Grid that is still not used
# Searches the grid to find an entry that is still unassigned. If
Expand Down Expand Up @@ -95,7 +95,7 @@ def solve_sudoku(arr):
# Driver main function to test above functions
def sudoku_solver(grid):
if(solve_sudoku(grid)):
print_grid(grid)
# print_grid(grid)
else:
print ("No solution exists")
grid = grid.astype(int)
Expand Down
29 changes: 23 additions & 6 deletions sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,37 @@
from NumberExtractor import extract_number
from SolveSudoku import sudoku_solver

def display_sudoku(sudoku):
for i in range(9):
for j in range(9):
cell = sudoku[i][j]
if cell == 0 or isinstance(cell, set):
output('.')
else:
output(cell)
if (j + 1) % 3 == 0 and j < 8:
output(' |')

if j != 8:
output(' ')
output('\n')
if (i + 1) % 3 == 0 and i < 8:
output("--------+----------+---------\n")

def main(image_path):
image = extract_sudoku(image_path)
try:
cv2.imshow('Sudoku', image)
except:
print('ERROR')
grid = extract_number(image)
print(grid)
print('Sudoku:')
display_sudoku(grid.tolist())
solution = sudoku_solver(grid)
print('Solution')
print(solution)



print('Solution:')
# print(solution)
display_sudoku(solution.tolist())

if __name__ == '__main__':
# image_path = 'images/sudoku.jpg'
# main(image_path)
Expand Down

0 comments on commit 5066035

Please sign in to comment.