人脸检测库libfacedetection介绍

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

 libfacedetection是于仕琪老师放到GitHub上的二进制库,没有源码,它的License是MIT,可以商用。目前只提供了windows 32和64位的release动态库,主页为https://github.com/ShiqiYu/libfacedetection,采用的算法好像是Multi-BlockLBP,提供了四套接口,分别为frontal、frontal_surveillance、multiview、multiview_reinforce,其中multiview_reinforce效果最好,速度比其它稍慢,四套接口的参数类型完全一致,可以根据需要对参数min_neighbors和min_object_width进行调整。

 新建一个控制台工程,用来测试libfacedetection,测试代码如下:

#include #include #include #include #include int main()std::vector<std::string> images{ "1.jpg", "2.jpg", "3.jpg", "4.jpeg", "5.jpeg", "6.jpg", "7.jpg", "8.jpg", "9.jpg", "10.jpg",  "11.jpeg", "12.jpg", "13.jpeg", "14.jpg", "15.jpeg", "16.jpg", "17.jpg", "18.jpg", "19.jpg", "20.jpg" }; std::vector<int> count_faces{1, 2, 6, 0, 1, 1, 1, 2, 1, 1,  1, 1, 1, 1, 1, 1, 1, 0, 8, 2}; std::string path_images{ "E:/GitCode/Face_Test/testdata/" }; if (images.size() != count_faces.size()) {  fprintf(stderr, "their size that images and count_faces are mismatch\n");  return -1; } typedef int* (*detect_face)(unsigned char * gray_image_data, int width, int height, int step,  float scale, int min_neighbors, int min_object_width, int max_object_width); detect_face detect_methods[]{  &facedetect_frontal,  &facedetect_multiview,  &facedetect_multiview_reinforce,  &facedetect_frontal_surveillance }; std::string detect_type[4] {"face frontal", "face multiview", "face multiview reinforce", "face surveillance"}; for (int method = 0; method < 4; method++) {  detect_face detect = detect_methods[method];  fprintf(stderr, "detect type: %s\n", detect_type[method].c_str());  for (int i = 0; i < images.size(); i++) {   cv::Mat src_ = cv::imread(path_images + images[i], 1);   if (src_.empty()) {    fprintf(stderr, "read image error: %s\n", images[i].c_str());    return -1;   }   cv::Mat src;   cv::cvtColor(src_, src, CV_BGR2GRAY);   int* results = nullptr;   results = detect(src.data, src.cols, src.rows, src.step, 1.2f, 2, 10, 0);   std::string save_result = path_images + std::to_string(method) + "_" + images[i];   //fprintf(stderr, "save result: %s\n", save_result.c_str());   for (int faces = 0; faces < (results ? *results : 0); faces++) {    short* p = ((short*)(results + 1)) + 6 * faces;    int x = p[0];    int y = p[1];    int w = p[2];    int h = p[3];    int neighbors = p[4];    int angle = p[5];    fprintf(stderr, "image_name: %s, faces_num: %d, face_rect=[%d, %d, %d, %d], neighbors=%d, angle=%d\n",     images[i].c_str(), *results, x, y, w, h, neighbors, angle);    cv::rectangle(src_, cv::Rect(x, y, w, h), cv::Scalar(0, 255, 0), 2);   }   cv::imwrite(save_result, src_);  } } int width = 200int height = 200; cv::Mat dst(height * 5, width * 4, CV_8UC3)for (int i = 0; i < images.size(); i++) {  std::string input_image = path_images + "2_" + images[i];  cv::Mat src = cv::imread(input_image, 1);  if (src.empty()) {   fprintf(stderr, "read image error: %s\n", images[i].c_str());   return -1;  }  cv::resize(src, src, cv::Size(width, height), 0, 0, 4);  int x = (i * width) % (width * 4);  int y = (i / 4) * height;  cv::Mat part = dst(cv::Rect(x, y, width, height));  src.copyTo(part); } std::string output_image = path_images + "result.png"; cv::imwrite(output_image, dst); fprintf(stderr, "ok\n"); return 0;}

 从网上找了20张图像,验证此库的检测率,下图是采用multiview_reinforce接口的检测结果:



 GitHub:https://github.com/fengbingchun/Face_Test

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

你可能感兴趣的:(人脸检测库libfacedetection介绍)