Skip to content
Snippets Groups Projects
Commit 137dc2e9 authored by zalonzo2's avatar zalonzo2
Browse files

Some final comments and added some sources that can be found in my notebook as well

parent 4dd5c21c
Branches main
No related tags found
No related merge requests found
......@@ -95,6 +95,8 @@ def find_lines(img):
return sorted_vertical, sorted_horizontal
def convert_to_cartesian(lines):
# used for HoughLines
# www.geeksforgeeks.org/line-detection-python-opencv-houghline-method/
line_points = []
if lines is not None:
for line in lines:
......@@ -145,6 +147,10 @@ def filter_lines(lines, min_distance):
return filtered_lines
def find_board(img):
# https://opencvpython.blogspot.com/2012/06/sudoku-solver-part-2.html
# https://stackoverflow.com/questions/10196198/how-to-remove-convexity-defects-in-a-sudoku-square/11366549#11366549
# ^ two sources that were very useful for the board detection code
vertical_lines, horizontal_lines = find_lines(img)
# create bitmasks for vert and horiz so we can get lines and intersections
......@@ -280,7 +286,7 @@ def warp_board(img, corners_sorted, intersection):
return warped_img, sorted_warped_points
prev_filled_contour_mask = None
prev_filled_contour_mask = None # probably should have stored this in game.py instead
def find_pieces(warped_img, prev_warped_img, sorted_warped_points, reader, img_idx):
global prev_filled_contour_mask
......@@ -485,6 +491,7 @@ def find_pieces(warped_img, prev_warped_img, sorted_warped_points, reader, img_i
if len(box_contours_sorted) != 0:
# straighten the letter based on its contours' bounding box
# https://stackoverflow.com/questions/11627362/how-to-straighten-a-rotated-rectangle-area-of-an-image-using-opencv-in-python <- this helped a lot
box_contour = box_contours_sorted[0]
drawn_box_img = cv2.cvtColor(box_img, cv2.COLOR_GRAY2BGR)
cv2.drawContours(drawn_box_img, [box_contour], -1, (255, 255, 0), 1)
......@@ -547,7 +554,7 @@ def find_pieces(warped_img, prev_warped_img, sorted_warped_points, reader, img_i
img_to_read_bigger = np.zeros((cols + 40, rows + 40))
img_to_read_bigger = img_to_read_bigger.astype(np.uint8)
# put img_to_read in center of img_to_read_bigger
# put img_to_read in center of img_to_read_bigger (probably should have made this section a separate function)
start_row = int((img_to_read_bigger.shape[0] - img_to_read.shape[0]) // 2)
start_col = int((img_to_read_bigger.shape[1] - img_to_read.shape[1]) // 2)
end_row = start_row + img_to_read.shape[0]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment