鼠标帧率检测软件_CPU实时帧率超过100+,嵌入式端首选的人脸检测库推荐

本文推荐了一款适用于嵌入式设备的人脸检测库,该库基于卷积神经网络,提供硬件指令加速的C++ SDK,不依赖第三方库。库支持最小10x10像素的人脸检测,模型文件可从Github获取,支持pytorch。此外,文章还展示了使用OpenCV DNN进行人脸检测的示例代码及运行效果。
摘要由CSDN通过智能技术生成
95a05120416c3a55914adb59fe38dafd.gif

点击上方蓝字关注我们

微信公众号:OpenCV学堂

关注获取更多计算机视觉与深度学习知识

开源人脸库调用尝试

 基于卷积神经网络的人脸检测库,实现了硬件指令加速,纯C++ SDK接口,不依赖第三方库与接口,可以独立使用,同时也提供了模型文件下载,之前的版本是caffe模型,最新版本支持pytorch。现已开源!支持最小检测人脸10x10大小

a76379b1d7f2940893cb0759066936a7.png

OpenCV DNN可以直接调用训练好的caffe模型文件,实现实时人脸检测,演示代码如下:

 1#include 
2#include 
3#include 
4
5using namespace cv;
6using namespace cv::dnn;
7using namespace std;
8
9const size_t inWidth = 300;
10const size_t inHeight = 300;
11const double inScaleFactor = 0.007843;
12const Scalar meanVal(104.0, 117, 123.0);
13const float confidence = 0.5;
14
15int main(int argc, char** argv) {
16    string model = "D:/projects/models/yufacedetectnet-open-v2.caffemodel";
17    string config = "D:/projects/models/yufacedetectnet-open-v2.prototxt";
18    // read network
19    Net net = readNetFromCaffe(config, model);
20    VideoCapture cap(0);
21    Mat frame;
22    while (true) {
23        bool ret = cap.read(frame);
24        if (!ret) {
25            break;
26        }
27        int64 start = getTickCount();
28        Mat input_data = blobFromImage(frame, inScaleFactor, Size(320, 240), meanVal, false, false);
29        net.setInput(input_data);
30
31        // 人脸检测
32        Mat detection = net.forward();
33        Mat detectionMat(detection.size[2], detection.size[3], CV_32F, detection.ptr<float>());
34
35        // 推断时间
36        vector<double> layersTimings;
37        double freq = getTickFrequency() / 1000;
38        double time = net.getPerfProfile(layersTimings) / freq;
39
40        ostringstream ss;
41        for (int i = 0; i 42        {
43            // 置信度 0~1之间
44            float score = detectionMat.at<float>(i, 2);
45            if (score > confidence)
46            {
47                int xLeftBottom = static_cast<int>(detectionMat.at<float>(i, 3) * frame.cols);
48                int yLeftBottom = static_cast<int>(detectionMat.at<float>(i, 4) * frame.rows);
49                int xRightTop = static_cast<int>(detectionMat.at<float>(i, 5) * frame.cols);
50                int yRightTop = static_cast<int>(detectionMat.at<float>(i, 6) * frame.rows);
51
52                Rect object((int)xLeftBottom, (int)yLeftBottom,53                    (int)(xRightTop - xLeftBottom),54                    (int)(yRightTop - yLeftBottom));
55
56                rectangle(frame, object, Scalar(0, 255, 0));
57
58                ss <59                String conf(ss.str());
60                String label = "Face: " + conf;
61                int baseLine = 0;
62                Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
63                rectangle(frame, Rect(Point(xLeftBottom, yLeftBottom - labelSize.height),
64                    Size(labelSize.width, labelSize.height + baseLine)),
65                    Scalar(255, 255, 255), FILLED);
66                putText(frame, label, Point(xLeftBottom, yLeftBottom),
67                    FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 0, 0));
68            }
69        }
70        float fps = getTickFrequency() / (getTickCount() - start);
71        ss.str("");
72        ss <"FPS: " <" ; inference time: " <" ms";
73        putText(frame, ss.str(), Point(20, 20), 0, 0.75, Scalar(0, 0, 255), 2, 8);
74        imshow("dnn_face_detection", frame);
75        if (waitKey(1) >= 0) break;
76    }
77    waitKey(0);
78    return 0;
79}

运行效果如下:

06c2b638fe8db359264a2fc447623668.png

Github地址

https://github.com/ShiqiYu/libfacedetection

天下难事,必作于易

天下大事,必作于细

 推荐阅读 

OpenCV4系统化学习路线图-视频版本!

OpenCV单应性矩阵发现参数估算方法详解

单应性矩阵应用-基于特征的图像拼接

OpenCV图像拼接改进算法之完美拼接

OpenCV | 二值图像分析的技巧都在这里

OpenCV二值图像分析之形态学应用技巧

图像色彩空间与应用转换

五分钟学会C++高效图表绘制神器调用

没想到图像直方图有这么多应用场景

基于灰度共生矩阵(GLCM)的图像纹理分析与提取

OpenCV中一个最容易搞错的形态学操作

OpenCV实现皮肤表面粗糙度3D显示

解密 | OpenCV加载图像大小是有限制的 ?

362c957d0b3c2e84b0baec4b08284484.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值