def detect_sudoku(img): sudoku_detector = SudokuDetector(img) sudoku_frame, sudoku_rectangles, max_approx, found = sudoku_detector.get_sudoku_from_image() if not found: return [], [] # Uncomment this section if you would like to see the sudoku with rectangles found. # sd.draw_sudoku() # cv2.imshow("Sudoku with rectangles found", img) # cv2.waitKey(0) bounding_boxes = [] for each in [sudoku_frame] + sudoku_rectangles: x, y, w, h = cv2.boundingRect(each) x_left, y_left, x_right, y_right = x, y, x + w, y + h bounding_boxes.append([(x_left, y_left), (x_right, y_right)]) # for b in bounding_boxes: # (x_left, y_left), (x_right, y_right) = b # cv2.rectangle(img, (x_left, y_left), (x_right, y_right), color=(0, 0, 255), thickness=2) return bounding_boxes, max_approx