libfacedetection 人脸检测库的基本使用

article/2025/10/24 21:33:09

目录

1、源码下载

2、编译

 3、构建工程

4、个人总结

运行总结:

与CascadeClassifier级联分类器 人脸检测 对比:


1、源码下载

直接从github上克隆项目仓库。

git clone https://github.com/ShiqiYu/libfacedetection.git

2、编译

这个项目使用了cmake脚本,先生成makefile。

cmake -DENABLE_NEON=OFF -DCMAKE_BUILD_TYPE=RELEASE .

输出:

-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
BUILD_VERSION:v0.0.3
-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
CXX_FLAGS:  -O3 -mavx2 -mfma -fopenmp
LINKER_FLAGS:  
AVX512 = OFF
AVX2 = ON
NEON = OFF
OpenMP = TRUE
DEMO = OFF
-- Configuring done
-- Generating done
CMake Warning:Manually-specified variables were not used by the project:NABLE_NEON-- Build files have been written to: /home/jason/file/libfacedetection-master

执行上面的命令成功后,执行下面语句进行编译

make -j4

输出:

[ 25%] Building CXX object CMakeFiles/facedetection.dir/src/facedetectcnn-data.cpp.o
[ 50%] Building CXX object CMakeFiles/facedetection.dir/src/facedetectcnn-model.cpp.o
[ 75%] Building CXX object CMakeFiles/facedetection.dir/src/facedetectcnn.cpp.o
[100%] Linking CXX static library libfacedetection.a
[100%] Built target facedetection

如此,得到了两个重要的文件:

 3、构建工程

除了上面得到的facedetection_export.h文件,还需要src目录下的四个文件:

 以及examples目录下的detect-image.cpp(你也可以用detect-camera.cpp),改名为main.cpp

 稍微修改main.cpp

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "facedetectcnn.h"//define the buffer size. Do not change the size!
//0x9000 = 1024 * (16 * 2 + 4), detect 1024 face at most
#define DETECT_BUFFER_SIZE 0x9000
using namespace cv;
using namespace std;int main()
{//load an image and convert it to gray (single-channel)string img_path = "/home/jason/file/02-use-libfacedetection/cnnresult.png";Mat image = imread(img_path);if(image.empty()){printf("Can not load the image file %s.\n", img_path.c_str());return -1;}int * pResults = NULL; //pBuffer is used in the detection functions.//If you call functions in multiple threads, please create one buffer for each thread!unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);if(!pBuffer){fprintf(stderr, "Can not alloc buffer.\n");return -1;}///// CNN face detection // Best detection rate////!!! The input image must be a BGR one (three-channel) instead of RGB//!!! DO NOT RELEASE pResults !!!TickMeter cvtm;cvtm.start();pResults = facedetect_cnn(pBuffer, (unsigned char*)(image.ptr(0)), image.cols, image.rows, (int)image.step);cvtm.stop();    printf("time = %gms\n", cvtm.getTimeMilli());printf("%d faces detected.\n", (pResults ? *pResults : 0));Mat result_image = image.clone();//print the detection resultsfor(int i = 0; i < (pResults ? *pResults : 0); i++){short * p = ((short*)(pResults + 1)) + 16*i;int confidence = p[0];int x = p[1];int y = p[2];int w = p[3];int h = p[4];//show the score of the face. Its range is [0-100]char sScore[256];snprintf(sScore, 256, "%d", confidence);cv::putText(result_image, sScore, cv::Point(x, y-3), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 255, 0), 1);//draw face rectanglerectangle(result_image, Rect(x, y, w, h), Scalar(0, 255, 0), 2);//draw five face landmarks in different colorscv::circle(result_image, cv::Point(p[5], p[5 + 1]), 1, cv::Scalar(255, 0, 0), 2);cv::circle(result_image, cv::Point(p[5 + 2], p[5 + 3]), 1, cv::Scalar(0, 0, 255), 2);cv::circle(result_image, cv::Point(p[5 + 4], p[5 + 5]), 1, cv::Scalar(0, 255, 0), 2);cv::circle(result_image, cv::Point(p[5 + 6], p[5 + 7]), 1, cv::Scalar(255, 0, 255), 2);cv::circle(result_image, cv::Point(p[5 + 8], p[5 + 9]), 1, cv::Scalar(0, 255, 255), 2);//print the resultprintf("face %d: confidence=%d, [%d, %d, %d, %d] (%d,%d) (%d,%d) (%d,%d) (%d,%d) (%d,%d)\n", i, confidence, x, y, w, h, p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13],p[14]);}imshow("result", result_image);waitKey();//release the bufferfree(pBuffer);return 0;
}

