Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Comparative Analysis of face Detection between OpenCV and Dlib

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, Xiaobian will bring you a comparative analysis of how to perform OpenCV and Dlib face detection. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.

Face detection is one of the most typical applications of computer vision, and the early OpenCV logo is a schematic diagram of Haar face detection.

Many people's first OpenCV learning goal is to run through Haar cascade face detection, Dlib library began to be popular in the industry largely because its HOG-SVM face detection is better than OpenCV Haar, and in recent years OpenCV and Dlib have included deep learning-based face detection algorithm implementation.

Haar-Cascade,HOG-SVM and Deep Learning represent the three eras of face detection and even object detection.

Yesterday, Dr. Vikas Gupta, blogger of Learn OpenCV, published an article comparing the implementation of four face detection algorithms in OpenCV and Dlib, including C++/Python code examples, and quantifying accuracy and speed.

1. OpenCV Haar Cascade Face Detection

The algorithm needs no elaboration.

Code example:

advantages

1) can work almost in real time on the CPU;

2) simple structure;

3) It can detect faces of different proportions.

disadvantages

1) There will be a large number of cases where non-faces are predicted as faces;

2) Not applicable to non-frontal face images;

3) No resistance to occlusion.

2. OpenCV DNN Face Detection

Introduced since OpenCV3.3, the algorithm comes from SSD: Single Shot MultiBox Detector (https://arxiv.org/abs/1512.02325). ResNet-10 is used as the backbone network.

OpenCV provides two models:

1) 16-bit floating point version of the original Caffe implementation (5.4MB);

2) 8-bit quantized version of TensorFlow implementation (2.7MB).

Vikas Gupta's code contains both models.

Model loading code example:

Example of detection test code:

advantages

1) It is the most accurate of these four methods;

2) It can run in real time on CPU;

3) Suitable for different face orientations: up, down, left, right, side, etc.

4) can still work even under severe occlusion;

5) It can detect faces of various scales.

disadvantages

The author thinks there are no major shortcomings ^_^

(52CV Jun dare not mention the shortcomings, but think it is definitely a pity that you cannot use NVIDIA GPU)

3. Dlib HoG Face Detection

Code example:

advantages

1) The fastest method on CPU;

2) for frontal and slightly non-frontal faces;

3) the model is small compared to the other three;

4) It can still work under small occlusion.

disadvantages

1) Small faces cannot be detected because the smallest face size of its training data is 80×80, but users can train their own detectors with face data of smaller size;

2) Bounding boxes often exclude part of the forehead or even part of the chin;

3) does not work well under severe occlusion;

4) Does not apply to sides and extreme non-fronts, such as looking down or up.

4. Dlib CNN Face Detection

The algorithm comes from Max-Margin Object Detection (https://arxiv.org/abs/1502.00046).

Code example:

advantages

1) Suitable for different face orientations;

2) robust to occlusion;

3) Works very fast on GPUs;

4) Very simple training process.

disadvantages

1) CPU speed is slow;

2) It cannot detect small faces because the smallest face size of its training data is 80×80, but users can train their own detectors with smaller face data of smaller size;

3) Face bounding box is even smaller than DLib HoG face detector.

5. Accuracy Comparison of Four Methods

The author evaluates the accuracy of four face detection algorithms in FDDB database, and the results are as follows:

It can be seen that the two methods of Dlib are not very good. The author found that the face bounding box of the data set used for Dlib training is small, which leads to unfair evaluation according to FDDB criteria.

In addition, Dlib's inability to detect small faces also lowered the score.

6. speed is relatively

Software and hardware environment:

Processor : Intel Core i7 6850K - 6 Core

RAM : 32 GB

GPU : NVIDIA GTX 1080 Ti with 11 GB RAM

OS : Linux 16.04 LTS

Programming Language : Python

Image size 300*300, test results are as follows:

It can be seen that all the other methods except MMOD achieve real-time, and GPU computation of MMOD method is the fastest.

7. Examples of detection results in different situations

7.1 cross-scale detection

7.2 non-frontal face

7.3 occlusion

8 Summary Recommendations

How to choose face detection algorithm in application? The authors suggest that OpenCV DNN and Dlib HOG methods should be tried first before making a decision.

normal circumstances

In most applications, we have no way of knowing the size of a face in an image. Therefore, it is best to use the OpenCV-DNN method because it is very fast and accurate, even for small size faces. It can also detect faces from various angles. So OpenCV-DNN is the first choice.

Medium to large size images

Dlib HOG is the fastest method on the CPU. But it can't detect small faces (

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report