26

I am currently learning OpenCV API with Python and its all good. I am making decent progress. Part of it comes from Python syntax's simplicity as against using it with C++ which I haven't attempted yet. I have come to realize that I have to get dirty with C++ bindings for OpenCV at some point if I intend to do anything production quality.

Just recently I came across dlib which also claims to do all the things OpenCV does and more. Its written in C++ and offers Python API too (surprise). Can anybody vouch for dlib based on their own implementation experience?

frogatto
  • 28,539
  • 11
  • 83
  • 129
ultrasounder
  • 585
  • 1
  • 7
  • 16
  • 1
    I've used opencv extensively for image processing and hadn't heard of dlib. dlib looks like it has far more than just image processing (which you may or may not want) and also doesn't look as fully-featured as opencv. Also, opencv has many optimizations on many algorithms which don't seem to be present in dlib – kmdreko May 13 '16 at 16:38
  • 7
    OpenCV - image processing library. Dlib - machine learning library. They are different and solving different tasks. Some projects need both of them – Evgeniy May 14 '16 at 12:13
  • Just a note: if you are compiling OpenCV from source you can add a huge amount of machine learning stuff to it. – rbaleksandar Oct 21 '16 at 20:25
  • When it comes to identifying faces, I did test `OpenCV` in identifying faces from images of decent resolution and I seem to be getting false positives over a small sample size of images (using all 4 available face recognition Haar Cascade xmls). I'm about to test `dlib` next as it should be better in recognizing faces via machine learning. – Bahamut Feb 05 '18 at 05:14
  • You didn't say what kind of project you are working on, what are your goals and what kind of limitations you are facing. As it is there is no way to recommend you anything, because both libraries have different intended usage. – slawekwin Oct 23 '18 at 10:25
  • Use both. DLib even has functionality to work with OpenCV's image format cv::Mat. – nada Aug 06 '19 at 19:35
  • In addition to Vikas' answer and blog, check out https://towardsdatascience.com/face-detection-models-which-to-use-and-why-d263e82c302c – rinogo Apr 12 '21 at 16:03

1 Answers1

38

I have used both OpenCV and dlib extensively for face detection and face recognition and dlib is much accurate as compared to OpenCV Haar based face detector. ( Note that OpenCV now has a DNN module where we get Deep Learning based Face Detector and Face Recognizer models. )

I'm in the middle of comparing the OpenCV-DNN vs Dlib for face detection / recognition. Will post the results once I'm done with it.

There are many useful functions available in dlib, but I prefer OpenCV for any other CV tasks.

EDIT : As promised, I have made a detailed comparison of OpenCV vs Dlib Face Detection methods.

Here is my conclusion :

General Case

In most applications, we won’t know the size of the face in the image before-hand. Thus, it is better to use OpenCV – DNN method as it is pretty fast and very accurate, even for small sized faces. It also detects faces at various angles. We recommend to use OpenCV-DNN in most

For medium to large image sizes

Dlib HoG is the fastest method on CPU. But it does not detect small sized faces ( < 70x70 ). So, if you know that your application will not be dealing with very small sized faces ( for example a selfie app ), then HoG based Face detector is a better option. Also, If you can use a GPU, then MMOD face detector is the best option as it is very fast on GPU and also provides detection at various angles.

For more details, you can have a look at this blog

Vikas Gupta
  • 570
  • 5
  • 7
  • Gone through your blog. That was very detailed and nicely articulated blog ! .. The article mainly talks about face detection, I am more interested in comparison for face recognition... do you have any data /opinion on it or any such article? – Milind Thakkar May 25 '20 at 12:58