至于我在ubuntu16,我必须通过以下步骤来完成:
-
下载检测人脸的fddb原始图像数据集并获得检测结果。你可以下载
here
.这是我的目录:
-
将所有图像文件路径连接到一个txt文件,并将所有fddb注释连接到一个txt文件。
你可以下载所有的文件
here
至于我,我把所有的
FDDB-FOLD-%d.txt
转到目录
all_file_path
,然后按顺序将它们加入到一个文件中
cat * > filePath.txt
加入所有
FDDB-fold-%d-ellipseList.txt
一个接一个
cat *ellipse*.txt > annotFile.txt
注意:您可能不需要创建它,因为
runEvaluate.pl
在跑步过程中为你做这件事。
3.创建FDDB evalute exe,在这里下载源代码
here
然后编译它,你可以修改makefile,看看原因
here
添加
INCS = -I/usr/local/include/opencv
LIBS = -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui
-lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d
-lopencv_objdetect -lopencv_contrib -lopencv_legacy
制作文件。
-
评估,你可以使用
runEvaluate。pl
但对于我(ubuntu16),我不能直接运行它。
4.1更改
GUNPLOT
路径(您应该安装
gnuplot
首先使用它创建ROC图像)
4.2我使用矩形检测模型,所以我改变了
$detFormat
到0。
my $detFormat = 0; # 0: rectangle, 1: ellipse 2: pixels
4.3所有图像的相对路径:
my $listFile ="/home/xy/face_sample/evaluation/compareROC/FDDB-folds/filePath.txt";
4.4所有图像注释
my $annotFile = "/home/xy/face_sample/evaluation/compareROC/FDDB-folds/annotFile.txt";
4.5要生成的roc文件(由exe创建):
my $gpFile ="/home/xy/face_sample/evaluation/compareROC/createROC.p";
4.6你的检测文件(稍后我将给出如何创建)
my $detFile ="/home/xy/face_sample/evaluation/compareROC/detDir/fddb_rect_ret1.txt";
Itâs content like that:
跑步者需要评估。如果出现一些错误,请将执行评估更改为以下内容:
system($evaluateBin, "-a", $annotFile, "-d", $detFile, "-f", $detFormat, "-i", $imDir, "-l", $listFile, "-r", $detDir, "-z", ".jpg");
您还可以使用以下命令进行检查:
xy@xy:~/face_sample/evaluation/compareROC$ ./evaluate \
> -a /home/xy/face_sample/evaluation/compareROC/FDDB-folds/annotFile.txt \
> -d /home/xy/face_sample/evaluation/compareROC/detDir/fddb_rect_ret1.txt \
> -f 0 \
> -i /home/xy/face_sample/evaluation/compareROC/originalPics/ \
> -l /home/xy/face_sample/evaluation/compareROC/FDDB-folds/filePath.txt \
> -r /home/xy/face_sample/evaluation/compareROC/detDir/ \
> -z .jpg
使用python创建fddb评估txt文件:
def get_img_relative_path():
"""
:return: ['2002/08/11/big/img_344', '2002/08/02/big/img_473', ......]
"""
f_name = 'E:/face_rec/face__det_rec_code/face_det/FDDB-folds/all_img_files.txt'
lst_name = open(f_name).read().split('\n')
return lst_name
def write_lines_to_txt(lst):
f_path = 'fddb_rect_ret.txt'
with open(f_path, 'w') as fp:
for line in lst:
fp.write("%s\n" % line)
def detect_face_lst(img):
"""
:param img: opencv image
:return: face rectangles [[x, y, w, h], ..........]
"""
m_path = 'D:/opencv/sources/data/haarcascades/haarcascade_frontalface_default.xml'
face_cascade = cv2.CascadeClassifier(m_path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
return faces
def generate_fddb_ret():
img_base_dir = 'E:/face_rec/face__det_rec_code/face_det/originalPics/'
lst_img_name = get_img_relative_path()
lst_write2_fddb_ret = []
try:
for img_name in lst_img_name:
img_full_name = img_base_dir + img_name + '.jpg'
img = cv2.imread(img_full_name)
if img == None:
print 'error %s not exists, can not generate complete fddb evaluate file' % img_full_name
return -1
lst_face_rect = detect_face_lst(img)
lst_write2_fddb_ret.append(img_name)
face_num = len(lst_face_rect)
lst_write2_fddb_ret.append(str(face_num))
if face_num > 0:
for face_rect in lst_face_rect:
s_rect = " ".join(str(item) for item in face_rect) + " 1"
lst_write2_fddb_ret.append(s_rect)
except Exception as e:
print 'error %s , can not generate complete fddb evaluate file' % e
return -1
write_lines_to_txt(lst_write2_fddb_ret)
运行上述代码后,可以创建FDDB结果:
注意:当你在windows中创建上面的txt文件时,如果你在ubuntu中测试它,你可能会得到以下错误
Incompatible annotation and detection files. See output specifications
:
只需将内容复制到一个新的txt文件(在ubuntu中创建)就可以了。
结果如下:
一些提示:
-
你可以看到
runEvaluate。pl
这并不难,可能不需要进行上述更改。您还可以在中更改一些变量
runEvaluate。pl
喜欢
$GNUPLOT
,
$imDir
等等
添加
"-z", ".jpg"
到
系统($evaluateBin,“-a”、$annotFile,“-d”、$detFile,“-f”、$detFormat,“-i”、$imDir,“-l”、$listFile,“-r”、$detDir);
系统($evaluateBin,“-a”、$annotFile,“-d”、$detFile,“-f”、$detFormat,“-i”、$imDir,“-l”、$listFile,“-r”、$detDir,“-z”、.jpg”);
-
你也可以阅读
evaluate
代码(主要是
evaluate.cpp
这很容易理解),所以你将对如何评估它有深刻的理解。