构建方式设为release:

结果:

time = 687.227ms
39 faces detected.
face 0: confidence=93, [864, 419, 105, 135] (888,470) (940,467) (912,496) (895,518) (939,516)
face 1: confidence=93, [77, 170, 70, 92] (102,205) (134,206) (121,224) (103,238) (131,238)
face 2: confidence=93, [535, 599, 105, 137] (562,654) (613,652) (589,677) (566,699) (612,698)
face 3: confidence=92, [867, 278, 66, 87] (885,312) (914,311) (900,329) (888,343) (914,341)
face 4: confidence=92, [636, 374, 80, 106] (659,414) (694,414) (677,436) (661,453) (692,453)
face 5: confidence=92, [731, 288, 79, 100] (755,324) (791,324) (774,344) (757,361) (789,361)
face 6: confidence=92, [1168, 233, 76, 101] (1190,265) (1223,265) (1207,287) (1192,303) (1222,303)
face 7: confidence=92, [259, 292, 74, 97] (277,331) (314,331) (295,352) (280,363) (311,365)
face 8: confidence=92, [386, 512, 88, 110] (411,558) (454,557) (433,581) (412,595) (449,596)
face 9: confidence=92, [653, 116, 63, 80] (669,145) (697,144) (681,162) (671,175) (695,174)
face 10: confidence=91, [149, 233, 64, 85] (165,266) (196,266) (181,285) (170,298) (195,297)
face 11: confidence=91, [1034, 326, 91, 112] (1055,363) (1094,362) (1072,384) (1061,405) (1092,403)
face 12: confidence=91, [310, 134, 58, 73] (330,160) (355,161) (344,176) (332,187) (353,188)
face 13: confidence=91, [968, 120, 59, 76] (985,146) (1013,147) (1000,162) (986,173) (1011,175)
face 14: confidence=91, [431, 271, 62, 81] (449,300) (479,300) (466,317) (451,330) (477,330)
face 15: confidence=90, [472, 148, 68, 90] (491,182) (524,182) (507,201) (493,213) (520,215)
face 16: confidence=90, [1063, 55, 55, 73] (1075,80) (1098,80) (1085,95) (1078,107) (1099,108)
face 17: confidence=90, [3, 171, 56, 77] (16,198) (42,198) (29,214) (18,227) (41,227)
face 18: confidence=90, [771, 84, 60, 75] (792,111) (818,111) (807,127) (793,139) (815,139)
face 19: confidence=88, [317, 13, 41, 53] (327,35) (345,35) (336,46) (330,55) (344,54)
face 20: confidence=88, [606, 46, 52, 65] (619,70) (644,70) (631,83) (621,92) (641,94)
face 21: confidence=88, [48, 73, 47, 58] (62,93) (84,93) (73,105) (63,112) (81,114)
face 22: confidence=88, [545, 54, 54, 71] (562,81) (586,81) (576,96) (565,106) (584,107)
face 23: confidence=87, [259, 57, 48, 62] (275,81) (295,81) (286,94) (276,104) (292,104)
face 24: confidence=85, [222, 60, 45, 61] (239,84) (250,82) (248,95) (244,106) (252,105)
face 25: confidence=85, [718, 215, 72, 79] (737,248) (767,247) (753,267) (744,275) (766,277)
face 26: confidence=80, [1098, 46, 53, 73] (1123,76) (1130,76) (1129,90) (1128,103) (1130,103)
face 27: confidence=78, [147, 167, 46, 60] (157,191) (172,191) (161,203) (159,212) (171,215)
face 28: confidence=78, [699, 2, 46, 43] (711,15) (733,13) (723,25) (716,32) (732,33)
face 29: confidence=74, [450, 1, 50, 41] (472,6) (491,5) (486,17) (474,27) (489,28)
face 30: confidence=63, [1194, 38, 52, 60] (1211,58) (1236,59) (1223,70) (1211,79) (1230,81)
face 31: confidence=62, [832, 86, 42, 58] (844,106) (859,106) (851,118) (847,126) (860,129)
face 32: confidence=48, [1149, 0, 35, 28] (1162,5) (1175,5) (1169,13) (1164,18) (1173,21)
face 33: confidence=48, [810, 0, 42, 40] (825,7) (841,7) (834,18) (827,26) (841,28)
face 34: confidence=45, [1021, 92, 40, 52] (1032,111) (1045,112) (1037,122) (1035,129) (1044,131)
face 35: confidence=42, [571, 0, 38, 26] (583,-3) (598,-2) (590,2) (583,12) (594,11)
face 36: confidence=30, [114, 0, 36, 25] (121,-1) (135,0) (125,4) (123,13) (134,13)
face 37: confidence=28, [0, 28, 30, 58] (5,50) (14,50) (10,60) (9,69) (16,71)
face 38: confidence=21, [889, 0, 20, 17] (896,0) (904,2) (900,5) (897,12) (902,10)

