示例#1
0
def draw_angle(image, angle, offset=(0, 0), color=(0, 0, 255), thickness=1, color2=(255, 0, 0), thickness2=1):
    line0 = instantiators['line'](angle.b, angle.a)
    line1 = instantiators['line'](angle.b, angle.c)
    draw_line(image, line0, offset=offset, color=color, thickness=thickness)
    draw_line(image, line1, offset=offset, color=color, thickness=thickness)
    radius = 0.3 * min(line_length(line0), line_length(line1))
    circle = instantiators['circle'](angle.b, radius)
    # FIXME : this arc definition is broken. Okay for now, but needs to fix.
    arc = instantiators['arc'](circle, angle.a, angle.c)
    draw_arc(image, arc, offset=offset, color=color2, thickness=thickness2)
def _get_pixels_near_line(pixels, line, eps):
    """
    This can be replaced with shorter, more inefficient code.
    Written to boost up the speed.
    :param pixels:
    :param line:
    :param eps:
    :return:
    """
    #return set(pixel for pixel in pixels if distance_between_line_and_point(line, pixel) <= eps)

    p = midpoint(line.a, line.b)
    u = line_unit_vector(line)
    n = line_normal_vector(line)
    half_length = line_length(line) / 2.0
    eps_squared = eps**2

    near_pixels = set()
    for point in pixels:
        vector = point.x - p.x, point.y - p.y
        perpendicular_distance = abs(np.dot(vector, n))
        if perpendicular_distance > eps:
            continue
        parallel_distance = abs(np.dot(vector, u))
        if parallel_distance <= half_length:
            near_pixels.add(point)
        else:
            if distance_between_points_squared(point, line.a) <= eps_squared or \
                    distance_between_points_squared(point, line.b) <= eps_squared:
                near_pixels.add(point)
    return near_pixels
示例#3
0
def _get_pixels_near_line(pixels, line, eps):
    """
    This can be replaced with shorter, more inefficient code.
    Written to boost up the speed.
    :param pixels:
    :param line:
    :param eps:
    :return:
    """
    #return set(pixel for pixel in pixels if distance_between_line_and_point(line, pixel) <= eps)

    p = midpoint(line.a, line.b)
    u = line_unit_vector(line)
    n = line_normal_vector(line)
    half_length = line_length(line)/2.0
    eps_squared = eps**2

    near_pixels = set()
    for point in pixels:
        vector = point.x - p.x, point.y - p.y
        perpendicular_distance = abs(np.dot(vector, n))
        if perpendicular_distance > eps:
            continue
        parallel_distance = abs(np.dot(vector, u))
        if parallel_distance <= half_length:
            near_pixels.add(point)
        else:
            if distance_between_points_squared(point, line.a) <= eps_squared or \
                    distance_between_points_squared(point, line.b) <= eps_squared:
                near_pixels.add(point)
    return near_pixels
示例#4
0
def _line_exists(diagram_parse, line):
    # TODO : smarter line_exists function needed (check continuity, etc.)
    eps = LINE_EPS
    multiplier = 1.0
    assert isinstance(diagram_parse, CoreParse)
    pixels = diagram_parse.primitive_parse.image_segment_parse.diagram_image_segment.pixels
    near_pixels = set(pixel for pixel in pixels if distance_between_line_and_point(line, pixel) <= eps)
    length = line_length(line)
    ratio = float(len(near_pixels))/length
    if ratio < multiplier:
        return False
    return True
示例#5
0
def _line_exists(diagram_parse, line):
    # TODO : smarter line_exists function needed (check continuity, etc.)
    eps = LINE_EPS
    multiplier = 1.0
    assert isinstance(diagram_parse, CoreParse)
    pixels = diagram_parse.primitive_parse.image_segment_parse.diagram_image_segment.pixels
    near_pixels = set(pixel for pixel in pixels
                      if distance_between_line_and_point(line, pixel) <= eps)
    length = line_length(line)
    ratio = float(len(near_pixels)) / length
    if ratio < multiplier:
        return False
    return True
示例#6
0
def label_distance_to_line(label_point, line, is_length):
    """
    minimum distance among:
    end points, mid point.

    :param point:
    :param line:
    :return:
    """
    mp = midpoint(line.a, line.b)
    distance = distance_between_points(label_point, mp)
    if is_length:
        return distance

    l = 1.0/line_length(line)  # To favor longer line if matching near the points
    return min(distance,
               distance_between_points(label_point, line.a) + l,
               distance_between_points(label_point, line.b) + l)
示例#7
0
def label_distance_to_line(label_point, line, is_length):
    """
    minimum distance among:
    end points, mid point.

    :param point:
    :param line:
    :return:
    """
    mp = midpoint(line.a, line.b)
    distance = distance_between_points(label_point, mp)
    if is_length:
        return distance

    l = 1.0 / line_length(
        line)  # To favor longer line if matching near the points
    return min(distance,
               distance_between_points(label_point, line.a) + l,
               distance_between_points(label_point, line.b) + l)
示例#8
0
def lengthOf(line):
    return line_length(line)
def LengthOf(twod):
    if isinstance(twod, instantiators['line']):
        return line_length(twod)
    elif isinstance(twod, instantiators['arc']):
        circle, a, b = twod
        return circle.radius * (b - a)
示例#10
0
def LengthOf(line):
    return line_length(line)