def evaluate(mean_f=True, point_dis=False, rect_flag=False):
    name_list = open(name_list_dir).read().strip().split('\n')
    fout = open(osp.join(cfg.DATA_DIR, 'wrong.txt'), 'w')
    (precision, recall, page_correct) = (0, 0, 0)
    (right_all, error_all, gt_all, res_all) = (0, 0, 0, 0)
    for name in name_list:
        results = read_txt(osp.join(res_base_dir, (name + '.txt')), use_bound=False)
        if rect_flag:
            rect_label = []
        else:
            rect_label = None
        gts = read_txt(osp.join(gt_base_dir, (name + '.txt')), rect_label=rect_label, is_gt=True, use_bound=False)
        (right_num, error_num, mid_num) = eval_one(results, gts, rect_label=rect_label, point_dis=point_dis)
        right_all += right_num
        error_all += error_num
        gt_all += (len(gts) - mid_num)
        res_all += (len(results) - mid_num)
        if ((len(results) - mid_num) > 0):
            precision += (right_num / (len(results) - mid_num))
        if ((len(gts) - mid_num) > 0):
            recall += (right_num / (len(gts) - mid_num))
        if ((right_num == len(gts)) and (error_num == 0)):
            page_correct += 1
        else:
            fout.write('{}\n'.format(name))
    n = len(name_list)
    precision /= n
    recall /= n
    page_correct /= n
    f1 = (((2 * precision) * recall) / (precision + recall))
    print('{} {:.5f} {:.5f} {:.5f} {:.5f}'.format(th, precision, recall, f1, page_correct))
    if (not mean_f):
        precision = (right_all / res_all)
        recall = (right_all / gt_all)
    f1 = (((2 * precision) * recall) / (precision + recall))
    print('{} {:.5f} {:.5f} {:.5f} {:.5f}'.format(th, precision, recall, f1, page_correct))
def evaluate(mean_f=True, point_dis=False, rect_flag=False):
    name_list = open(name_list_dir).read().strip().split('\n')
    fout = open(osp.join(cfg.DATA_DIR, 'wrong.txt'), 'w')
    (precision, recall, page_correct) = (0, 0, 0)
    (right_all, error_all, gt_all, res_all) = (0, 0, 0, 0)
    for name in name_list:
        results = read_txt(osp.join(res_base_dir, (name + '.txt')), use_bound=False)
        if rect_flag:
            rect_label = []
        else:
            rect_label = None
        gts = read_txt(osp.join(gt_base_dir, (name + '.txt')), rect_label=rect_label, is_gt=True, use_bound=False)
        (right_num, error_num, mid_num) = eval_one(results, gts, rect_label=rect_label, point_dis=point_dis)
        right_all += right_num
        error_all += error_num
        gt_all += (len(gts) - mid_num)
        res_all += (len(results) - mid_num)
        if ((len(results) - mid_num) > 0):
            precision += (right_num / (len(results) - mid_num))
        if ((len(gts) - mid_num) > 0):
            recall += (right_num / (len(gts) - mid_num))
        if ((right_num == len(gts)) and (error_num == 0)):
            page_correct += 1
        else:
            fout.write('{}\n'.format(name))
    n = len(name_list)
    precision /= n
    recall /= n
    page_correct /= n
    f1 = (((2 * precision) * recall) / (precision + recall))
    print('{} {:.5f} {:.5f} {:.5f} {:.5f}'.format(th, precision, recall, f1, page_correct))
    if (not mean_f):
        precision = (right_all / res_all)
        recall = (right_all / gt_all)
    f1 = (((2 * precision) * recall) / (precision + recall))
    print('{} {:.5f} {:.5f} {:.5f} {:.5f}'.format(th, precision, recall, f1, page_correct))