【最快人脸检测模型开源】libfacedetection开源

285 篇文章 55 订阅
261 篇文章 14 订阅

来自于仕琪老师的人脸检测库,可以实现高达1500fps的人脸检测
算法源码已经开源

在这里插入图片描述

1.简介

libfacedetection是一个优秀的人脸检测算法库,在pc和树莓派上都能达到十分优秀的检测结果:

windows上的表现
MethodTimeFPSTimeFPS
X64X64X64X64
Single-threadSingle-threadMulti-threadMulti-thread
OpenCV Haar+AdaBoost (640x480)12.33ms81.1
cnn (CPU, 640x480)64.21ms15.5715.59ms64.16
cnn (CPU, 320x240)15.23ms65.683.99ms250.40
cnn (CPU, 160x120)3.47ms288.080.95ms1052.20
cnn (CPU, 128x96)2.35ms425.950.64ms1562.10
  • OpenCV Haar+AdaBoost runs with minimal face size 48x48
  • Face detection only, and no landmark detection included.
  • Minimal face size ~12x12
  • Intel® Core™ i7-7700 CPU @ 3.6GHz.
嵌入式设备Raspberry Pi 3 B+上的表现
MethodTimeFPSTimeFPS
Single-threadSingle-threadMulti-threadMulti-thread
cnn (CPU, 640x480)512.04ms1.95174.89ms5.72
cnn (CPU, 320x240)123.47ms8.1042.13ms23.74
cnn (CPU, 160x120)27.42ms36.479.75ms102.58
cnn (CPU, 128x96)17.78ms56.246.12ms163.50
  • Face detection only, and no landmark detection included.
  • Minimal face size ~12x12
  • Raspberry Pi 3 B+, Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz

近日算法的源码已经开源:
在这里插入图片描述

2.源码

源码中主要包含了四个文件,包括了模型数据、人脸检测cnn模型的定义和卷积操作的实现等:

facedetectcnn-floatdata.cpp   //模型数据
facedetectcnn-int8data.cpp   //模型数据
facedetectcnn-model.cpp	     //cnn定义
facedetectcnn.cpp            //基本操作定义
facedetectcnn.h

1.使用样例

API是这样的:int * facedetect_cnn(unsigned char * result_buffer, //buffer memory for storing face detection results, !!its size must be 0x20000 Bytes!! unsigned char * rgb_image_data, int width, int height, int step); //input image, it must be RGB (three-channel) image!

//copy from https://github.com/ShiqiYu/libfacedetection/blob/master/example/libfacedetectcnn-example.cpp
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "facedetectcnn.h"

//定义缓冲区大学. Do not change the size!
#define DETECT_BUFFER_SIZE 0x20000
using namespace cv;

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
    	//图像的路径输入
        printf("Usage: %s <image_file_name>\n", argv[0]);
        return -1;
    }

	//load an image and convert it to gray (single-channel)
	Mat image = imread(argv[1]); 
	if(image.empty())
	{
		fprintf(stderr, "Can not load the image file %s.\n", argv[1]);
		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 RGB one (three-channel)
	//!!! DO NOT RELEASE pResults !!!
	pResults = facedetect_cnn(pBuffer, (unsigned char*)(image.ptr(0)), image.cols, image.rows, (int)image.step);
	//这个api用于检测

    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++)
	{
        
        //返回值position坐标点
        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 confidence = p[4]; 
		int angle = p[5];

		//printf("face_rect=[%d, %d, %d, %d], neighbors=%d, angle=%d\n", x,y,w,h,neighbors, angle);   
		//update neifhbors to confidence,05302019
		printf("face_rect=[%d, %d, %d, %d], confidence=%d, angle=%d\n", x,y,w,h,confidence, angle);
		rectangle(result_cnn, Rect(x, y, w, h), Scalar(0, 255, 0), 2);   //画框框
	}
	imshow("result_cnn", result_cnn);

	waitKey();

    //release the buffer
    free(pBuffer);

	return 0;
}

注:
1.可以使用avx2指令集编译得到更大的加速。
2.于老师曾经写了著名的《OpenCV入门教程》

ref:
https://blog.csdn.net/m0_37733057/article/details/68059552
https://blog.csdn.net/CV_Jason/article/details/78819088 https://blog.csdn.net/CV_Jason/article/details/78819088
https://blog.csdn.net/sinat_31425585/article/details/77891844

在这里插入图片描述
pic from pexels.com

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值