Tadas Baltrusaitis的OpenFace是一个开源的面部行为分析工具,它的源码可以从 https://github.com/TadasBaltrusaitis/OpenFace 下载。OpenFace主要包括面部关键点检测(facial landmard detection)、头部姿势估计(head pose estimation)、面部动作单元识别(facial action unit recognition)、人眼视线方向估计(eye gaze estimation)。
编译Tadas Baltrusaitis的OpenFace需要依赖开源库boost、dlib、TBB、OpenCV。

以下是基于Haar Cascade Classifiers方法的人脸检测的测试代码:

#include "funset.hpp"
#include <vector>
#include <string>
#include <fstream>#include <filesystem.hpp>
#include <filesystem/fstream.hpp>
#include <dlib/image_processing/frontal_face_detector.h>
#include <tbb/tbb.h>
#include <opencv2/opencv.hpp>#include <LandmarkCoreIncludes.h>
#include <FaceAnalyser.h>
#include <GazeEstimation.h>#define CONFIG_DIR "E:/GitCode/Face_Test/src/TadasBaltrusaitis_OpenFace/lib/local/LandmarkDetector/"int test_FaceDetect_HaarCascade()
{std::vector<std::string> arguments{ "", "-wild", "-fdir", "E:/GitCode/Face_Test/testdata/","-ofdir", "E:/GitCode/Face_Test/testdata/ret1/", "-oidir", "E:/GitCode/Face_Test/testdata/ret2/" };std::vector<std::string> files, depth_files, output_images, output_landmark_locations, output_pose_locations;std::vector<cv::Rect_<double> > bounding_boxes; // Bounding boxes for a face in each image (optional)LandmarkDetector::get_image_input_output_params(files, depth_files, output_landmark_locations, output_pose_locations, output_images, bounding_boxes, arguments);LandmarkDetector::FaceModelParameters det_parameters(arguments);cv::CascadeClassifier classifier(det_parameters.face_detector_location);for (auto file : files) {cv::Mat grayscale_image = cv::imread(file, 0);if (grayscale_image.empty()) {fprintf(stderr, "Could not read the input image: %s\n", file.c_str());return -1;}int pos = file.find_last_of("\\");std::string image_name = file.substr(pos + 1);std::vector<cv::Rect_<double> > face_detections; // Detect faces in an imageLandmarkDetector::DetectFaces(face_detections, grayscale_image, classifier);std::string image_path = file.substr(0, pos);std::string save_result = image_path + "/ret2/_" + image_name;cv::Mat bgr = cv::imread(file, 1);fprintf(stderr, "%s face count: %d\n", image_name.c_str(), face_detections.size());for (int i = 0; i < face_detections.size(); ++i) {cv::Rect_<double> rect{ face_detections[i] };fprintf(stderr, "    x: %.2f, y: %.2f, width: %.2f, height: %.2f\n",rect.x, rect.y, rect.width, rect.height);cv::rectangle(bgr, cv::Rect(rect.x, rect.y, rect.width, rect.height), cv::Scalar(0, 255, 0), 2);}cv::imwrite(save_result, bgr);}int width = 200;int height = 200;cv::Mat dst(height * 5, width * 4, CV_8UC3);int pos = files[0].find_last_of("\\");std::string image_path = files[0].substr(0, pos);for (int i = 0; i < files.size(); i++) {std::string image_name = files[i].substr(pos + 1);std::string input_image = image_path + "/ret2/_" + image_name;cv::Mat src = cv::imread(input_image, 1);if (src.empty()) {fprintf(stderr, "read image error: %s\n", input_image.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 = image_path + "/ret2/result.png";cv::imwrite(output_image, dst);return 0;
}

执行结果如下图:

人脸检测结果如下:

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

