Esempio n. 1
0
def collect_line_around(pt_list, trace_list, rev, rot):
    """
    important to road segment generation
    trace_list[ti][tj] is pt
    collect all the points from beginning to end as trace goes on if the point is anchor
    because the vehicle may turn around and trace back, the trace should be split when turning happened
    :param pt_list: list of anchor point
    :param trace_list: original trace list, list of TaxiData
    :param rev: each index
    :param rot: rotate angle
    :return: list of line(list of Point)
    """
    # begin, end = {}, {}
    trace_detail = {}
    for i, pt in enumerate(pt_list):
        ti, tj = rev[i][:]
        try:
            trace_detail[ti].append(tj)
        except KeyError:
            trace_detail[ti] = [tj]
    for ti in trace_detail.keys():
        trace_detail[ti].sort()

    line_list = []
    fact_ort = 90 - rot
    for i, idx_list in trace_detail.items():
        iset = set(idx_list)
        for j in idx_list:
            if j + 1 < len(trace_list[i]):
                iset.add(j)
        fill_list = list(iset)
        fill_list.sort()

        line = []
        last_j = None
        for j in fill_list:
            pt = trace_list[i][j]
            if last_j is not None and j - last_j > 3:
                if len(line) > 1:
                    line_list.append(rotate(line, rot))
                line = [[pt.x, pt.y]]
            else:
                line.append([pt.x, pt.y])
            last_j = j

        if len(line) > 1:
            line_list.append(rotate(line, rot))

    return line_list
Esempio n. 2
0
def norm_road(road_list):
    """
    使道路正向(0-90, 270-360)
    :param road_list: 
    :return: 
    """
    ma_list = []
    ret_list = []
    for road in road_list:
        a_list = []
        last_pt = None
        for pt in road:
            if last_pt:
                a = xy_angle(last_pt[0], last_pt[1], pt[0], pt[1])
                a_list.append(a)
            last_pt = pt
        ma = mean_angle(a_list)
        print ma
        ret_list.append(road)
        ma_list.append(ma)
    # then rotate
    ama = np.mean(ma_list)
    final_list = []
    for road in ret_list:
        road = rotate(road, 90 - ama)
        final_list.append(road)
    return final_list, ama
Esempio n. 3
0
def work(tup_list, rd_list):
    for item in tup_list:
        pt_list, line_list, a, lb = item[:]
        road = center_road(pt_list, line_list)
        # print "label", lb
        try:
            road = rotate(road, -a)
            rd_list.append(road)
        except ValueError:
            print "value error", lb
Esempio n. 4
0
def gene_center_line(labels,
                     data_list,
                     rev_index,
                     trace_list,
                     ma_list,
                     debug=False):
    n = len(labels)
    x_list, y_list, angle_list = zip(*data_list)
    pts_dict = defaultdict(list)
    angle_dict = defaultdict(list)
    rev_dict = defaultdict(list)

    for i in range(n):
        pts_dict[labels[i]].append([x_list[i], y_list[i]])
        angle_dict[labels[i]].append(angle_list[i])
        rev_dict[labels[i]].append(rev_index[i])

    colors = ['pink', 'orange', 'y', 'blue', 'c', 'g', 'lime', 'red']

    tup_list = []
    for label, pt_list in pts_dict.items():
        rev = rev_dict[label]
        if label == -2:
            # draw_points(pt_list, '+', 'k', 0.1, -3)
            pass
        else:
            if debug and label != 20:
                continue
            a = ma_list[label]
            try:
                idx = int(a / 45)
            except ValueError:
                continue
            if len(pt_list) > 100:
                a = 90 - a
                line_list = collect_line_around(pt_list, trace_list, rev, a)
                pt_list = rotate(pt_list, a)
                tup_list.append([pt_list, line_list, a, label])

    mng = mp.Manager()
    ret_list = mng.list()
    proc_num = 32
    pool = mp.Pool(processes=proc_num)
    for i in range(proc_num):
        pool.apply_async(work, args=(tup_list[i::proc_num], ret_list))
    pool.close()
    pool.join()

    for road in ret_list:
        draw_center(road)

    save_road(ret_list)
Esempio n. 5
0
def merge(road_list):
    """
    :param road_list: list(list(x,y))
    :return: 
    """
    road_list, ama = norm_road(road_list)
    final_road = merge_road(road_list)
    # find_convex(final_road)
    final_road = rotate(final_road, ama - 90)
    final_road = mean_y_filter(final_road)
    final_road = median_y_filter(final_road)
    # final_road = dog_last(final_road, 5)
    # find_convex(final_road)
    # draw_outline(final_road)
    # for road in road_list:
    #     draw_center(road)
    draw_center(final_road, 'k')
    return final_road