def find_square_ragion(gray_image): # for some big size pictures which need to blur, # but cannot using ksize=(5,5), since some picture will get wrong number value. blured_image = cv2.GaussianBlur(gray_image, ksize=(3,3), sigmaX=0) # Display.image(blured_image) threshed_image = cv2.adaptiveThreshold(blured_image,WHITE, cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY_INV, blockSize=7, C=2) # flag_test() # Display.image(threshed_image) ''' It's very depend on the threshed_image. ''' max_contour = find_max_contour(threshed_image) # Display.contours(gray_image, [max_contour]) # max_contour.ppl() # 'test'.pl() # from picture_sudoku.helpers.common import Resource # numpy.save(Resource.get_path("for_issues/max_contour.npy"), max_contour) # square_contour = convert_to_square(max_contour) # this is using the border line. square_contour = extract_square_from_contour(max_contour) # square_contour.ppl() if square_contour == None: raise SudokuError("Cannot find sudoku square!") # flag_test() # Display.contours(gray_image, [square_contour]) larged_contour = Quadrilateral.enlarge(square_contour, 0.007) larged_contour = Contour.check_beyond_borders(larged_contour, gray_image.shape) # Display.contours(gray_image, [larged_contour]) # larged_contour.ppl() square_ragion = Contour.get_rect_ragion(larged_contour, gray_image) # Display.image(square_ragion) return square_ragion