4、个人总结

运行总结:

  • 图片中检测即使构建方式为Release,依然是600多ms耗时,感觉有点慢
  • 使用摄像头检测,构建方式未Realease,检测耗时150ms左右,有点延迟
  • 不过该说不说,这张图片后面被虚化的人脸都检测出来了,确实检测效果还不错
  • 另外图片检测的话,检测框我怎么看都有两个,从源码中暂时又看不出什么问题。可是github上挂的结果图不是这样的啊,有大佬知道怎么回事吗?
  • 而摄像头检测则很正常,只有一个检测框

与CascadeClassifier级联分类器 人脸检测 对比:

  •  效果好很多,侧脸也可以识别出来,只要露出眼睛嘴巴鼻子
  • 存在一定误检,但是可以控制输出阈值的方式调整

存在的疑问:

编译生成的静态库应该有用?

  

参考:

libfacedetection库的配置及基本使用——内涵(cmake编译libfacedetection库)_龙龙就是龙龙的博客-CSDN博客

https://www.cnblogs.com/oloroso/p/10716214.html


http://chatgpt.dhexx.cn/article/jh80YeFY.shtml

相关文章

人脸检测库libfacedetection使用方法

libfacedetection介绍 libfacedetection是一个开源的人脸检测库&#xff0c;使用C编写&#xff0c;将模型文件转化为C的静态变量&#xff0c;不依赖外部第三方库&#xff0c;使用时可以直接把源代码拷到自己的工程&#xff0c;也可以使用动态库(so)/静态库(a)的方式来调用&…

人脸识别之一图像采集及人脸库的建立

完整人脸识别系统&#xff08;源码教程环境&#xff09;&#xff1a; 开源毕业设计&#xff1a;基于嵌入式ARM-Linux的应用OpenCV和QT实现的人脸识别系统(源码论文) 完全毕设教程&#xff1a;Linux上Opencv与Qt实现的人脸识别的考勤点名/门禁系统(PC与嵌入式ARM版本) 人脸识别…

C++实现人脸识别(百度云平台)

C实现人脸识别&#xff08;百度云平台&#xff09; 项目资源下载 项目思路&#xff1a;opencv 采集人脸照片&#xff0c;将照片发送至百度智能云平台&#xff0c;百度云平台与人脸库中的数据进行比较并返回结果。 一、项目环境 Ubuntu 64 20.0.4 opencv 4.2.0 二、环境配置…

人脸识别开源库

https://blog.csdn.net/qq_42156420/article/details/83445801 以往的人脸识别主要是包括人脸图像采集、人脸识别预处理、身份确认、身份查找等技术和系统。现在人脸识别已经慢慢延伸到了ADAS中的驾驶员检测、行人跟踪、甚至到了动态物体的跟踪。由此可以看出&#xff0c;人脸…

人脸识别——基于DLib库

目录 1.人脸识别的流程 2.ResNet-34算法概述 3.测试准备 4.测试代码 5.测试结果 1.人脸识别的流程 dlib库提供高精度人脸识别算法是基于深度学习网络ResNet-34实现&#xff0c;该网络基于三百万张照片进行训练&#xff0c;最终获得了人脸检测模型。 模型下载地址&#xff…

深度学习系列18:开源人脸识别库

这年头&#xff0c;能有个开源的人脸库真是感天谢地了&#xff0c;而且可以在arm机器上使用&#xff0c;真不容易。git地址见https://github.com/ageitgey/face_recognition 1. 人脸检测 人脸检测可以选hog和cnn两种。默认用hog&#xff08;在cpu上用cnn真的很慢&#xff09;…

人脸识别库的安装

确保你的python为3.6 !!! 1.安装cmake pip install cmake2.安装boost pip install boost3.安装dlib 选择19.8.1 pip install dlib19.8.14.安装face-recognition pip install face-recognition

应用一个基于Python的开源人脸识别库,face_recognition

转载请注明出处&#xff1a;http://blog.csdn.net/hongbin_xu 或 http://hongbin96.com/ 文章链接&#xff1a;http://blog.csdn.net/hongbin_xu/article/details/74981819 或http://hongbin96.com/125 今天看微信时&#xff0c;看到一篇推送文章介绍了一个基于python的开源人…

开源人脸识别库,face_recognition

