1

According to Davis Kings answer in that question: Create a shared library for dlib, I created shared libraries for Dlib and linked them to a program that uses the Dlib Face detection to detect faces in the pictures of a camera, using these commands:

cd dlib-19.0/dlib
mkdir build
cd build
cmake ..
make
sudo make install

And the -ldlib option.

I can compile and execute the program, however the face detection is extremely slow.

I tried the same program on Windows with Visual Studio 2013. When I used the Debug Mode, the face detection was extremely slow as well, but was running pretty well in Release mode. So I thought, that the shared libraries might be in Debug mode as well and tried to force them in Release mode with these commands:

cd examples
mkdir build
cd build
cmake ..
cmake --build . --config Release 
sudo make install

But the result was the same as before.

Does anybody have an Idea, what the reason could be, that it is that slow?

Thank you for your help.

Community
  • 1
  • 1
elHam
  • 31
  • 5
  • Were there any warnings in the compilation e.g. it complaining about no `BLAS` library being found? It might help. You could also try `cmake CMAKE_CXX_FLAGS=-mavx ..`, which will add the `-mavx` option to compilation - it may give an optimization boost to the build. TBH, though you would need to compare the resulting compiled code for the library to determine the reason for the performance difference – Anya Shenanigans Aug 10 '16 at 21:15
  • All face detection code is header-based. It does not depend on using shared/static libraries (but they are needed for loading face detector model). The problem is somewhere else. Please tell us more details about this performance problems: CPU model/speed, image resolution, detection time in both cases – Evgeniy Aug 12 '16 at 08:46

1 Answers1

5

I want to share my experience. ^^

You should use -O3 and -mavx option for speed up.

(-O3 complie option is critical for speed up)

I created a shared library for dlib as mentioned above.

and compiled web_face_pose_ex.cpp with dlib shared library.

OS : Ubuntu 14.04

dlib version : 19.0.0

Input Resolution : 640 x 480 webcam (Logitech C920)

  1. I exported below path.

    $ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
    $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    
  2. Without -O3 option : time : 2674.25 ms

    g++ -o my_web_face webcam_face_pose_ex.cpp -lpthread -lX11 -lblas -llapack `pkg-config --cflags --libs opencv dlib-1`
    
  3. With -O3 option : time : 55 ms

    g++ -o -O3 my_web_face webcam_face_pose_ex.cpp -lpthread -lX11 -lblas -llapack `pkg-config --cflags --libs opencv dlib-1`
    
  4. With both -O3 & -mavx (use AVX) : time : 45 ms

    g++ -o -O3 -mavx my_web_face webcam_face_pose_ex.cpp -lpthread -lX11 -lblas -llapack `pkg-config --cflags --libs opencv dlib-1`
    
runhani
  • 5,919
  • 1
  • 9
  • 6
  • Thanks for this answer! I did much searching before I came across this and was just convinced that dlib's face detection was ridiculously slow. The key point is that, since it is contained fully in header files, the optimization of your program is what matters here! (it is also surprising that the difference between the debug build and the release build would be many seconds vs a few ms). – logidelic Jun 09 '17 at 14:31