python
生成FDDB对比的文件。FDDB: A Benchmark for Face Detection in Unconstrained Settings
,以及FDDB主页,了解人脸评估的基本原理FDDB-FOLD-%d.txt
合成一个文件: cat * > filePath.txt
FDDB-fold-%d-ellipseList.txt
合成一个文件 cat *ellipse*.txt > annotFile.txt
evaluate
可执行文件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
部分修改GUNPLOT
变量修改(gnuplot路径),确保已经安装gnuplot
$detFormat
人脸检测的的类型,椭圆还是矩形,我用矩形评价,因此变量修改:my $detFormat = 0; # 0: rectangle, 1: ellipse 2: pixels
$detFile
自己的检测文件my $detFile =
"/home/xy/face_sample/evaluation/compareROC/detDir/fddb_rect_ret1.txt";
runEvaluate.pl
,执行语句修改,主要是添加"-z", ".jpg"
:system($evaluateBin, "-a", $annotFile, "-d", $detFile, "-f", $detFormat, "-i", $imDir, "-l", $listFile, "-r", $detDir, "-z", ".jpg");
evaluate
使用验证:具体命令如下:
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
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)
Incompatible annotation and detection files. See output specifications
,由于windows下文件和ubuntu下不同导致的。只需要在ubuntu下面创建一个txt文件,然后将内容复制进去即可。runEvaluate.pl
evaluate.cpp
源代码。