对于我在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 的一个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
到 make 文件。
-
评估,你可以使用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文件(由evaluate 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:
'runEvaluate.pl'有一些错误,将执行评估更改为以下:
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):
# lst = ['line1', 'line2', 'line3']
f_path = 'fddb_rect_ret.txt'
with open(f_path, 'w') as fp:
for line in lst:
fp.write("%s\n" % line)
# For example use opencv to face detection
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():
# The directory from which we get the test images from FDDB
img_base_dir = 'E:/face_rec/face__det_rec_code/face_det/originalPics/'
# All the images relative path, like '['2002/08/11/big/img_344', '2002/08/02/big/img_473', ......]'
lst_img_name = get_img_relative_path()
# Store detect result, like:
# ['2002/08/11/big/img_344', '1', '10 10 50 50 1', .............]
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)
# append img name like '2002/08/11/big/img_344'
lst_write2_fddb_ret.append(img_name)
face_num = len(lst_face_rect)
# append face num, note if no face 0 should be append
lst_write2_fddb_ret.append(str(face_num))
if face_num > 0:
# append each face rectangle x y w h score
for face_rect in lst_face_rect:
# append face rectangle x, y, w, h score
# note: opencv hava no confidence so use 1 here
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 all the result to txt for FDDB evaluation
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);
system($evaluateBin, "-a", $annotFile, "-d", $detFile, "-f", $detFormat, "-i", $imDir, "-l", $listFile, "- r", $detDir, "-z", ".jpg");
您也可以阅读evaluate代码(主要是容易理解的evaluate.cpp),这样您就可以深入了解如何评估它。