4/24/2016

Facial Landmarks implemented by DLib on Android

  In the past, Google had provided Vision API to detect facial landmark. However, if you would like to use that, it requires Android Play Services SDK level 26 or greater. Besides, the number of landmarks might not be enough for you. Luckily, after the release of dlib, v18.10, it includes a number of new minor features.  The main addition in that release is an implementation of an excellent paper from this year's Computer Vision and Pattern Recognition Conference:
One Millisecond Face Alignment with an Ensemble of Regression Trees by Vahid Kazemi and Josephine Sullivan
The implementation of facial landmark extraction is fast enough, and it has 68 landmarks. Therefore, I spent a while to implement this feature to Android platform. 

Hope it can be helpful to Android developers. If it is helpful to you, please give me stars on my Github repositories, dlib-android and dlib-android-app

9 comments:

  1. Can you give me basic the steps regarding how to integrate dlib & openCV in android studio. I am new to this field.

    ReplyDelete
    Replies
    1. Hi @Binod Deka,
      I am willing to show you the details, however, I am pretty busy with other stuff.

      My suggestion is that you should setup an env first like install Andriod stuudio and ndk.

      Then try to build dlib-android

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Thanks for the quick reply. I have already configured Android Studio and able to work with fews example of open CV. My problem is that I need to integrate dlib with android and opencv. Can you show be simple example using dlib & opencv in android (Steps to configure dlib like various flags) like face detection (need to use dlib).

    ReplyDelete
    Replies
    1. Hi Binod Deka,
      Could you take a look at https://github.com/tzutalin/dlib-android?
      After going throught reameme or code, you can raise your problems and send a qeustion to my email

      Delete
  4. Another question, Suppose I have passed the frame from java to c++ (NDK) and the code at cpp side is
    jbyte * pNV21FrameData = env->GetByteArrayElements(NV21FrameData, 0);
    Now am trying to put a marker on the image using the following code
    cv::Mat frame = cv::Mat(height,width,CV_16UC1,(unsigned char *) pNV21FrameData,0);
    putText(frame,"Testing for simple marker", Point(30,30), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0,255,0),2);
    But it is not working. Kindly help me.


    ReplyDelete
  5. I have tried to implement dlib in the android studio. Android.mk file content for linking with dlib and opencv is
    .............
    LOCAL_C_INCLUDES +=/home/sysadmin/Android/opencv-3.1.0/modules/imgproc/include
    LOCAL_C_INCLUDES +=/home/sysadmin/Android/opencv-3.1.0/modules/core/include
    LOCAL_C_INCLUDES +=/dlib/dlib/all/source.cpp
    .................
    LOCAL_LDLIBS := -lm -llog -ldl -lz
    LOCAL_CPPFLAGS += -fexceptions -frtti -std=c++11
    ..................................................

    But when I tried to ndk-build, the following error has shown which I am not able to solve. Kindly help to solve the problem# ERROR was :

    /home/sysadmin/AndroidStudioProjects/MyRealTimeImageProcessing-master/app/src/main/jni/dlib/dlib/image_processing/../svm/../threads/threads_kernel_shared.h:46: error: undefined reference to 'USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_'
    collect2: error: ld returned 1 exit status
    make: *** [/home/sysadmin/AndroidStudioProjects/MyRealTimeImageProcessing-master/app/src/main/obj/local/armeabi-v7a/libImageProcessing.so] Error 1
    make: Leaving directory `/home/sysadmin/AndroidStudioProjects/MyRealTimeImageProcessing-master/app/src/main/jni'

    ReplyDelete
  6. Hai TzuTaLin,
    I've tried to implement your code with updated gradle but it shows invalid code length given can you plaese give me a fix for that, already i've raised an issue in github issue no is 47

    ReplyDelete
  7. Anonymous3/18/2020

    Hi,

    I have setup this project, now I just want to know, how to setup front camera and also i want only single screen with face recognition not on popup window.

    ReplyDelete