Skip to content

Instantly share code, notes, and snippets.

@kod3r
Forked from giacomoran/dlib_opencv_android.md
Created July 16, 2017 01:23
Show Gist options
  • Save kod3r/119b2374967d10239205219e409ef329 to your computer and use it in GitHub Desktop.
Save kod3r/119b2374967d10239205219e409ef329 to your computer and use it in GitHub Desktop.
How to create an Android Studio project with OpenCV and dlib.

dlib and OpenCV in Android app

  • Create project and get OpenCV working

Follow the instructions on the following link. NOTICE: When creating the new project, on the C++ Support tab, select C++11 from the dropdown. Link: https://github.com/leadrien/opencv_native_androidstudio#how-to-create-the-native-opencv-project-from-scratch

  • Download correct version of dlib

The most recent version of dlib seems to have problems on Android, download version 19.1.

  • Unzip dlib in project folder

Uzip the downloaded dlib zip file to your-project-name/app. You should now have a dlib-19.1 folder there.

  • Edit CMakeList.txt

Add after the line set_target_properties( lib_opencv .....:

set(DLIB_DIR dlib-19.1)
include_directories(${DLIB_DIR} include)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

Add inside add_library, after src/main/cpp/native-lib.cpp:

${DLIB_DIR}//dlib/threads/threads_kernel_shared.cpp
${DLIB_DIR}/dlib/entropy_decoder/entropy_decoder_kernel_2.cpp
${DLIB_DIR}/dlib/base64/base64_kernel_1.cpp
${DLIB_DIR}/dlib/threads/threads_kernel_1.cpp
${DLIB_DIR}/dlib/threads/threads_kernel_2.cpp
  • You should be good to go!

Notice that dlib will be slow if you compile in Debug mode, I suggest compiling in Release mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment