最牛的人脸检测算法

深大于老师的libfacedetection检测算法快速高效准确率相当高,世界排名第五,最小可检测人脸12×12像素关键是前两天开源了,于是我简单的看了一下,是自己用c++手敲的cnn代码,真心佩服。

该代码可以在windows linux arm android平台等只要支持c++编译环境中运行,下面是windows和树莓派(arm)平台运行的各项参数:

下面我在ubuntu16.04 下编译和运行了一下,效果非常好,感兴趣的朋友可以试一试,IDE用的是QT。

1、下载源码

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

2、qt5编译

(1)配置.pro文件

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += \
    libfacedetectcnn-example.cpp \
    facedetectcnn-int8data.cpp \
    facedetectcnn-floatdata.cpp \
    facedetectcnn-model.cpp \
    facedetectcnn.cpp

HEADERS += \
    facedetectcnn.h

#system
INCLUDEPATH += /usr/local/lib \
               /usr/lib/x86_64-linux-gnu

LIBS += -L/usr/local/lib

#opencv   其实在/usr/include就可以不要添加
INCLUDEPATH += /usr/include \
               /usr/include/opencv \
               /usr/include/opencv2/

LIBS += -L /usr/lib/libopencv_*.so

QMAKE_CXXFLAGS_RELEASE += -O3             # Release -O3
QMAKE_CXXFLAGS_RELEASE += -march=native     

(2)修改libfacedetectcnn-example.cpp(我是用摄像头测试)

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "facedetectcnn.h"
#include "time.h"

//define the buffer size. Do not change the size!
#define DETECT_BUFFER_SIZE 0x20000
using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    //usb camera
    Mat image;
    VideoCapture cam(0);

    while(1){
        cam >> image;
        if(image.empty())
        {
            fprintf(stderr, "Can not open camera.\n");
            return -1;
        }
        resize(image,image,Size(320,240));

        time_t start = clock();
        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 RGB one (three-channel)
        //!!! DO NOT RELEASE pResults !!!
        pResults = facedetect_cnn(pBuffer, (unsigned char*)(image.ptr(0)), image.cols, image.rows, (int)image.step);
        printf("%d faces detected.\n", (pResults ? *pResults : 0));
        Mat result_cnn = image.clone();;
        //print the detection results
        for(int i = 0; i < (pResults ? *pResults : 0); i++)
        {
            short * p = ((short*)(pResults+1))+142*i;
            int x = p[0];
            int y = p[1];
            int w = p[2];
            int h = p[3];
            int neighbors = p[4];
            int angle = p[5];

            printf("face_rect=[%d, %d, %d, %d], neighbors=%d, angle=%d\n", x,y,w,h,neighbors, angle);
            cv::rectangle(result_cnn, Rect(x, y, w, h), Scalar(0, 255, 0), 2);
        }

        time_t end = clock();

        //show in the screen
        imshow("result_cnn", result_cnn);

        //release the buffer
        free(pBuffer);

        //calculate running time
        double total_time = (double)(end-start)/CLOCKS_PER_SEC*1000;
        cout<<"total_time:"<<total_time<<"ms"<<endl;

        waitKey(1);
    }
    return 0;
}

3、测试

至于速度和准确度,你们测试一下就知道了。

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值