def extract_square_from_contour(contour):
    the_image = Image.generate_mask(Contour.get_shape(contour))
    # Display.contours(the_image, [contour])
    cv2.drawContours(the_image, [contour], -1, 255, 1)
    # Display.image(the_image)
    # lines = PolarLines.find_suitable_lines(the_image)
    square_ragion = the_image
    vertical_lines = find_vertical_lines(square_ragion)
    border_line_count = 2
    if len(vertical_lines) > border_line_count:
        raise SudokuError("The count of vertical border lines is larger than {0}".format(border_line_count))

    horizontal_lines = find_horizontal_lines(square_ragion)
    if len(horizontal_lines) > border_line_count:
        raise SudokuError("The count of horizontal border lines is larger than {0}".format(border_line_count))
    Display.polar_lines(square_ragion, vertical_lines + horizontal_lines)
    # Display.polar_lines(square_ragion, horizontal_lines)

    intersections = main_analyzer.find_intersections(vertical_lines, horizontal_lines)
    # intersections.ppl()
    Points.to_contour(intersections).ppl()
def extract_square_from_contour(contour):
    '''
        it will extract square from the contour which could have many noise points.
    '''
    the_image = Image.generate_mask(Contour.get_shape(contour))
    # Display.contours(the_image, [contour])
    cv2.drawContours(the_image, [contour], -1, 255 ,1)
    # Display.image(the_image)
    # lines = PolarLines.find_suitable_lines(the_image)
    square_ragion = the_image
    vertical_lines = find_vertical_lines(square_ragion)

    horizontal_lines = find_horizontal_lines(square_ragion)
    # flag_test()
    # Display.polar_lines(square_ragion, vertical_lines+horizontal_lines)

    border_line_count = 2
    if len(vertical_lines) > border_line_count:
        logger.info("The count of vertical border lines is larger than {0}"
            .format(border_line_count))
        vertical_lines = [vertical_lines[0],vertical_lines[-1]]
    if len(horizontal_lines) > border_line_count:
        logger.info("The count of horizontal border lines is larger than {0}"
            .format(border_line_count))
        horizontal_lines = [horizontal_lines[0],horizontal_lines[-1]]

    # flag_test()
    # Display.polar_lines(square_ragion, vertical_lines+horizontal_lines)

    intersections = find_intersections(vertical_lines, horizontal_lines)
    # intersections.ppl()
    square_contour =  Points.to_contour(intersections)
    # order the points
    square_contour = Points.to_contour(Quadrilateral.vertices(square_contour))
    # 'test'.pl()
    # Display.contours(the_image,[square_contour])
    return square_contour
示例#3
0
        the_line = numpy.array([  340,   0.06] )
        PolarLines.adjust_theta_when_rho_0_and_near_180(the_line).must_close(
            the_line)

        # the_image = Image.generate_mask((800,600))
        # Display.polar_lines(the_image, [the_line])



    with test("show line degree"):
        # 2,3,5 same, 1,4 same
        line1 = PolarLines.create_from_rho_and_degree(10, 178)
        line2 = PolarLines.create_from_rho_and_degree(10, -2)
        line3 = PolarLines.create_from_rho_and_degree(-10, -182)
        line4 = PolarLines.create_from_rho_and_degree(-10, -2)
        line5 = PolarLines.create_from_rho_and_degree(10, 358)
        the_image = Image.generate_mask((800,600))
        # # # Display.polar_lines(the_image, [line2,line3, line4])
        # Display.polar_lines(the_image, [line1, line2])
        # Display.polar_lines(the_image, [line2,])


        lines = [numpy.array([ 1.        , -0.12217298]),
                 numpy.array([ 1.        ,  3.01941967]),
                 numpy.array([ 3.        ,  3.00196624]),
                 numpy.array([ 5.        ,  3.00196624]),
                 numpy.array([ 7.        ,  3.00196624])]
        # Display.polar_lines(the_image, lines[:1])
        # Display.polar_lines(the_image, lines[:1])