Dlib is C++ library for machine learning and deep learning. Being it a header only library and we can’t compile it to shared library directly, it is impossible to expose it to java directly.
Many dlib ports to many languages are exist but for Java SE I don’t see any of them works well. I started Jdlib by exposing the most dlib famous examples face HOG detector, facial landmarks, face embedding models.
Even there is a precompiled package on center maven central repository for MacOSX and linux binaries, I recommend to compile it manually as follow.
- Clone project
$ git clone https://github.com/tahaemara/jdlib.git
- Compile JNI/C++ code
$ cd jdlib/jni
$ mkdir build
$ cd build
$ cmake ..
- Compile Java package via maven:
$ cd ../../Jdlib
$ mvn package
After that you will have the JAR file including the binaries for your platform inside Jdlib/target. You can use it inside your project after adding it manually using you IDE. For example Netbeans, In the projects window, right-click the Libraries node for the your project and then click on "Add JAR/Folder...". Then locate the jdlib jar and select it.
Or simply create a maven project and install Jdlib jar manually in your local maven center.
Compiling and running examples
- To run examples, we need to download the needed model for facial landmarks and face embedding extraction and save them to examples folder and uncompress them.
$ cd examples
$ wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
$ wget http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2
$ bzip2 -dk shape_predictor_68_face_landmarks.dat.bz2
$ bzip2 -dk dlib_face_recognition_resnet_model_v1.dat.bz2
- Change Diectory to an example folder such as faces_clustering:
- Build the example via maven
- Run the example
java -jar target/JdlibExamples-1.0.0-jar-with-dependencies.jar