您的位置:首页 > 数据库

Windows下如何在FDDB数据库上评测自己的人脸检测分类器

2016-08-07 19:55 701 查看
本文是对该博客的一个补充。

http://blog.csdn.net/phoenix_zhou/article/details/47399819

因为自己是小白,想到应该还有一些和我一样无从下手的同学,所以特意详细的记录一下。

准备工作

文件准备

首先需要到FDDB的网站上下载评测的图片和工具。在这里我统一给一个链接,供大家下载。

http://pan.baidu.com/s/1nvrmDSl

解压后得到几个文件:

2002文件夹、2003文件夹、Fold_all.txt、evaluation.tgz、FDDB-folds.tgz、

其中2002文件夹和2003文件夹是解压originalPics.tar.gz得到的。

而关于Fold_all.txt与Elsp.txt,则是FDDB-folds.tgz中的各个10个txt的整合版,我把它们整合到一起(如果你不怕麻烦也可以自己整,..)

工程准备

在Visual Studio中,新建一个项目,把文件移植到下面,如下。



开始检测

使用你自己的分类器进行检测。在检测过程中,需要生成一个txt文档。官方文档在这里。

http://vis-www.cs.umass.edu/fddb/README.txt

其实就是以下格式

这里给出写这个的C++代码。

注意:以下的p[0],p[1],p[2],p[3]分别代表着人脸的左上角点坐标(x,y)宽度和高度w,h。

string Double_String(double x)
{
stringstream ss;
ss << x;
return ss.str();
}

string Int_String(int x)
{
stringstream ss;
ss << x;
return ss.str();
}
void detectAndDisplay(Mat gray,string line)
{
//以下人脸的数量用face_number代替
string face_position_1 = line;
string face_position_2 = Int_String(face_number);
vector<string> face;
for (int i = 0; i < face_number; i++)
{

// <left_x top_y width height detection_score>
//we do it
string face_vector = Int_String(p[0]) + " " + Int_String(p[1]) + " " + Int_String(p[2]) + " " + Int_String(p[3]) + " " + Double_String(detect_score);//detect_score,根据官网上的介绍,分类器中应该就包含这个参数。如果你是用opencv,那么在detectMultiScale中可以找到
face.push_back(face_vector);
}
//首先打开txt
ofstream result("result.txt", ios::app);
result << face_position_1 << endl << face_position_2 << endl;
result.close();//先关闭一次
//把vector写入
for (vector<string>::iterator iter = face.begin(); iter != face.end(); ++iter)
{
ofstream result_eachface("result.txt", ios::app);  //每一张脸
result_eachface << *iter << endl;
result_eachface.close();
}
face.clear();//清除这个
result.clear();
}
int main()
{
string file = "Fold_all.txt";
string line;
ifstream in(file);

if (in) // 有该文件
{
while (getline(in, line)) // line中不包括每行的换行符
{
string pic_road = line + ".jpg";
Mat gray = imread(pic_road, CV_LOAD_IMAGE_GRAYSCALE);//it is necessary that must have CV_LOAD_IMAGE_GRAYSCALE
detectAndDisplay(gray, line);
}
}
cout << "Finally we got it";
getchar();
}


我们得到了一个这样的txt文档:



因为我是在脸上画矩形,所以是这样。椭圆的格式可以见官网。

进行评测

解压evaluation.tgz,将其源文件和头文件包含在工程中,添加Opencv的属性表。

然后做以下修改:

在evaluate.cpp中的main函数,把第235行改为如下,即在max前面添加括号,否则会冲突。

Results *r = new Results(imName, (std::numeric_limits<double>::max)(), NULL, annot, det);


再者,在项目的属性栏中做如下改动。





在72行,把这里改成自己的

#ifdef _WIN32
string baseDir = "F:/soft/c++/Test_FDDB/Test_FDDB/";
string listFile = "F:/soft/c++/Test_FDDB/Test_FDDB/Fold_all.txt";
string detFile = "F:/soft/c++/Test_FDDB/Test_FDDB/result.txt";
string annotFile = "F:/soft/c++/Test_FDDB/Test_FDDB/Elsp.txt";


生成,在工程目录下得到了tempContROC.txt与tempDiscROC.txt文件。

安装perl与gnuplot4.6

安装的文件也在前面给的网址中。

关于perl的配置,请戳:http://jingyan.baidu.com/article/9f7e7ec0b798ae6f281554e9.html?st=2&os=0&bd_page_type=1&net_type=1

关于gnuplot,没什么好讲的…就是一路next到底。

安装好之后,修改原来的一个用于评测的pl文件:

#!/usr/bin/perl -w
use strict;
#### VARIABLES TO EDIT ####
# where gnuplot is
my $GNUPLOT = "D:/gnuplot/bin/gnuplot";
# where the binary is
my $evaluateBin = "evaluate";
# where the images are
my $imDir = "F:/soft/c++/Test_FDDB/Test_FDDB"; #FDDB数据库的图片在哪
# where the folds are
my $fddbDir = "F:/soft/c++/Test_FDDB/Test_FDDB/FDDB-Folds"; #fddb图片的两个txt
# where the detections are
my $detDir = "C:/Users/strstr/Desktop/FDDB_DRAW/Filep/"; #图片存放的位置
###########################

my $detFormat = 0; # 0: rectangle, 1: ellipse 2: pixels

sub makeGNUplotFile
{
my $rocFile = shift;
my $gnuplotFile = shift;
my $title = shift;
my $pngFile = shift;

open(GF, ">$gnuplotFile") or die "Can not open $gnuplotFile for writing\n";
#print GF "$GNUPLOT\n";
print GF "set term png\n";
print GF "set size 1,1\n";
print GF "set output \"$pngFile\"\n";
#print GF "set xtics 500\n";
print GF "set ytics 0.1\n";
print GF "set grid\n";
#print GF "set size ratio -1\n";
print GF "set ylabel \"True positive rate\"\n";
print GF "set xlabel \"False positives\"\n";
#print GF "set xr [0:2000]\n";
print GF "set yr [0:1.0]\n";
print GF "set key right bottom\n";
print GF "plot \"$rocFile\" using 2:1 title \"$title\" with lines lw 2 \n";
close(GF);
}

my $gpFile = "C:/Users/strstr/Desktop/FDDB_DRAW/Filep/ContROC.p";
my $gpFile1 = "C:/Users/strstr/Desktop/FDDB_DRAW/Filep/DistROC.p";
my $title = "YotoFace";

# plot the two ROC curves using GNUplot
makeGNUplotFile("C:/Users/strstr/Desktop/FDDB_DRAW/tempContROC.txt", $gpFile, $title, $detDir."ContROC.png");
makeGNUplotFile("C:/Users/strstr/Desktop/FDDB_DRAW/tempDiscROC.txt", $gpFile1, $title, $detDir."DiscROC.png");


已经标注的很清楚,根据上述修改即可。

在命令行模式下,运行perl xxxxxxxxxxxx.pl得到ContROC.p与DistROC.p。

打开gnuplot4.6:



先把pl文件拖到里面,然后再file->output,即可看到我们的曲线。



曲线:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  windows FDDB 人脸检测