文本检测评估代码

1.评估代码

评测接口来自ICDAR大赛:http://rrc.cvc.uab.es/?ch=4&com=mymethods&task=1

可下载离线代码:https://github.com/liuheng92/OCR_EVALUATION

代码运行环境python 2.x

运行命令:

python script.py –g gt.zip –s submit.zip -p '{"LTRB":true,"E2E":true}'

但在命令框中运行时会出现问题,主要是json字符串格式不对,修改为:

python script.py –g gt.zip –s submit.zip -p '{"LTRB":"true","E2E":"true"}'

这样改的话,无论对应的字符串是否为true都会判定为True,即 if  str,如果str不为空 相当于 if true

所以设置为False的话还是在代码中设置为默认值

具体参数含义:

-g: Path of the Ground Truth file. In most cases, the Ground Truth will be included in the same Zip file named 'gt.zip', gt.txt' or 'gt.json'. If not, you will be able to get it on the Downloads page of the Task.

-s: Path of your method's results file.

Optional parameters:

-o: Path to a directory where to copy the file ‘results.zip’ that contains per-sample results.

-p: JSON string parameters to override the script default parameters. The parameters that can be overrided are inside the function 'default_evaluation_params' located at the begining of the evaluation Script.

when use Algorithm_IOU -p
'IOU_CONSTRAINT': 0.5,
'AREA_PRECISION_CONSTRAINT': 0.5,
'GT_SAMPLE_NAME_2_ID': 'gt_img_([0-9]+).txt',
'DET_SAMPLE_NAME_2_ID': 'res_img_([0-9]+).txt',
'LTRB': False,  # LTRB:2points(left,top,right,bottom) or 4 points(x1,y1,x2,y2,x3,y3,x4,y4)
'CRLF': False,  # Lines are delimited by Windows CRLF format
'CONFIDENCES': False,  # Detections must include confidence value. AP will be calculated
'PER_SAMPLE_RESULTS': True,  # Generate per sample results and produce data for visualization
'E2E': False   #compute average edit distance for end to end evaluation
when use Algorithm_DetEva -p
'AREA_RECALL_CONSTRAINT': 0.8,
'AREA_PRECISION_CONSTRAINT': 0.4,
'EV_PARAM_IND_CENTER_DIFF_THR': 1,
'MTYPE_OO_O': 1.,
'MTYPE_OM_O': 0.8,
'MTYPE_OM_M': 1.,
'GT_SAMPLE_NAME_2_ID': 'gt_img_([0-9]+).txt',
'DET_SAMPLE_NAME_2_ID': 'res_img_([0-9]+).txt',
'CRLF': False  # Lines are delimited by Windows CRLF format

2.运行代码注意事项

1.要注意压缩包是不带文件夹的

2.文件名字格式是gt_img_**.txt以及res_img_**.txt

3.文件内容格式8点坐标为顺时针方向,即使是检测评估,后面也要跟一个对应文本框内容如:x1,y1,x2,y2,x3,y3,x4,y4,###

4.使用代码压缩文件时,要注意关闭流,arch.close()。否则压缩包会出现 不可预料的压缩文件末端错误。

生成gt.zip代码:

import os
import xml.etree.ElementTree as ET
import numpy as np
import zipfile
from functools import reduce
gt_output = 'mygt.zip'
arch2 = zipfile.ZipFile(gt_output,'w')
fpath='D:\yang\data\\textdata\\alitext\\task2\\aliVOC\VOCtest\VOC2007\ImageSets\Main\\val.txt'
gtpath='D:\yang\data\\textdata\\alitext\\task2\\aliVOC\VOCtest\\txt_train\\'
f=open(fpath,'r')
count=1
for name in f:
    name = name.strip()
    with open(gtpath+name+'.txt', 'r',encoding='utf-8') as f:
        s=''
        for line in f.readlines():
            x1, y1, x2, y2, x3, y3, x4, y4 = list(map(float,line.strip().split(',')[0:8]))
            if len(line.split(',')) == 9:
                label = line.strip().split(',')[-1]
            else:
                lable = reduce(lambda x,y:x+y,line.strip().split(',')[8:])
            newline = str(x1)+','+str(y1)+','+str(x4)+','+str(y4)+',' + str(x3)+','+str(y3)+',' +str(x2)+','+str(y2)+','+label +'\n'
            s += newline
    arch2.writestr(os.path.basename("gt_img_"+str(count)+".txt"),s)
    count=count+1
arch2.close()

主要参考:

https://blog.csdn.net/liuxiaoheng1992/article/details/82632594

https://blog.csdn.net/ab0902cd/article/details/82902791

你可能感兴趣的:(Python)