def find_sudoku_number_binary_arr(gray_pic_arr): ''' Find all numbers from a picture in which there is a soduku puzzle. The number form is a binary numpy.array in which number parts are 1, the others are 0. ''' ''' notice: the threshold_value is the key, if it directly impact the binary matrix. ''' threshed_pic_array = cv2_helper.threshold_white_with_mean_percent(gray_pic_arr,0.8) cv2_helper.show_pic(threshed_pic_array) square = find_max_square(threshed_pic_array) # cv2_helper.show_contours_in_pic(threshed_pic_array, [square]) square_rect=cv2.boundingRect(square) number_rects = cv2_helper.Rect.cal_split_ragion_rects(square_rect, 9, 9) # cv2_helper.show_rects_in_pic(gray_pic_arr, number_rects) binary_pic = numpy_helper.transfer_values_quickly(threshed_pic_array, {BLACK:0, WHITE:1}) number_binary_ragions = map(lambda c: cv2_helper.get_rect_ragion_with_rect(binary_pic, c), number_rects) number_binary_ragions = map(remove_border, number_binary_ragions) non_empty_indexs, number_binary_ragions = get_nonzero_ragions_and_indexs(number_binary_ragions) # indexs.pp() # cv2_helper.show_same_size_ragions_as_pic(number_binary_ragions, 9) number_binary_ragions = map(remove_margin, number_binary_ragions) number_binary_ragions = map(enlarge, number_binary_ragions) # cv2_helper.show_pic(threshed_pic_array) # cv2_helper.show_same_size_ragions_as_pic(number_binary_ragions, 9) return number_binary_ragions, non_empty_indexs
def remove_margin(pic_array): new_rect = cv2_helper.cal_nonzero_rect_as_pic_ratio(pic_array) return cv2_helper.get_rect_ragion_with_rect(pic_array, new_rect)