pico在lfw上测试检测率

来源:互联网 发布:第七感计划软件 编辑:程序博客网 时间:2024/05/17 00:49

测试pico在lfw上的检测率。

lfw给定的文件格式:


每个名称文件夹下有一张或多张图片。

[cpp] view plain copy
  1. #include "io.h"  
  2. std::vector<std::string> list_folders(std::string pathname)  
  3. {  
  4.     std::vector<std::string> folders;  
  5.     _finddata_t folder;  
  6.   
  7.     std::string findpath = pathname + "\\*";  
  8.   
  9.     long handle = _findfirst(findpath.c_str(),&folder);  
  10.   
  11.     if(handle == -1)  
  12.     {  
  13.         std::cerr << "no such path" << std::endl;  
  14.         system("pause");  
  15.         exit(-1);  
  16.     }  
  17.   
  18.     do  
  19.     {  
  20.         if(folder.attrib & _A_SUBDIR)  
  21.         {  
  22.             if( (strcmp(folder.name, ".") != 0) && (strcmp(folder.name, "..") != 0) )  
  23.             {  
  24.                 std::string newpath = pathname + "\\" + folder.name;  
  25.                 folders.push_back(newpath);  
  26.             }  
  27.         }  
  28.     }while( _findnext(handle, &folder) == 0 );  
  29.   
  30.     return folders;  
  31. }  
  32.   
  33. std::vector<std::string> list_files(std::string pathname)  
  34. {  
  35.     std::vector<std::string> files;  
  36.     _finddata_t file;  
  37.   
  38.     std::string findpath = pathname + "\\*";  
  39.   
  40.     long handle = _findfirst(findpath.c_str(),&file);  
  41.   
  42.     if(handle == -1)  
  43.     {  
  44.         std::cerr << "no such path" << std::endl;  
  45.         system("pause");  
  46.         exit(-1);  
  47.     }  
  48.   
  49.     do  
  50.     {  
  51.         if(!(file.attrib & _A_SUBDIR))  
  52.         {  
  53.             files.push_back(pathname + "\\" + file.name);  
  54.         }  
  55.     }while( _findnext(handle, &file) == 0 );  
  56.   
  57.     return files;  
  58. }  
list_folders(),遍历给定路径下的文件夹。list_files(),遍历给定路径下的文件。

在此基础上:

[cpp] view plain copy
  1. std::string root = "C:\\Users\\zhuqian\\Desktop\\pico_face_detect\\lfw\\lfw";  
  2.     std::vector<std::string> all = list_folders(root);  
  3.     for (std::vector<std::string>::const_iterator it = all.begin(); it!=all.end();++it)  
  4.     {  
  5.         //std::cout << *it << std::endl;  
  6.         std::vector<std::string> filename = list_files(*it);  
  7.         for (std::vector<std::string>::const_iterator subit = filename.begin();subit!=filename.end();  
  8.             ++subit)  
  9.         {  
  10.             IplImage* img;  
  11.             allface += 1;  
  12.             //  
  13.             img = cvLoadImage(subit->c_str(), CV_LOAD_IMAGE_COLOR);  
  14.             if(!img)  
  15.             {  
  16.                 printf("# cannot load image from '%s'\n", subit->c_str());  
  17.                 return 0;  
  18.             }  
  19.             process_image(img, 1, *it);  
  20.             cvReleaseImage(&img);  
  21.         }  
  22.     }  
  23.     std::cout << "lossdect: " << lossdect << std::endl;  
  24.     std::cout << "falsedect: " << falsedect << std::endl;  
  25.     std::cout << "allface" << allface << std::endl;  
  26.   
  27.     std::cout << "lossdectRate: " << (double)lossdect/allface << std::endl;  
  28.     std::cout << "facedectRate: " << (double)falsedect/allface << std::endl;  
其中调用的void process_image(IplImage* frame, int draw, const std::string& path)修改如下:

[cpp] view plain copy
  1. if(draw)  
  2.         for(i=0; i<ndetections; ++i)  
  3.             if(qs[i]>=qthreshold) // check the confidence threshold  
  4.             {  
  5.                 /*cv::Rect r1(cs[i]-ss[i]/2, rs[i]-ss[i]/2, ss[i], ss[i]); //矩阵标记 
  6.                 cv::Mat img(frame,0);                                   //IplImage转Mat 
  7.                 cv::Mat face(img(r1));*/                     //取矩阵  
  8.                 //std::stringstream s;  
  9.                 //s << i;                         //int转string的方法之一  
  10.                 //cv::imwrite(path + "result_" + s.str() + ".jpg", face);  
  11.                   
  12.                 cvCircle(frame, cvPoint(cs[i], rs[i]), ss[i]/2, CV_RGB(255, 0, 0), 4, 8, 0); // we draw circles here since height-to-width ratio of the detected face regions is 1.0f  
  13.                   
  14.             }  
  15.   
  16.     static int nnn=0;  
  17.     std::stringstream s;  
  18.     s << nnn++;  
  19.   
  20.     if (ndetections==0)  //记录误检漏检率,并在项目路径下写检测后的图片,便于人眼观察。  
  21.     {  
  22.         cv::imwrite("lossdect"  + s.str() + ".jpg", cv::Mat(frame,0));  
  23.         lossdect += 1;  
  24.     }  
  25.     if (ndetections>1)  
  26.     {  
  27.         falsedect += ndetections-1;  
  28.         std::cout << path << std::endl;  
  29.         cv::imwrite("falsedect"  + s.str() + ".jpg", cv::Mat(frame,0));  
  30.     }  
  31.     else  
  32.     {  
  33.         cv::imwrite("right"  + s.str() + ".jpg", cv::Mat(frame,0));  
  34.     }  
  35.   
  36.     // if the `verbose` flag is set, print the results to standard output  
  37.     if(verbose)  
  38.     {  
  39.         //  
  40.         for(i=0; i<ndetections; ++i)  
  41.             if(qs[i]>=qthreshold) // check the confidence threshold  
  42.                 printf("%d %d %d %f\n", (int)rs[i], (int)cs[i], (int)ss[i], qs[i]);  
  43.   
  44.         //  
  45.         //printf("# %f\n", 1000.0f*t); // use '#' to ignore this line when parsing the output of the program  
  46.     }  
结果:

样本:13233. 漏检84. 误检150. (漏检率:0.6%,误检率:1.1%) 
还有参数设置,如果参数能够根据样本中人脸的大小(先验知识)作相应修改,效果会更好。

原创粉丝点击