OpenFace库(Tadas Baltrusaitis)中基于Haar Cascade Classifiers进行人脸检测的测试代码相关推荐

  1. OpenFace库(Tadas Baltrusaitis)中基于HOG进行正脸人脸检测的测试代码

    Tadas Baltrusaitis的OpenFace是一个开源的面部行为分析工具,它的源码可以从https://github.com/TadasBaltrusaitis/OpenFace下载.Ope ...

  2. 基于Haar分类器的OpenCV人脸检测实例

    一.人脸的Haar特征分类器是什么 人脸的Haar特征分类器就是一个XML文件,该文件中会描述人脸的Haar特征值.当然Haar特征的用途可不止可以用来描述人脸这一种,用来描述眼睛,嘴唇或是其它物体也 ...

  3. Dlib库中实现正脸人脸检测的测试代码

    Dlib库中提供了正脸人脸检测的接口,这里参考dlib/examples/face_detection_ex.cpp中的代码,通过调用Dlib中的接口,实现正脸人脸检测的测试代码,测试代码如下: #i ...

  4. 基于Android平台的简易人脸检测库

    代码地址如下: http://www.demodashi.com/demo/12135.html ViseFace 简易人脸检测库,不依赖三方库,可快速接入人脸检测功能. 项目依赖:compile ' ...

  5. Dlib库中实现正脸人脸关键点(landmark)检测的测试代码

    Dlib库中提供了正脸人脸关键点检测的接口,这里参考dlib/examples/face_landmark_detection_ex.cpp中的代码,通过调用Dlib中的接口,实现正脸人脸关键点检测的 ...

  6. 两个一样的图像相除会怎么样_【壮凌自动化分析】一种动力电池生产中基于图像运动模糊的速度检测方法...

    一种动力电池生产中基于图像运动模糊的速度检测方法 1.西南大学 电子信息工程学院,重庆 400715) 2.非线性电路与智能信息处理重庆市重点实验室,重庆 400715) 1.当前背景与成熟方法介绍 ...

  7. 基于OpenCV的视频处理 - 人脸检测

    一个不知名大学生,江湖人称菜狗 original author: jacky Li Email : 3435673055@qq.com  Time of completion:2023.2.7 Las ...

  8. 使用 OpenCV与 HAAR 级联算法进行人脸检测和人脸识别

    AI人脸识别是一种从数字图像或视频帧中识别或验证人脸的技术.人类可以毫不费力地快速识别面部.这对我们来说是一项轻松的任务,但对计算机来说却是一项艰巨的任务.因为存在各种复杂性,例如低分辨率.遮挡.光照 ...

  9. Haar特征描述算子-人脸检测

    Haar特征描述算子-人脸检测 详细资料 3.1简介 Haar-like特征最早是由Papageorgiou等应用于人脸表示,在2001年,Viola和Jones两位大牛发表了经典的<Rapid ...

最新文章

  1. android view的隐藏和显示_Android使用Viewpager实现3D卡片翻动效果
  2. 20165203《Java程序设计》第二周Java学习总结
  3. 【深度学习】Focal Loss 与 GHM——解决样本不平衡问题
  4. Javascript 面向对象编程初探(一)--- 封装
  5. Scala数组和Java集合互转代码演示
  6. C++ static的作用
  7. 大数据安全分析“架构”
  8. HttpURLConnection与 HttpClient 区别/性能测试对比
  9. mysql 5.6密钥_MySQL的密钥文件不正确
  10. python numpy中对ndarry按照index(位置下标)增删改查
  11. uboot常用命令详解 2
  12. 共享onload事件
  13. 优酷1080p的kux格式文件转换方法
  14. 一键登录163邮箱方法
  15. PDF带目录导出java_itextpdf为pdf文件添加目录(可跳转)
  16. 大脑信息编码_编码人大脑的5大小吃
  17. python获取别人的微信好友_python使用itchat获取微信好友列表
  18. POI对Word操作参考
  19. ps提示没有足够的ram
  20. python求解迷宫问题,配js实现的走迷宫动画,动起来才有意思~

热门文章

  1. Python Qt GUI设计:QLineEdit和QTextEdit文本框类(基础篇—13)
  2. OpenCV(22)SIFT尺度不变特征变换(纯理论)
  3. python创建对象的格式为_Python入门基础学习(面向对象)
  4. scp 命令 路径_基于SSH的文件传输:scp命令
  5. 自动驾驶中高效的激光雷达里程计
  6. Python中if__name__==__main__:该如何理解
  7. C/C++指向指针的指针
  8. 【从零开始的ROS四轴机械臂控制】(七)- ROS与arduino连接
  9. SketchUp Pro 2021基础入门学习视频教程
  10. linux进程间通信:无名管道 pipe