def delete_lines(input_file,
                 lines,
                 probabilistic=False,
                 line_length=1000,
                 width=5,
                 color=(255, 255, 255)):
    """
    >>> lines = detect_lines(test_image)
    >>> isinstance(delete_lines(test_image, lines), np.ndarray)
    True

    >>> lines = detect_lines(test_image, probabilistic=True)
    >>> isinstance(delete_lines(test_image, lines, probabilistic=True), np.ndarray)
    True

    >>> delete_lines(None, lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> delete_lines("", lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> delete_lines("fakeRoute", lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> delete_lines(test_image, None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Lines can't be None.

    >>> delete_lines(test_image, lines, line_length=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Line_length value must be greater than 0.

    >>> delete_lines(test_image, lines, width=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Width value must be greater than 0.

    >>> delete_lines(test_image, lines, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).
    """

    # Checking arguments
    check_lines(lines)
    check_line_length(line_length)
    check_width(width)
    iu.check_color(color)

    image = iu.get_image(input_file)

    return draw_lines(image, lines, probabilistic, line_length, width, color)
Example #2
0
def draw_corners(input_file,
                 corners,
                 radius=5,
                 color=(0, 0, 255),
                 thickness=-1):
    """
    >>> corners = detect_corners(test_image)
    >>> isinstance(draw_corners(test_image, corners), np.ndarray)
    True

    >>> draw_corners(None, corners)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> draw_corners("", corners)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> draw_corners("fakeRoute", corners)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> draw_corners(test_image, None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Corners can't be None.

    >>> draw_corners(test_image, [])
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Corners can't be void.

    >>> draw_corners(test_image, corners, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).

    >>> draw_corners(test_image, corners, radius=-5)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Radius value must be greater than 0.
    """

    # Checking arguments
    check_corners(corners)
    check_radius(radius)
    iu.check_color(color)

    img = iu.get_image(input_file)

    for i in corners:
        x, y = i.ravel()
        cv.circle(img, (x, y), radius, color, thickness)

    return img
def delete_lines(input_file, lines, probabilistic=False, line_length=1000,
                 width=5, color=(255, 255, 255)):
    """
    >>> lines = detect_lines(test_image)
    >>> isinstance(delete_lines(test_image, lines), np.ndarray)
    True

    >>> lines = detect_lines(test_image, probabilistic=True)
    >>> isinstance(delete_lines(test_image, lines, probabilistic=True), np.ndarray)
    True

    >>> delete_lines(None, lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> delete_lines("", lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> delete_lines("fakeRoute", lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> delete_lines(test_image, None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Lines can't be None.

    >>> delete_lines(test_image, lines, line_length=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Line_length value must be greater than 0.

    >>> delete_lines(test_image, lines, width=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Width value must be greater than 0.

    >>> delete_lines(test_image, lines, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).
    """

    # Checking arguments
    check_lines(lines)
    check_line_length(line_length)
    check_width(width)
    iu.check_color(color)

    image = iu.get_image(input_file)

    return draw_lines(image, lines, probabilistic, line_length, width, color)
Example #4
0
def draw_corners(input_file, corners, radius=5, color=(0, 0, 255), thickness=-1):
    """
    >>> corners = detect_corners(test_image)
    >>> isinstance(draw_corners(test_image, corners), np.ndarray)
    True

    >>> draw_corners(None, corners)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> draw_corners("", corners)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> draw_corners("fakeRoute", corners)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> draw_corners(test_image, None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Corners can't be None.

    >>> draw_corners(test_image, [])
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Corners can't be void.

    >>> draw_corners(test_image, corners, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).

    >>> draw_corners(test_image, corners, radius=-5)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Radius value must be greater than 0.
    """

    # Checking arguments
    check_corners(corners)
    check_radius(radius)
    iu.check_color(color)

    img = iu.get_image(input_file)

    for i in corners:
        x, y = i.ravel()
        cv.circle(img, (x, y), radius, color, thickness)

    return img
Example #5
0
def draw_contours(input_file, contours, thickness=0, color=(0, 0, 255)):
    """
    >>> contours = detect_contours(test_image)
    >>> isinstance(draw_contours(test_image, contours), np.ndarray)
    True

    >>> draw_contours(None, contours)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> draw_contours("", contours)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> draw_contours("fakeRoute", contours)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> draw_contours(test_image, None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Contours can't be None.

    >>> draw_contours(test_image, [])
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Contours can't be void.

    >>> draw_contours(test_image, contours, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).
    """

    # Checking arguments
    check_contours(contours)
    iu.check_color(color)

    image = iu.get_image(input_file)

    for cnt in contours:
        cv.drawContours(image, [cnt], 0, color, thickness)

    return image
