예제 #1
0
def find_vertical_lines(gray_image):
    # gray_image = cv2.GaussianBlur(gray_image,ksize=(5,5), sigmaX=0)
    # let the horizen lines dispear
    # flag_test()
    # Display.image(gray_image)
    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)
    # Display.polar_lines(cannied_image, lines)

    # tansfer negative angle to positive
    lines = map(PolarLines.adjust_to_positive_rho_line, lines)
    # lines.ppl()
    # Display.polar_lines(cannied_image, lines)
    lines = map(PolarLines.adjust_theta_when_rho_0_and_near_180, lines)
    # lines.ppl()
    # Display.polar_lines(cannied_image, lines)
    # lines = map(to_positive_rho, lines)
    # flag_test()
    # Display.polar_lines(cannied_image, lines)

    def filter_line(line):
        rho, theta = line
        # larger than 170, 10 degree equal 0.174444, 180 degree equal 3.14
        if theta > 3.14 - 0.174:
            theta = 3.14 - theta
        return abs(theta) < 0.174
        # theta_degree = (theta * 180/ numpy.pi)
        # # (rho, theta_degree).pl()
        # # 180 and 0 are same to the line's theta.
        # if theta_degree > 170:
        #     theta_degree = 180 - theta_degree
        # return abs(theta_degree) < 10
    # remove the lines which have large angle
    # Display.polar_lines(cannied_image, lines)
    lines = filter(filter_line, lines)
    # flag_test()
    # Display.polar_lines(cannied_image, lines)

    accuracy_pixs = gray_image.shape[1] / SUDOKU_SIZE *0.3 # 9
    catalogued_lines = PolarLines.catalogue_lines(lines, accuracy_pixs)
    # catalogued_lines.ppl()
    mean_lines = PolarLines.cal_mean_lines(catalogued_lines)
    # flag_test()
    # Display.polar_lines(cannied_image, mean_lines)

    return mean_lines
예제 #2
0
def find_sudoku_horizontal_lines(gray_image):
    gray_image = cv2.GaussianBlur(gray_image,ksize=(5,5), sigmaX=0)

    mean_lines = find_horizontal_lines(gray_image)

    all_lines = PolarLines.fill_lost_lines(mean_lines, SUDOKU_SIZE+1)
    # Display.polar_lines(cannied_image, all_lines)

    return all_lines
예제 #3
0
def find_sudoku_vertical_lines(gray_image):
    gray_image = cv2.GaussianBlur(gray_image,ksize=(5,5), sigmaX=0)

    mean_lines = find_vertical_lines(gray_image)

    all_lines = PolarLines.fill_lost_lines(mean_lines, SUDOKU_SIZE+1)
    # show_lines(cannied_image, all_lines)

    return all_lines
예제 #4
0
def find_intersections(vertical_lines, horizontal_lines):

    '''sometimes, the point may less than 0'''
    intersections = tuple(PolarLines.cal_intersection(v_line, h_line) 
            for h_line in horizontal_lines for v_line in vertical_lines)

    def adjust_negative(point):
        x, y = point
        return (max(0,x), max(0,y))
    intersections = map(adjust_negative, intersections)

    return numpy.array(intersections, dtype=numpy.int32)
예제 #5
0
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