def find_vertical_lines(gray_image):
    # gray_image = cv2.GaussianBlur(gray_image,ksize=(5,5), sigmaX=0)
    # let the horizen lines dispear
    dx_image = cv2.Sobel(gray_image, cv2.CV_16S, 2, 0)
    # convert from dtype=int16 to dtype=uint8
    dx_image = cv2.convertScaleAbs(dx_image)

    # detect the edges
    low_threshold, high_threshold = 40, 80
    cannied_image = cv2.Canny(dx_image, low_threshold, high_threshold)

    lines = PolarLines.find_suitable_lines(cannied_image)
    # show_lines(cannied_image, lines)

    def to_positive_rho(line):
        if line[0] < 0:
            line[0] = abs(line[0])
            line[1] = line[1] - numpy.pi
        return line

    # tansfer negative angle to positive
    lines = map(to_positive_rho, lines)

    def filter_line(line):
        rho, theta = line
        theta_degree = theta * 180 / numpy.pi
        return abs(theta_degree) < 10

    # remove the lines which have large angle
    lines = filter(filter_line, lines)
    # show_lines(cannied_image, lines)

    accuracy_pixs = gray_image.shape[1] / SUDOKU_SIZE * 0.3  # 9
    catalogued_lines = PolarLines.catalogue_lines(lines, accuracy_pixs)
    mean_lines = PolarLines.cal_mean_lines(catalogued_lines)
    # all_lines = PolarLines.fill_lost_lines(mean_lines, SUDOKU_SIZE+1)
    # show_lines(cannied_image, all_lines)

    return mean_lines
def find_horizontal_lines(gray_image):
    # gray_image = cv2.GaussianBlur(gray_image,ksize=(5,5), sigmaX=0)

    dy_image = cv2.Sobel(gray_image, cv2.CV_16S, 0, 2)
    # convert from dtype=int16 to dtype=uint8
    dy_image = cv2.convertScaleAbs(dy_image)

    low_threshold, high_threshold = 40, 80
    cannied_image = cv2.Canny(dy_image, low_threshold, high_threshold)

    lines = PolarLines.find_suitable_lines(cannied_image)

    def filter_line(line):
        rho, theta = line
        theta_degree = (theta * 180 / numpy.pi) - 90
        return abs(theta_degree) < 10

    lines = filter(filter_line, lines)
    accuracy_pixs = gray_image.shape[0] / SUDOKU_SIZE * 0.3  # 9

    catalogued_lines = PolarLines.catalogue_lines(lines, accuracy_pixs)
    mean_lines = PolarLines.cal_mean_lines(catalogued_lines)
    return mean_lines