转载请注明出处&#xff1a;http://blog.csdn.net/hongbin_xu 或 http://hongbin96.com/ 文章链接&#xff1a;http://blog.csdn.net/hongbin_xu/article/details/74981819 或http://hongbin96.com/125 今天看微信时&#xff0c;看到一篇推送文章介绍了一个基于python的开源人…

[深度学习] Python人脸识别库Deepface使用教程

deepface是一个Python轻量级人脸识别和人脸属性分析&#xff08;年龄、性别、情感和种族&#xff09;框架&#xff0c;提供非常简单的接口就可以实现各种人脸识别算法的应用。deepface官方仓库为deepface。deepface提供了多种模型&#xff0c;模型下载地址为deepface_models。 …

[深度学习] Python人脸识别库face_recognition使用教程

Python人脸识别库face_recognition使用教程 face_recognition号称是世界上最简单的开源人脸识别库&#xff0c;可以通过Python或命令行识别和操作人脸。face_recognition提供了十分完整的技术文档和应用实例&#xff0c;人脸识别初学者建议研究该库上手。face_recognition的官…

Face Recognition 库-人脸识别

1. Face Recognition 库简介&#xff1a; 中文文档&#xff1a; [face_recognition/README_Simplified_Chinese.md] Face Recognition 库主要封装了dlib这一 C 图形库&#xff0c;通过 Python 语言将它封装为一个非常简单就可以实现人脸识别的 API 库&#xff0c;屏蔽了人脸识…

应用层下的人脸识别(二):人脸库

本文为系列文章的第二篇&#xff0c;介绍人脸库的相关内容。人脸库是人脸识别的基础&#xff0c;建立人脸库往往是人脸项目的首要任务&#xff0c;全文围绕着什么是人脸库及如何建立人脸库展开讨论。 1. 什么是人脸库 简单来讲&#xff0c;人脸库就是人脸数据的储存管理中心&a…

全国高校计算机能力挑战赛Java试题(一)

消除字符串 这个题目上来就是运用一个回文的一个思想&#xff0c;我目前算法也是入门阶段&#xff0c;所以也处于学习阶段。 public class xiaozfc {public static void main(String[] args) {Scanner sc new Scanner(System.in);String txt sc.next();ArrayList<String&…

Java课程设计--学生成绩管理系统

一、团队名称&#xff1a; 团队成员&#xff1a; 刘江华 2019122249819 19信管专升本杨利杰 2018122241648 18信管本张富强 2018122241658 18信管本 二、需求分析 1.数据存储在数据库和文件中 分为“教师”模块和“学生”模块。 2.学生模块提供登陆功能&#xff0c;登陆成功后…

Java8--20道关于Stream流的题目练习

正题开始 Student 类 具有属性&#xff1a; 不及格次数failCount&#xff0c; 名字name&#xff0c; 科任老师chineseTeacher&#xff0c; 班主任classTeacher题目1&#xff1a;筛选学生不及格次数3次及3次以上的学生列表 List<String> arrayList array.stream().filte…

第十三届蓝桥杯省赛 JAVA B组(真题解析+个人体会)(已更新完G题)

试题 A: 星期计算【填空题】 题目&#xff1a; 答案&#xff1a;7 解析&#xff1a; 此题直接对7求余即可。 public class Main {public static void main(String[] args) {System.out.println(Math.pow(20, 22) % 7 6);} } 贴一个BigInteger的代码 import java.math.Bi…

java的一些课程设计题目_Java课程设计

Java课程设计 1. 题目及要求 基于学校的搜索引擎 负责部分:Java GUI设计 2.界面调查 1)调查界面:百度 2)思考: 根据我的调查,我认为我需要完成三个界面的设计: 第一个是调查主界面,里面有一个集美大学的logo,一个搜索框用文本字段,因为需要在里面写入搜索内容,一个搜索…

计算机二级--java篇

计算机二级 全国计算机等级&#xff08;NCRE&#xff09;&#xff0c;计算机二级分为语言程序设计&#xff08;包括C、C、Java、Visual Basic&#xff09;、数据库程序设计&#xff08;包括Visual FoxPro、Access&#xff09;、MS Office高级应用&#xff0c;各项目均为机考。考…

java 课程设计题目_Java课程设计题目有哪些?Java课程设计题目汇总

在学习Java的路上,多多练习项目实践是很有必要的。因此,本文整理了20道Java课程设计题目,希望大家总结、回顾和实践学过的所有面向对象的编程思想以及编程方法。 1、编写一个记事本程序 要求:用图形用户界面实现。 能实现编辑、保存、另存为、查找替换等功能。 提示:使用文…