dlib vs opencv which one to use when

21,223

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

Share:
21,223
ultrasounder
Author by

ultrasounder

An EE by day time and an ios enthusiast by the night. Loves to play the violin and tinker with audio. @audioholyx

Updated on July 09, 2022

Comments

  • ultrasounder
    ultrasounder almost 2 years

    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?

    • kmdreko
      kmdreko about 8 years
      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
    • Evgeniy
      Evgeniy about 8 years
      OpenCV - image processing library. Dlib - machine learning library. They are different and solving different tasks. Some projects need both of them
    • rbaleksandar
      rbaleksandar over 7 years
      Just a note: if you are compiling OpenCV from source you can add a huge amount of machine learning stuff to it.
    • Bahamut
      Bahamut over 6 years
      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.
    • slawekwin
      slawekwin over 5 years
      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.
    • nada
      nada almost 5 years
      Use both. DLib even has functionality to work with OpenCV's image format cv::Mat.
    • TommyAutoMagically
      TommyAutoMagically about 3 years
      In addition to Vikas' answer and blog, check out towardsdatascience.com/…
  • Milind Thakkar
    Milind Thakkar almost 4 years
    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?