Example #6
0
def draw_contours(input_file, contours, thickness=0, color=(0, 0, 255)):
    """
    >>> contours = detect_contours(test_image)
    >>> isinstance(draw_contours(test_image, contours), np.ndarray)
    True

    >>> draw_contours(None, contours)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> draw_contours("", contours)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> draw_contours("fakeRoute", contours)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> draw_contours(test_image, None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Contours can't be None.

    >>> draw_contours(test_image, [])
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Contours can't be void.

    >>> draw_contours(test_image, contours, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).
    """

    # Checking arguments
    check_contours(contours)
    iu.check_color(color)

    image = iu.get_image(input_file)

    for cnt in contours:
        cv.drawContours(image, [cnt], 0, color, thickness)

    return image
Example #7
0
def delete_border_noise(input_file, width=20, color=(255, 255, 255)):
    """
    >>> isinstance(delete_border_noise(test_image), np.ndarray)
    True

    >>> delete_border_noise(None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> delete_border_noise("")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> delete_border_noise("fakeRoute")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> delete_border_noise(test_image, width=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Width value must be greater than 0.

    >>> delete_border_noise(test_image, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).
    """

    # Checking arguments
    iu.check_color(color)
    check_width(width)

    image = iu.get_image(input_file)

    image = iu.pyramid_clean(image)

    image[0:width, :] = color
    image[:, 0:width] = color
    image[:, -width:] = color
    image[-width:, :] = color

    return image
Example #8
0
def delete_border_noise(input_file, width=20, color=(255, 255, 255)):
    """
    >>> isinstance(delete_border_noise(test_image), np.ndarray)
    True

    >>> delete_border_noise(None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> delete_border_noise("")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> delete_border_noise("fakeRoute")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> delete_border_noise(test_image, width=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Width value must be greater than 0.

    >>> delete_border_noise(test_image, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).
    """

    # Checking arguments
    iu.check_color(color)
    check_width(width)

    image = iu.get_image(input_file)

    image = iu.pyramid_clean(image)

    image[0:width, :] = color
    image[:, 0:width] = color
    image[:, -width:] = color
    image[-width:, :] = color

    return image
def draw_lines(input_file, lines, probabilistic=False,
               line_length=1000, width=5, color=(0, 0, 255)):
    """
    >>> lines = detect_lines(test_image)
    >>> isinstance(draw_lines(test_image, lines), np.ndarray)
    True

    >>> linesp = detect_lines(test_image, probabilistic=True)
    >>> isinstance(draw_lines(test_image, linesp, probabilistic=True), np.ndarray)
    True

    >>> draw_lines(None, lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> draw_lines("", lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> draw_lines("fakeRoute", lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> draw_lines(test_image, None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Lines can't be None.

    >>> draw_lines(test_image, lines, line_length=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Line_length value must be greater than 0.

    >>> draw_lines(test_image, lines, width=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Width value must be greater than 0.

    >>> draw_lines(test_image, lines, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).
    """

    # Checking arguments
    check_lines(lines)
    check_line_length(line_length)
    check_width(width)
    iu.check_color(color)

    # Loading the image
    image = iu.get_image(input_file)

    if np.size(lines[0]) == 1:
        l_array = [lines]
    else:
        l_array = lines[0]

    for l in l_array:
        x1, y1, x2, y2 = get_line_coordinates(l, probabilistic, line_length)
        p1 = (x1, y1)
        p2 = (x2, y2)
        cv.line(image, p1, p2, color, width)

    return image
def delete_all_lines(input_file, probabilistic=False,
                     min_val=50, max_val=200, aperture_size=3,
                     rho=1, theta=np.pi/180, threshold=200,
                     min_line_length=30, max_line_gap=20,
                     line_length=1000, width=5, color=(255, 255, 255)):
    """
    >>> isinstance(delete_all_lines(test_image), np.ndarray)
    True

    >>> isinstance(delete_all_lines(test_image, probabilistic=True), np.ndarray)
    True

    >>> delete_all_lines(None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> delete_all_lines("")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> delete_all_lines("fakeRoute")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> delete_all_lines(test_image, min_val=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Min_val value must be between 0 and 255.

    >>> delete_all_lines(test_image, max_val=300)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Max_val value must be between 0 and 255.

    >>> delete_all_lines(test_image, min_val=100, max_val=30)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Min_val value must be lesser than max_val.

    >>> delete_all_lines(test_image, aperture_size=-3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Aperture_size value must be greater than 0.

    >>> delete_all_lines(test_image, rho=-3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Rho value must be greater than 0.

    >>> delete_all_lines(test_image, theta=-3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Theta value must be greater than 0.

    >>> delete_all_lines(test_image, threshold=-3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Threshold value must be greater than 0.

    >>> delete_all_lines(test_image, line_length=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Line_length value must be greater than 0.

    >>> delete_all_lines(test_image, width=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Width value must be greater than 0.

    >>> delete_all_lines(test_image, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).
    """

    # Checking arguments
    if probabilistic is False:
        check_line_length(line_length)

    check_canny_args(min_val, max_val, aperture_size)
    check_houghlines_args(rho, theta, threshold, min_line_length, max_line_gap,
                          probabilistic)
    check_width(width)
    iu.check_color(color)

    image = iu.get_image(input_file)

    lines = detect_lines(image, probabilistic, min_val, max_val, aperture_size,
                         rho, theta, threshold, min_line_length, max_line_gap)

    while lines is not None:
        image = delete_lines(image, lines, probabilistic, line_length, width,
                             color)
        lines = detect_lines(image, probabilistic, rho, theta, threshold,
                             min_line_length, max_line_gap)

    return image
