zoukankan      html  css  js  c++  java
  • 如何快糙好猛的使用libfacedetection库【最新版】

    前言

    最近已经很少看CSDN了。这一年多准备考研,基本上怕是不会再怎么上了。以前有一个http://blog.csdn.net/mr_curry/article/details/51804072 如何快糙好猛的使用Shiqi.Yu老师的公开人脸检测库(附源码)的BLOG,因为于老师的库已经更新了,所以重新写一下吧。
    PS:这个库越来越强了,已经可以做人脸关键点检测了。关键点检测可以用于矫正人脸,再也不要用慢的要死的dlib啦~~

    配置

    五张图带你解决问题:(X64,Debug)
    这里写图片描述
    这里写图片描述
    这里写图片描述

    然后你需要把opencv的属性表也引进来:
    这里写图片描述

    两个方法,加系统变量或者放到和exe同一个文件夹下。加了系统变量后重启一次才生效,所以这里就直接放咯
    这里写图片描述

    代码

    我们直接用FDDB上评测效果最好的函数:facedetect_multiview_reinforce
    这里写图片描述

    #include <opencv.hpp>
    #include <facedetect-dll.h>
    using namespace cv;
    using namespace std;
    
    //define the buffer size. Do not change the size!
    #define DETECT_BUFFER_SIZE 0x20000
    
    int main()
    {
        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.
    ");
            return -1;
        }
        Mat src = imread("img.jpg");
        Mat gray;
        cvtColor(src, gray, CV_BGR2GRAY);
        int doLandmark = 1;// do landmark detection
        pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step,
            1.2f, 2, 48, 0, doLandmark);
        //print the detection results
        for (int i = 0; i < (pResults ? *pResults : 0); i++)
        {
            short * p = ((short*)(pResults + 1)) + 142 * i;
            rectangle(src, Rect(p[0], p[1], p[2], p[3]), Scalar(0, 255, 0), 2);
            if (doLandmark)
            {
                for (int j = 0; j < 68; j++)
                    circle(src, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 0, 255),2);
            }
        }
        imshow("Show", src);
        waitKey(0);
    }

    效果还是很赞:
    这里写图片描述

    视频流中的人脸检测代码就是用VideoCapture解析为Mat然后循环检测啊:

    #include <opencv.hpp>
    #include <facedetect-dll.h>
    using namespace cv;
    using namespace std;
    
    //define the buffer size. Do not change the size!
    #define DETECT_BUFFER_SIZE 0x20000
    
    int main()
    {
        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.
    ");
            return -1;
        }
        int doLandmark = 1;// do landmark detection
        VideoCapture cap(0);
        if (!cap.isOpened()){
            cout << "Please check your USB camera's interface num." << endl;
            return 0;
        }
        Mat src;
        while (true)
        {
            cap >> src;
            if (!src.empty()){
                Mat gray;
                cvtColor(src, gray, CV_BGR2GRAY);
                pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step,
                    1.2f, 2, 48, 0, 1);
                for (int i = 0; i < (pResults ? *pResults : 0); i++)
                {
                    short * p = ((short*)(pResults + 1)) + 142 * i;
                    rectangle(src, Rect(p[0], p[1], p[2], p[3]), Scalar(0, 255, 0), 2);
                    if (doLandmark)
                    {
                        for (int j = 0; j < 68; j++)
                            circle(src, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 0, 255), 2);
                    }
                }
                imshow("Show", src);
                waitKey(1);
            }
    
        }
    }
  • 相关阅读:
    C# 遍历enum类型元素、获取最大值、最小值
    ABAP-成本报表案例
    recovering corrupted postgres database
    自定义QHeaderView后,点击表头排序失效的解决办法
    Visual Studio 2017社区版登录时始终卡在登录界面的另一个登录办法
    已经安装好的TortoiseSVN在更改盘符后不能使用无法卸载也无法安装的解决办法
    使用别人已经静态编译好的Qt库在进行自己的Qt Creator配置时,在配置Qt Version时出现的2个问题解决办法
    ASCII、Unicode和UTF-8,一文看懂,保存链接
    centos7 挂载硬盘操作
    一次性kill所有进程的命令
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412024.html
Copyright © 2011-2022 走看看