Face tracking with dlib?

I’ve been playing around with Kyle’s ofxFaceTracker addon and really like what it’s capable of, but there are a lot of faces that don’t register (for instance: beards).

I was talking with Zach about this and he recommended checking out dlib’s face tracking capability. A quick write-up on that one here:

Anyone out there have experience using the dlib face tracking with oF? Or even just general gotchas about dlib+oF? I’m tempted to dive in but my C++ skills are not that advanced so feeling a bit intimidated.

hey andy! I can give you a hand on this. let me take a look and I’ll let you know.
best!

cool, thanks @roymacdonald!

regarding what I told you about, please ping me in a week, I should have something to share… (it uses dlib to find the faces via HoG, but the tracking is a separate library). It’s a very large thing at the moment since it uses a ton of compiled libs / dylibs / etc and it kind of unwieldy / hard to share, I need to clean it up and find a way to put it online… probably takes me a week (or two) since I am traveling.

Ah ok, will do! I have the stuff you sent me a while ago but haven’t gotten anywhere with it :slight_smile:

hey @andydayton, I have it running, yet it runs absurdly slow. I’m still checking what’s going on.
I can push the project to github so you can fiddle with it. I’ll let you know once done.

@roymacdonald ok cool, thanks!

Hey @andydayton
take a look at this

The tricky part with DLib is to add the correct includes. But once you figure it out it is very straight forwards.
In this example we are not opening new windows, although it might complain if you dont have xQuartz installed.

Let me know how it goes.

BTW, I just started an addon for using DLib inside OF projects, inspired in the way that ofxCV deals with different data types, wrappers, etc. I should be pushing it to github anytime soon.

Best

1 Like

this sounds very exciting.
thanks for uploading the project.

it compiles fine on OS X 10.10.2 and OF 0.9.0.
but i get this error when trying to run it:

dyld: Library not loaded: ./libfmodex.dylib Referenced from: /Applications/of_v0.9.0_osx_release/apps/faceDLib/DLibTest/bin/DLibTest.app/Contents/MacOS/DLibTest Reason: image not found

i checked and libfmodex.dylib is inside the contents/frameworks/

thanks for your help

Thanks @roymacdonald!

I’m getting the same error, I’ll spend some time with it to see if I can see what’s going on…

@andydayton @stephanschulz Ohh that’s odd. I’m using osx 10.9.5 and OF from github, pulled recently.
by looking at that error message I’d say that the libfmodex.dylib should be in the same directory as the executable, hence DLibTest.app/Contents/MacOS/
move try moving the fmodex file so it is in the same folder as the executable.

If not, you can try making a new project and add the dlib stuff. It´s actually quite easy, you just need to add the path to the dlib folder (this path must be to the folder containing the dlib folder, not the dlib folder itself). add it to the “user include search path”. take a look to my project to get the idea.
If you want to avoid the gui and windowing part of dlib you need to add #define DLIB_NO_GUI_SUPPORT
to the dlib/all/source.cpp file. also comment out from the ofApp.h file.

//#include "dlib/image_processing/render_face_detections.h"
//#include "dlib/gui_widgets.h"

If you actually want the dlib gui and windowing you need to add the path to the X11 stuff.
Make sure that you add to your project the dlib/all/sources.cpp file.
I think that that is all. Let me know how it goes.

@stephanschulz I was able to get it up and running by updating the project build settings. In Project Settings -> Build Phases -> Run Script I found this line in the shell script:

install_name_tool -change @executable_path/libfmodex.dylib @executable_path/../Frameworks/libfmodex.dylib "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME\";

And replaced @executable_path/libfmodex.dylib with ./libfmodex.dylib. (Not sure how it got that way but this is what it’s set to in the 0.9.0 emptyExample project).

This article explains a little bit about what install_name_tool is doing.

ALSO I ran into a runtime error once I resolved that issue giving me an EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) error thrown in one of the dlib source files.

I you run into this, I fixed it by going to Project Settings -> Build Settings -> “APPLE LLVM 6.1 - Code Generation” and changed the value of “Enable Additional Vector Extensions” from “AVX” to “Platform default”.

1 Like

Thanks @andydayton!
This is the real fix for what I was commenting before, instead of moving libfmodex
It is weird though.

The vector extension set to AVX is recomended by dlib in order to make the app run faster.

Best!

Worked for me aswell, thanks a lot! One remark from me: you have to select target from “project/target” selector. So not Project settings but Target setting

great i got it working with the advice from @andydayton

also to get the face features to be drawn and not just the bounding box i had to copy shape_predictor_68_face_landmarks.dat from the lib folder in to the bin/data folder

Thanks @stephanschulz for letting me know that. I’ll make all the fixes mentioned here later.
When I was doing this test I started a sort of addon for dlib very much in the style of ofxCv. but left it aside. Is this something worth working on? what do you guys think?

best!

oh certainly, a ofxDLib would be great.
i’m right now pulling out the left and right eye positions.
but a proper addon would make the code much cleaner.

also. looks like dlib is great at other things like pedestrian/object tracking.
would be nice to expose that too :slightly_smiling:

Yep, it has several other handy stuff, but it is quite big. It also has machine learning. ofxLearn implements it.

Was anyone lucky to make this work at a reasonable speed? I think I get 1fps most… and compiling settings (vector extension) do not help.

OF 9.2.0
OSX 10.11.3 (10.11 SDK)

this runs super fast on my macbook pro 2.8 GHz Intel Core i7 16GB RAM

i had to install X11 for it to work at all. maybe that’s why you get such a frame drop?