def last_changes(final_list_of_segments, final_list_of_circles):
    new_segments = []
    for Seg in final_list_of_segments:
        P1 = Seg.point_1
        P2 = Seg.point_2
        EPSSS = 10
        p1x = P1.x
        p1y = P1.y
        p2x = P2.x
        p2y = P2.y
        P1_new = Point(p1x, p1y)
        P2_new = Point(p2x, p2y)
        k1 = False
        k2 = False
        for circle in final_list_of_circles:
            radius_ = circle.radius
            center_ = circle.center
            distt1 = Point.distance_between(P1, center_)
            if abs(distt1 - radius_) < EPSSS:
                P1_new = circle.project_point_seg(Seg, P1)
                k1 = True
            distt2 = Point.distance_between(P2, center_)
            if abs(distt2 - radius_) < EPSSS:
                P2_new = circle.project_point_seg(Seg, P2)
                k2 = True
            if k1 and k2:
                break
        new_segments.append(Segment(P1_new, P2_new))
    return new_segments
Example #2
0
def generate_triangle(plot_side):
    min_segment = plot_side / 10
    point_1 = Point(uniform(0, plot_side), uniform(0, plot_side))
    while True:
        point_2 = Point(uniform(0, plot_side), uniform(0, plot_side))
        if Point.distance_between(point_1, point_2) > min_segment:
            break
    while True:
        point_3 = Point(uniform(0, plot_side), uniform(0, plot_side))
        if min(Point.distance_between(point_1, point_3),
               Point.distance_between(point_2, point_3)) > min_segment:
            break
    segment_1 = Segment(point_1, point_2)
    segment_2 = Segment(point_1, point_3)
    segment_3 = Segment(point_2, point_3)
    return segment_1, segment_2, segment_3
Example #3
0
def generate_segment(plot_side):
    min_segment = plot_side / 10
    point_1 = Point(uniform(0, plot_side), uniform(0, plot_side))
    while True:
        point_2 = Point(uniform(0, plot_side), uniform(0, plot_side))
        if Point.distance_between(point_1, point_2) > min_segment:
            break
    return Segment(point_1, point_2)
Example #4
0
def find_segments(image, min_dist=50, min_angel=12, thr_hough=100, num_peaks=20, angles_count=720,
                  min_segment_len=40, window_size=2, thr_segs=750):
    lines = find_lines(image, min_dist, min_angel, thr_hough, num_peaks, angles_count)[0]
    ans = []

    for line in lines:
        way = line.cross_with_rect(Point(0, 0), Point(image.shape[1], image.shape[0]))
        if way is None:
            print("Warning: line doesn't intersect image (hough.py, def find_segments)")
            continue

        dir = way.point_2 - way.point_1
        dir = dir.norm()
        start = way.point_1

        cur = start
        strick = 0
        while Point.distance_between(start, cur) < Point.distance_between(start, way.point_2):
            cur_pixel = (int(np.round(cur.y)), int(np.round(cur.x)))
            pixels_to_check = []
            for i in range(-window_size, window_size + 1):
                for j in range(-window_size, window_size + 1):
                    pixels_to_check.append((cur_pixel[0] + i, cur_pixel[1] + j))

            brightnes = 0
            for pix in pixels_to_check:
                try:
                    brightnes += image[pix[0]][pix[1]]
                except IndexError:
                    pass

            if brightnes >= thr_segs:
                if strick == 0:
                    seg_start = cur
                strick += 1
            else:
                if strick >= min_segment_len:
                    ans.append(Segment(seg_start, cur))
                strick = 0
            cur = cur + dir
    return ans
def unite_similar(final_list_of_segments):
    current_points = []
    THRES = 18
    new_list = []
    for Seg in final_list_of_segments:
        keyy1 = False
        keyy2 = False
        PP1 = Seg.point_1
        PP2 = Seg.point_2
        for curP in current_points:
            if Point.distance_between(PP1, curP) < THRES:
                Seg.point_1.x = curP.x
                Seg.point_1.y = curP.y
                keyy1 = True
            if Point.distance_between(PP2, curP) < THRES:
                Seg.point_2.x = curP.x
                Seg.point_2.y = curP.y
                keyy2 = True
        if not keyy1:
            current_points.append(PP1)
        if not keyy2:
            current_points.append(PP2)
        new_list.append(Seg)
    return new_list