gurwindersingh commited on
Commit
b7b5aa9
·
1 Parent(s): 122de80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -40,6 +40,7 @@ def reframe(points):
40
  points_new[2] = points[np.argmax(diff)]
41
  return points_new
42
 
 
43
  def splitcells(img):
44
  rows = np.vsplit(img,9)
45
  boxes = []
@@ -49,6 +50,7 @@ def splitcells(img):
49
  boxes.append(box)
50
  return boxes
51
 
 
52
  def CropCell(cells):
53
  Cells_croped = []
54
  for image in cells:
@@ -60,6 +62,7 @@ def CropCell(cells):
60
 
61
  return Cells_croped
62
 
 
63
  def read_cells(cell,model):
64
 
65
  result = []
@@ -73,7 +76,7 @@ def read_cells(cell,model):
73
  # getting predictions and setting the values if probabilities are above 65%
74
 
75
  predictions = model.predict(img)
76
- classIndex = np.argmax(model.predict(img), axis=-1)
77
  probabilityValue = np.amax(predictions)
78
 
79
  if probabilityValue > 0.65:
@@ -82,6 +85,8 @@ def read_cells(cell,model):
82
  result.append(0)
83
  return result
84
 
 
 
85
  #This function finds the next box to solve
86
 
87
  def next_box(quiz):
@@ -141,9 +146,6 @@ def Solved(quiz):
141
  else:
142
  print(str(quiz[row][col]) + " ", end="")
143
 
144
-
145
-
146
-
147
  def main():
148
  st.title('Sudoku Solver')
149
 
@@ -154,15 +156,14 @@ def main():
154
  puzzle = Image.open(uploaded_file)
155
  col1.image(puzzle, use_column_width=True)
156
  puzzle = np.asarray(puzzle)
157
-
158
  # Resizing puzzle to be solved
159
- sudoku_a = cv2.resize(puzzle, (450,450))
160
  # Preprocessing Puzzle
161
- su_puzzle = preprocess(sudoku_a)
162
 
163
  # Finding the outline of the sudoku puzzle in the image
164
  su_contour_1= su_puzzle.copy()
165
- su_contour_2= sudoku_a.copy()
166
  su_contour, hierarchy = cv2.findContours(su_puzzle,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
167
  cv2.drawContours(su_contour_1, su_contour,-1,(0,255,0),3)
168
 
@@ -183,7 +184,7 @@ def main():
183
  grid = read_cells(sudoku_cell_croped, model)
184
  grid = np.asarray(grid)
185
  grid = np.reshape(grid,(9,9))
186
- solve(grid)
187
 
188
  # Display the solution or appropriate message
189
  if solve(grid):
 
40
  points_new[2] = points[np.argmax(diff)]
41
  return points_new
42
 
43
+
44
  def splitcells(img):
45
  rows = np.vsplit(img,9)
46
  boxes = []
 
50
  boxes.append(box)
51
  return boxes
52
 
53
+
54
  def CropCell(cells):
55
  Cells_croped = []
56
  for image in cells:
 
62
 
63
  return Cells_croped
64
 
65
+
66
  def read_cells(cell,model):
67
 
68
  result = []
 
76
  # getting predictions and setting the values if probabilities are above 65%
77
 
78
  predictions = model.predict(img)
79
+ classIndex = np.argmax(predictions, axis=1)
80
  probabilityValue = np.amax(predictions)
81
 
82
  if probabilityValue > 0.65:
 
85
  result.append(0)
86
  return result
87
 
88
+
89
+
90
  #This function finds the next box to solve
91
 
92
  def next_box(quiz):
 
146
  else:
147
  print(str(quiz[row][col]) + " ", end="")
148
 
 
 
 
149
  def main():
150
  st.title('Sudoku Solver')
151
 
 
156
  puzzle = Image.open(uploaded_file)
157
  col1.image(puzzle, use_column_width=True)
158
  puzzle = np.asarray(puzzle)
 
159
  # Resizing puzzle to be solved
160
+ puzzle = cv2.resize(puzzle, (450,450))
161
  # Preprocessing Puzzle
162
+ su_puzzle = preprocess(puzzle)
163
 
164
  # Finding the outline of the sudoku puzzle in the image
165
  su_contour_1= su_puzzle.copy()
166
+ su_contour_2= puzzle.copy()
167
  su_contour, hierarchy = cv2.findContours(su_puzzle,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
168
  cv2.drawContours(su_contour_1, su_contour,-1,(0,255,0),3)
169
 
 
184
  grid = read_cells(sudoku_cell_croped, model)
185
  grid = np.asarray(grid)
186
  grid = np.reshape(grid,(9,9))
187
+ solve(grid)
188
 
189
  # Display the solution or appropriate message
190
  if solve(grid):