예제 #1
0
def test_merge_three_in_almost_line():
    L = [
        LineSegment(454, 212, 457, 160),
        LineSegment(458, 171, 458, 152),
        LineSegment(452, 231, 454, 191)
    ]
    assert merge_lines(L, 1, 1) == [LineSegment(452, 231, 458, 152)]
예제 #2
0
def test_merge_trivial():
    L = [LineSegment(0, 0, 10, 10), LineSegment(0, 0, 10, 10)]
    assert merge_lines(L, 1, 1) == [LineSegment(0, 0, 10, 10)]
예제 #3
0
def test_merge_simple():
    L = [LineSegment(0, 0, 10, 10), LineSegment(0, 0, 10, 11)]
    assert merge_lines(L, 1, 1) == [LineSegment(0, 0, 10, 11)]
예제 #4
0
    # TODO Maybe look at fast arguments for this
    distances = cv2.distanceTransform(cv2.bitwise_not(centres),
                                      distanceType=cv2.DIST_L2,
                                      maskSize=cv2.DIST_MASK_PRECISE)

    lines = cv2.HoughLinesP(centres,
                            1,
                            np.pi / 180,
                            threshold=10,
                            minLineLength=5,
                            maxLineGap=5)[:, 0, :]
    line_segments = [
        lsm.LineSegment(x1, y1, x2, y2) for x1, y1, x2, y2 in lines
    ]
    merged_lines = lsm.merge_lines(line_segments, tau_theta=0.1, xi_s=0.5)
    polys = trace_filaments(merged_lines)

    end = time.time()
    print("Line finding", end - start)

    fig, ax = plt.subplots(figsize=(10, 9))
    ax.imshow(d_cv, cmap='bone', alpha=0.99)

    for poly in polys:
        if poly.length < 30:
            continue
        x = [p.x for p in poly.points]
        y = [p.y for p in poly.points]
        ax.plot(x, y, linewidth=5, alpha=0.8)