Example #11
0
def draw_lines(input_file,
               lines,
               probabilistic=False,
               line_length=1000,
               width=5,
               color=(0, 0, 255)):
    """
    >>> lines = detect_lines(test_image)
    >>> isinstance(draw_lines(test_image, lines), np.ndarray)
    True

    >>> linesp = detect_lines(test_image, probabilistic=True)
    >>> isinstance(draw_lines(test_image, linesp, probabilistic=True), np.ndarray)
    True

    >>> draw_lines(None, lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> draw_lines("", lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> draw_lines("fakeRoute", lines)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> draw_lines(test_image, None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Lines can't be None.

    >>> draw_lines(test_image, lines, line_length=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Line_length value must be greater than 0.

    >>> draw_lines(test_image, lines, width=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Width value must be greater than 0.

    >>> draw_lines(test_image, lines, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).
    """

    # Checking arguments
    check_lines(lines)
    check_line_length(line_length)
    check_width(width)
    iu.check_color(color)

    # Loading the image
    image = iu.get_image(input_file)

    if np.size(lines[0]) == 1:
        l_array = [lines]
    else:
        l_array = lines[0]

    for l in l_array:
        x1, y1, x2, y2 = get_line_coordinates(l, probabilistic, line_length)
        p1 = (x1, y1)
        p2 = (x2, y2)
        cv.line(image, p1, p2, color, width)

    return image
Example #12
0
def delete_all_lines(input_file,
                     probabilistic=False,
                     min_val=50,
                     max_val=200,
                     aperture_size=3,
                     rho=1,
                     theta=np.pi / 180,
                     threshold=200,
                     min_line_length=30,
                     max_line_gap=20,
                     line_length=1000,
                     width=5,
                     color=(255, 255, 255)):
    """
    >>> isinstance(delete_all_lines(test_image), np.ndarray)
    True

    >>> isinstance(delete_all_lines(test_image, probabilistic=True), np.ndarray)
    True

    >>> delete_all_lines(None)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be a None object

    >>> delete_all_lines("")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: The input file can't be ''.

    >>> delete_all_lines("fakeRoute")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    IOError: Input file not found.

    >>> delete_all_lines(test_image, min_val=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Min_val value must be between 0 and 255.

    >>> delete_all_lines(test_image, max_val=300)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Max_val value must be between 0 and 255.

    >>> delete_all_lines(test_image, min_val=100, max_val=30)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Min_val value must be lesser than max_val.

    >>> delete_all_lines(test_image, aperture_size=-3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Aperture_size value must be greater than 0.

    >>> delete_all_lines(test_image, rho=-3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Rho value must be greater than 0.

    >>> delete_all_lines(test_image, theta=-3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Theta value must be greater than 0.

    >>> delete_all_lines(test_image, threshold=-3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Threshold value must be greater than 0.

    >>> delete_all_lines(test_image, line_length=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Line_length value must be greater than 0.

    >>> delete_all_lines(test_image, width=-10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Width value must be greater than 0.

    >>> delete_all_lines(test_image, color=(-10, 0, 0))
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    ValueError: Color value must be: (0-255, 0-255, 0-255).
    """

    # Checking arguments
    if probabilistic is False:
        check_line_length(line_length)

    check_canny_args(min_val, max_val, aperture_size)
    check_houghlines_args(rho, theta, threshold, min_line_length, max_line_gap,
                          probabilistic)
    check_width(width)
    iu.check_color(color)

    image = iu.get_image(input_file)

    lines = detect_lines(image, probabilistic, min_val, max_val, aperture_size,
                         rho, theta, threshold, min_line_length, max_line_gap)

    while lines is not None:
        image = delete_lines(image, lines, probabilistic, line_length, width,
                             color)
        lines = detect_lines(image, probabilistic, rho, theta, threshold,
                             min_line_length, max_line_gap)

    return image