def evaluate_tracking(sequences, track_dir, gt_dir):
    all_info = []
    for seqname in sequences:
        track_res = os.path.join(track_dir, seqname, 'res.txt')
        gt_file = os.path.join(gt_dir, seqname, 'gt.txt')
        assert os.path.exists(track_res) and os.path.exists(gt_file), 'Either tracking result or groundtruth directory does not exist'

        trackDB = read_txt_to_struct(track_res)
        gtDB = read_txt_to_struct(gt_file)

        gtDB, distractor_ids = extract_valid_gt_data(gtDB)
        metrics, extra_info = evaluate_sequence(trackDB, gtDB, distractor_ids)
        print_metrics(seqname + ' Evaluation', metrics)
        all_info.append(extra_info)
    all_metrics = evaluate_bm(all_info)
    print_metrics('Summary Evaluation', all_metrics)
def evaluate_new(results, gt_file):
    res = []
    for i, track in results.items():
        for frame, bb in track.items():
            x1 = bb[0]
            y1 = bb[1]
            x2 = bb[2]
            y2 = bb[3]
            res.append([
                float(frame + 1),
                float(i + 1),
                float(x1 + 1),
                float(y1 + 1),
                float(x2 + 1),
                float(y2 + 1),
                float(-1),
                float(-1),
                float(-1),
                float(-1)
            ])

    trackDB = np.array(res)
    gtDB = read_txt_to_struct(gt_file)

    # manipulate mot15 to fit mot16
    #gtDB[:,7] = gtDB[:,6]
    #gtDB[:,6] = 1
    #gtDB[:,8] = 1
    #gtDB = gtDB[:,:9]

    gtDB, distractor_ids = extract_valid_gt_data(gtDB)

    metrics, extra_info, clear_mot_info, ML_PT_MT = evaluate_sequence(
        trackDB, gtDB, distractor_ids)

    print_metrics(' Evaluation', metrics)

    # evaluate sizes of ML_PT_MT
    ML_PT_MT_sizes = [[]]
    ML_PT_MT_vis = [[]]
    for i, p in enumerate(ML_PT_MT, 1):
        ML_PT_MT_sizes.append([])
        ML_PT_MT_vis.append([])
        for tr_id in p:
            gt_in_person = np.where(gtDB[:, 1] == tr_id)[0]
            #w = gtDB[gt_in_person, 4]
            h = gtDB[gt_in_person, 5] - gtDB[gt_in_person, 3]
            #sizes = (w*h).mean()
            ML_PT_MT_sizes[i].append(h.mean())
            ML_PT_MT_sizes[0].append(h.mean())

            vis = gtDB[gt_in_person, 8]
            ML_PT_MT_vis[i].append(vis.mean())
            ML_PT_MT_vis[0].append(vis.mean())

    print("\t\theight\tvis")
    print("MT: \t\t{:.2f}\t{:.2f}".format(np.mean(ML_PT_MT_sizes[3]),
                                          np.mean(ML_PT_MT_vis[3])))
    print("PT: \t\t{:.2f}\t{:.2f}".format(np.mean(ML_PT_MT_sizes[2]),
                                          np.mean(ML_PT_MT_vis[2])))
    print("ML: \t\t{:.2f}\t{:.2f}".format(np.mean(ML_PT_MT_sizes[1]),
                                          np.mean(ML_PT_MT_vis[1])))
    print("total (mean of\t{:.2f}\t{:.2f}\ntrack means):".format(
        np.mean(ML_PT_MT_sizes[0]), np.mean(ML_PT_MT_vis[0])))

    return clear_mot_info