Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,11 @@ import numpy as np
|
|
8 |
model = load_model('sudoku_net.h5')
|
9 |
|
10 |
def preprocess(image):
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
# blur = cv2.GaussianBlur(gray, (3,3),6)
|
13 |
blur = cv2.bilateralFilter(gray,9,75,75)
|
14 |
threshold_img = cv2.adaptiveThreshold(blur,255,1,1,11,2)
|
@@ -167,10 +171,10 @@ def main():
|
|
167 |
if uploaded_file is not None:
|
168 |
col1, col2 = st.columns(2)
|
169 |
col1.subheader("Sudoku Puzzle:")
|
170 |
-
puzzle = cv2.imread(uploaded_file)
|
171 |
-
|
172 |
col1.image(puzzle, use_column_width=True)
|
173 |
-
|
174 |
|
175 |
# Resizing puzzle to be solved
|
176 |
puzzle = cv2.resize(puzzle, (450,450))
|
@@ -192,7 +196,13 @@ def main():
|
|
192 |
su_pts2 = np.float32([[0,0],[450,0],[0,450],[450,450]])
|
193 |
su_matrix = cv2.getPerspectiveTransform(su_pts1,su_pts2)
|
194 |
su_imagewrap = cv2.warpPerspective(puzzle,su_matrix,(450,450))
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
_, su_imagewrap = cv2.threshold(su_imagewrap, 127, 255, cv2.THRESH_BINARY)
|
197 |
|
198 |
sudoku_cell = splitcells(su_imagewrap)
|
|
|
8 |
model = load_model('sudoku_net.h5')
|
9 |
|
10 |
def preprocess(image):
|
11 |
+
if len(image.shape) == 2:
|
12 |
+
gray = image # No need to convert, it's already grayscale
|
13 |
+
else:
|
14 |
+
# Convert RGB image to grayscale using OpenCV
|
15 |
+
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
16 |
# blur = cv2.GaussianBlur(gray, (3,3),6)
|
17 |
blur = cv2.bilateralFilter(gray,9,75,75)
|
18 |
threshold_img = cv2.adaptiveThreshold(blur,255,1,1,11,2)
|
|
|
171 |
if uploaded_file is not None:
|
172 |
col1, col2 = st.columns(2)
|
173 |
col1.subheader("Sudoku Puzzle:")
|
174 |
+
# puzzle = cv2.imread(uploaded_file)
|
175 |
+
puzzle = Image.open(uploaded_file)
|
176 |
col1.image(puzzle, use_column_width=True)
|
177 |
+
puzzle = np.asarray(puzzle)
|
178 |
|
179 |
# Resizing puzzle to be solved
|
180 |
puzzle = cv2.resize(puzzle, (450,450))
|
|
|
196 |
su_pts2 = np.float32([[0,0],[450,0],[0,450],[450,450]])
|
197 |
su_matrix = cv2.getPerspectiveTransform(su_pts1,su_pts2)
|
198 |
su_imagewrap = cv2.warpPerspective(puzzle,su_matrix,(450,450))
|
199 |
+
|
200 |
+
# su_imagewrap =cv2.cvtColor(su_imagewrap, cv2.COLOR_BGR2GRAY)
|
201 |
+
if len(su_imagewrap.shape) == 2:
|
202 |
+
su_imagewrap = su_imagewrap # No need to convert, it's already grayscale
|
203 |
+
else:
|
204 |
+
# Convert RGB image to grayscale using OpenCV
|
205 |
+
su_imagewrap = cv2.cvtColor(su_imagewrap, cv2.COLOR_RGB2GRAY)
|
206 |
_, su_imagewrap = cv2.threshold(su_imagewrap, 127, 255, cv2.THRESH_BINARY)
|
207 |
|
208 |
sudoku_cell = splitcells(su_imagewrap)
|