tzutalin / dlib-android Goto Github PK
View Code? Open in Web Editor NEW:dragon: Port dlib to Android
License: MIT License
:dragon: Port dlib to Android
License: MIT License
Hi, I am wondering if the facial landmark detection example from dlib works in Android?
Thank you.
Hi There,
I am using Camera API (Old Camera API). Using this old api i am getting yuv raw image data and i am converting that data into the ARGB format and when i pass this bitmap to dlib library it says no face found.
Can anyone help me in which format i need to pass the data means ARGB is fine or any other image convertions i need to do?.
It's possible to export the coordinates of the facial landmarks on a file? Thanks.
有更具体的说明吗?
以前没有做过Android. 现在出了CMake。
Successfully built and replaced all .SO files on jniLibs folder.
Android.mk and Application.mk without changes.
Testing on Dlib Andorid App: Without any gradle version or library updates.
Samsung Galaxy S4 (I9500) API22: Library Loaded with Success.
LG Nexus 5 API 23: UnsatisfiedLinkError
E/dlib: library not found.
W/System.err: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__aeabi_memcpy"
W/System.err: at java.lang.Runtime.loadLibrary(Runtime.java:372)
W/System.err: at java.lang.System.loadLibrary(System.java:1076)
W/System.err: at com.tzutalin.dlib.FaceDet.<clinit>(FaceDet.java:29)
Also tested compiling with different NDK versions: r14b and r13b. Still crashes.
Thanks.
Hi, I'm following your instructions, but when I build I get:
ABI:armeabi-v7a
Traceback (most recent call last):
File "build_push.py", line 104, in <module>
build(args.jobs)
File "build_push.py", line 37, in build
subprocess.call(['ndk-build', '-j', str(jobs)])
File "/usr/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
It happens also when building it for another project, and not only to test.
I've tried to build it with ndk-build but it says it can't find opencv in third-party. I've tried C++ and android versions but none of them works.
Heya,
I am making an Android app, with similar functionality as the demo app in terms of dlib calls. I started from a new project, using the Gradle dependency. Everything works fine including JNI calls to DetFace etc. but I also want to use the JNI functions of the ImageUtils class and am not sure how I can include these? Every time I run them, I get an Implementation not found error. It seems the binaries are not inside the libpeople_det.so, right? Where are they then? I would expect to see a .so file somewhere, and a System.loadLibrary in ImageUtils, but I do not find either of them. Could anyone help me out? Thanks a lot.
Hi,
Is there any way that JNI take a bitmap or the byte array of the bitmap and convert it to dlib::array2d
without openCV?
The default "libpeople_det.so" included in the repo works. But when I build it locally on my machine I end up with UnsatisfiedLinkError.
OS: mac OS sierra
ndk version: android-ndk-r12b
10-21 17:28:33.561 25557-25679/com.tzutalin.dlibtest E/art: No implementation found for void com.tzutalin.dlibtest.ImageUtils.convertYUV420ToARGB8888(byte[], byte[], byte[], int[], int, int, int, int, int, boolean) (tried Java_com_tzutalin_dlibtest_ImageUtils_convertYUV420ToARGB8888 and Java_com_tzutalin_dlibtest_ImageUtils_convertYUV420ToARGB8888___3B_3B_3B_3IIIIIIZ)
10-21 17:28:33.571 25557-25679/com.tzutalin.dlibtest E/AndroidRuntime: FATAL EXCEPTION: ImageListener
Process: com.tzutalin.dlibtest, PID: 25557
java.lang.UnsatisfiedLinkError: No implementation found for void com.tzutalin.dlibtest.ImageUtils.convertYUV420ToARGB8888(byte[], byte[], byte[], int[], int, int, int, int, int, boolean) (tried Java_com_tzutalin_dlibtest_ImageUtils_convertYUV420ToARGB8888 and Java_com_tzutalin_dlibtest_ImageUtils_convertYUV420ToARGB8888___3B_3B_3B_3IIIIIIZ)
at com.tzutalin.dlibtest.ImageUtils.convertYUV420ToARGB8888(Native Method)
at com.tzutalin.dlibtest.OnGetImageListener.onImageAvailable(OnGetImageListener.java:193)
at android.media.ImageReader$ListenerHandler.handleMessage(ImageReader.java:648)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
Another log:
10-21 18:33:59.178 20989-21373/com.tzutalin.dlibtest E/art: No implementation found for int com.tzutalin.dlib.PeopleDet.jniOpencvHOGDetect(java.lang.String) (tried Java_com_tzutalin_dlib_PeopleDet_jniOpencvHOGDetect and Java_com_tzutalin_dlib_PeopleDet_jniOpencvHOGDetect__Ljava_lang_String_2)
10-21 18:33:59.183 20989-21373/com.tzutalin.dlibtest E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
Process: com.tzutalin.dlibtest, PID: 20989
java.lang.UnsatisfiedLinkError: No implementation found for int com.tzutalin.dlib.PeopleDet.jniOpencvHOGDetect(java.lang.String) (tried Java_com_tzutalin_dlib_PeopleDet_jniOpencvHOGDetect and Java_com_tzutalin_dlib_PeopleDet_jniOpencvHOGDetect__Ljava_lang_String_2)
at com.tzutalin.dlib.PeopleDet.jniOpencvHOGDetect(Native Method)
at com.tzutalin.dlib.PeopleDet.detPerson(PeopleDet.java:56)
at com.tzutalin.dlibtest.MainActivity.runDetectAsync(MainActivity.java:236)
at com.tzutalin.dlibtest.MainActivity_.access$301(MainActivity_.java:32)
at com.tzutalin.dlibtest.MainActivity_$6.execute(MainActivity_.java:156)
at org.androidannotations.api.BackgroundExecutor$Task.run(BackgroundExecutor.java:405)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Steps to reproduce:
Any pointers on where I should look next? ( I haven't changed anything in the repo. Just ran an ndk-build after cloning the repo.)
Hi,
I have successfully compile dlib library in windows 7. Now how can I use "TestSelectiveSearch" and "face_landmark_detection_ex" files in android which are in "Tests" folder and build with other files in "android-dlib" static library.
Thanks and regards
Nadeem Asif
Hi, I'm trying (with no luck until now) to build jnilib_ex, I think there's a typo in https://github.com/tzutalin/dlib-android/blob/master/jni/Android.mk#L7, shouldn't it be LOCAL_C_INCLUDES
?
any plan to optimize the speed of scan_fhog_pyrimaid using OpenMP like https://github.com/TadasBaltrusaitis/CLM-framework/blob/master/lib/3rdParty/dlib/include/dlib/image_processing/scan_fhog_pyramid.h
Hi, I'm using your app for checking face detection time.
I'm revising dlib library code, compile it manually ndk-build -j2
.
when I compiled it, and cp -r libs/* ~~jniLibs/
successfully builded, but when I turn on the cam, it crashes.
how did you compile with your example(dlib-android-app) .so file?
can you give any hints?
thank you for your contribution. :)
I need to get faster camera preview with face landmarks, it normally take 200 ms to perform the operation on each video frame, can anything should be done for faster face landmarking.
thank you
How to enable libpng support, I am getting runtime exception:
You must #define DLIB_PNG_SUPPORT and link to libpng to read PNG files.
Do this by following the instructions at http://dlib.net/compile.html.
Note that you must cause DLIB_PNG_SUPPORT to be defined for your entire project.
So don't #define it in one file. Instead, use a compiler switch like -DDLIB_PNG_SUPPORT
so it takes effect for your entire application." failed
did all as described
but face landmark failed like below in "python build_push.py --test "
Test face landmark
3969 KB/s (327422 bytes in 0.080s)
6394 KB/s (99693937 bytes in 15.225s)
5796 KB/s (1492988 bytes in 0.251s)
----Execute /data/local/tmp/face_lanmark
exception thrown!
error occurred in compress_stream_kernel_1::decompress
do I miss something? how can I fix it ?
In my demo project, invoke get_frontal_face_detector(); , when run, i will get the following error:
terminate called after throwing an instance of 'std::ios_base::failure'
what(): error occurred in compress_stream_kernel_1::decompress
I've checked the source code, in dlib/compress_stream/compress_stream_kernel_1.h,
if (out.sputc(static_cast<char>(symbol)) != static_cast<int>(symbol))
{
throw std::ios::failure("error occurred in compress_stream_kernel_1::decompress");
}
I don't know the purpose of this code : out.sputc(static_cast(symbol)), sputc should change char to int, but when symbol equal or greater than 128, sputc will get a negtive signed char value. Then the demo running failed. The cross compiler is: arm-linux-gnueabi-gcc-4.7.1
But everything works fine in Ubuntu 14.04 x64, GCC 4.8.
How to fix it?
Hello,i notice that you add facial landmark into your project and it is not finished.I wonder that when can facial landmark available?
Thanks for your contribution.
I am currently trying to use dlib-android (rev d6e48c1) after building it via the default build command:
python build_push.py --android_project ../dlib-android-app/dlib/src/main/jniLibs/
(dlib-android-app
is dlib-android-app at d6e48c1)
When not building dlib-android manually, the app behaves as expected. However, the app behaves as following after performing a (successful) build as shown above:
Do you have any idea what could be the difference between your original build and my local one?
The original dlib board has an (unresolved) thread regarding this issue that relates to Android and possibly to dlib-android: https://sourceforge.net/p/dclib/discussion/442518/thread/b3ef5401/
Thanks a lot!
Crash log
Full log: 20160713_dlib-android_crash.txt
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/trltexx/trlte:5.1.1/LMY47X/N910FXXS1COK2:user/release-keys'
Revision: '12'
ABI: 'arm'
pid: 4292, tid: 4747, name: InferenceThread >>> com.tzutalin.dlibtest <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
r0 00000000 r1 0000128b r2 00000006 r3 00000000
r4 9c87bdb8 r5 00000006 r6 00000016 r7 0000010c
r8 b4b4bb00 r9 a0349d30 sl 12c033d0 fp 9c878bb0
ip 0000128b sp 9c8789f0 lr b6e0771d pc b6e2a2dc cpsr 600f0010
backtrace:
#00 pc 000372dc /system/lib/libc.so (tgkill+12)
#01 pc 00014719 /system/lib/libc.so (pthread_kill+52)
#02 pc 00015337 /system/lib/libc.so (raise+10)
#03 pc 00011bd1 /system/lib/libc.so (__libc_android_abort+36)
#04 pc 00010044 /system/lib/libc.so (abort+4)
#05 pc 0046a103 /data/app/com.tzutalin.dlibtest-1/lib/arm/libpeople_det.so (__gnu_cxx::__verbose_terminate_handler()+226)
#06 pc 00433dc9 /data/app/com.tzutalin.dlibtest-1/lib/arm/libpeople_det.so (__cxxabiv1::__terminate(void (*)())+4)
#07 pc 00433e3d /data/app/com.tzutalin.dlibtest-1/lib/arm/libpeople_det.so (std::terminate()+8)
#08 pc 00433f61 /data/app/com.tzutalin.dlibtest-1/lib/arm/libpeople_det.so (__cxa_throw+120)
#09 pc 00150a9c /data/app/com.tzutalin.dlibtest-1/lib/arm/libpeople_det.so (dlib::compress_stream_kernel_1<dlib::entropy_encoder_model_kernel_5<257ul, dlib::entropy_encoder_kernel_2, 200000ul, 4ul>, dlib::entropy_decoder_model_kernel_5<257ul, dlib::entropy_decoder_kernel_2, 200000ul, 4ul>, dlib::crc32>::decompress(std::istream&, std::ostream&) const+544)
#10 pc 00150478 /data/app/com.tzutalin.dlibtest-1/lib/arm/libpeople_det.so (dlib::get_serialized_frontal_faces()+63512)
#11 pc 00140654 /data/app/com.tzutalin.dlibtest-1/lib/arm/libpeople_det.so (dlib::get_frontal_face_detector()+44)
#12 pc 0013544c /data/app/com.tzutalin.dlibtest-1/lib/arm/libpeople_det.so (DLibHOGFaceDetector::det(cv::Mat const&)+236)
#13 pc 000e8d30 /data/app/com.tzutalin.dlibtest-1/lib/arm/libpeople_det.so (Java_com_tzutalin_dlib_PeopleDet_jniBitmapFaceDect+868)
#14 pc 0013c77f /data/dalvik-cache/arm/data@[email protected]@[email protected]
OS used for build
Android device
Hi, It would be a very sweet implementation, if you add a new function that allows input frames for face and landmark detection, in NV21 Image Format, since that's the native image format of all Andorid Camera Preview. Or, maybe allow YUV_420_888 if you only want Camera2 compatibility.
My reason is that I have to read preview frames in NV21 (from Camera1) then convert it to Bitmap then downscale the Bitmap, and send bitmap to detector.
Read preview frames in YUV_420_888 (from Camera2) then convert to NV21, then convert to Bitmap then Downscale the Bitmap, and send bitmap to detector.
That process is not done inside NDK, and you may know it's slow. In order to get a "high FPS" face detection, I have to downscale a lot and almost none faces are detected.
Thanks!
is there a way to execute compute_face_descriptors from https://github.com/davisking/dlib/blob/3e63e0a1b342c7b79e84aa2d1750587e39403922/tools/python/src/face_recognition.cpp
Without rebuilding
// The format of mat should be BGR or Gray
// If converting 4 channels to 3 channls because the format could be BGRA or
// ARGB
virtual inline int det(const cv::Mat& image) {
if (image.empty())
return 0;
LOG(INFO) << "com_tzutalin_dlib_PeopleDet go to det(mat)";
if (image.channels() == 1) {
cv::cvtColor(image, image, CV_GRAY2BGR);
}
CHECK(image.channels() == 3);
// TODO : Convert to gray image to speed up detection
// It's unnecessary to use color image for face/landmark detection
dlib::cv_imagedlib::bgr_pixel img(image);
mRets = mFaceDetector(img);
LOG(INFO) << "Dlib HOG face det size : " << mRets.size();
mFaceShapeMap.clear();
// Process shape
if (mRets.size() != 0 && mLandMarkModel.empty() == false) {
for (unsigned long j = 0; j < mRets.size(); ++j) {
dlib::full_object_detection shape = msp(img, mRets[j]);
LOG(INFO) << "face index:" << j
<< "number of parts: " << shape.num_parts();
mFaceShapeMap[j] = shape;
}
}
return mRets.size();
}
Hi, I have got this error on executing following command
ndk build -j 2
TOP Level Path: /opt/dlib/dlib-android
/opt/dlib/dlib-android/third_party/miniglog/Android.mk:5: "Build miniglog.so/miniglog.a"
/opt/dlib/dlib-android/third_party/miniglog/Android.mk:8: /opt/dlib/dlib-android/third_party/miniglog
jni/jni_detections/Android.mk:8: /opt/dlib/dlib-android/third_party/opencv/jni/OpenCV.mk: No such file or directory
"Won't build test's executable file"
make: *** No rule to make target '/opt/dlib/dlib-android/third_party/opencv/jni/OpenCV.mk'. Stop.
dp@dp-Lenovo-G480:/opt/dlib/dlib-android$
Hi again,
I have this code to export the facial landmarks in an external file, but I don't know where I must put it. Initially, I put it in FaceDetTest.java. It compiles but doesn't work.
public void landmarkextract(ArrayList<Point> landmarks) throws IOException { String route = "/sdcard/landmarks.txt"; File lndmrk = new File(route); BufferedWriter bw = new BufferedWriter(new FileWriter(lndmrk)); for(int i=0; i<landmarks.size(); i++){ bw.write(String.valueOf(landmarks.get(i))+"\n"); } bw.close(); }
Thanks.
Edit: Solved! I put it on the MainActivity.
I tried to compile it using NDK-build but received following error:
jni/../dlib\dlib/image_loader/../image_transforms/random_cropper.hjni/../dlib\dlib/image_loader/../image_transforms/random_cropper.h::178178::6767:: error: noerror : member nonamed member'round' namedin 'round'namespace
in 'std'namespace
const unsigned long min_object_height_absolute = std::round(min_object_height*crop_plan.rows);'std'
~~~~~^ const unsigned long min_object_height_absolute = std::round(min_object_height*crop_plan.rows);
~~~~~^
Anyone know how can I fix it?
I add your pre-build .so file in my application project.
When I debugged my application, I got an error message:
A/native: F/jni_primitives.h:113 'detRetClass' Must be non NULL
Is there anything that I forget to add in my project?
The project structure setting:
|--app:
|--|--src:
|--|--|--main
|--|--|--|--jniLibs
|--|--|--|--|--arm64-v8a
|--|--|--|--|--|--.so Files
|--|--|--|--|--armeabi-v7a
|--|--|--|--|--|--.so Files
|--|--|--|--|--x86
|--|--|--|--|--|--.so Files
|--|--|--|--|--x86_64
|--|--|--|--|--|--.so Files
Hello!
I used both this repo and dlib-android-app.
I wonder, how can i change the path where the file shape_predictor_68_face_landmarks.dat
will be saved at?
An other question, i want to create a new project (app) that uses dlib parts, how can i do it?
thank you very much!
When executing envsetup opencv it raises an error that "is not a zip file". Trying to decompress manually with 2 different tools gives me the same problem. (I'm on a mac, never had issues with zip files until this one)
Traceback (most recent call last):
File "./envsetup", line 127, in <module>
main(sys.argv[1:])
File "./envsetup", line 124, in main
sync_submodules()
File "./envsetup", line 119, in sync_submodules
prefix=prebuilt_path, out_prefix=prebuilt_opencv_out)
File "./envsetup", line 97, in downloadPrebuiltOpencv
unzipFile(OPENCV_ARCHIVE)
File "./envsetup", line 22, in unzipFile
zfile = zipfile.ZipFile(filename)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 770, in __init__
self._RealGetContents()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 811, in _RealGetContents
raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file
How can I get a file that can be unzipped?
The dlib android app example uses jniBitmapFaceDect, but I wanted to detect objects instead.
I added a new function (jniBitmapDLibHOGDect) to jni_people_det.cpp. I compiled it by following the instructions, and I got four people_det.so files. I copied them to the android app sample project, but now the library fails to load, throwing this error:
dlopen failed: cannot locate symbol "__aeabi_memcpy" referenced by "/data/app/com.tzutalin.dlibtest-1/lib/arm/libpeople_det.so"
Any ideas what this means, or how to resolve it?
Hi man,
I have a problem when build dlib-android on Ubuntu, pls help. The error is as following:
Android NDK: [x86_64] Modules to build: TestSelectiveSearch face_landmark max_cost_assignment_ex people_det svm_ex svr_ex
rm -f ./libs/arm64-v8a/lib_.so ./libs/armeabi/lib_.so ./libs/armeabi-v7a/lib_.so ./libs/armeabi-v7a-hard/lib_.so ./libs/mips/lib_.so ./libs/mips64/lib_.so ./libs/x86/lib_.so ./libs/x86_64/lib_.so
[armeabi-v7a] Compile++ arm : TestSelectiveSearch <= TestSelectiveSearch.cpp
[armeabi-v7a] Compile++ arm : face_landmark <= threads_kernel_shared.cpp
/home/huynq/Android/android-ndk-r11c/toolchains/llvm/prebuilt/linux-x86/bin/clang++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs-debug/TestSelectiveSearch/TestSelectiveSearch.o.d -gcc-toolchain /home/huynq/Android/android-ndk-r11c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -fno-integrated-as -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-exceptions -fno-rtti -O2 -g -DNDEBUG -fomit-frame-pointer -fstrict-aliasing -O0 -UNDEBUG -fno-omit-frame-pointer -fno-strict-aliasing -mfpu=neon -Ijni/other_daemon_ex/../../third_party/opencv/jni/include -Ijni/other_daemon_ex/../dlib -Ijni/other_daemon_ex/../dlib/all/source.cpp -I/home/huynq/Android/android-ndk-r11c/sources/cxx-stl/gnu-libstdc++/4.9/include -I/home/huynq/Android/android-ndk-r11c/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -I/home/huynq/Android/android-ndk-r11c/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -Ijni/other_daemon_ex -DANDROID -fPIC -DANDROID -fsigned-char -pie -fPIE -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -std=c++11 -frtti -fexceptions -isystem /home/huynq/Android/android-ndk-r11c/platforms/android-8/arch-arm/usr/include -c jni/other_daemon_ex/TestSelectiveSearch.cpp -o ./obj/local/armeabi-v7a/objs-debug/TestSelectiveSearch/TestSelectiveSearch.o
make: /home/huynq/Android/android-ndk-r11c/toolchains/llvm/prebuilt/linux-x86/bin/clang++: Command not found
rm -f ./libs/arm64-v8a/gdbserver ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/armeabi-v7a-hard/gdbserver ./libs/mips/gdbserver ./libs/mips64/gdbserver ./libs/x86/gdbserver ./libs/x86_64/gdbserver
[armeabi-v7a] Compile++ arm : face_landmark <= entropy_decoder_kernel_2.cpp
/home/huynq/Android/android-ndk-r11c/toolchains/llvm/prebuilt/linux-x86/bin/clang++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs-debug/face_landmark//dlib//dlib/threads/threads_kernel_shared.o.d -gcc-toolchain /home/huynq/Android/android-ndk-r11c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -fno-integrated-as -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-exceptions -fno-rtti -O2 -g -DNDEBUG -fomit-frame-pointer -fstrict-aliasing -O0 -UNDEBUG -fno-omit-frame-pointer -fno-strict-aliasing -mfpu=neon -Ijni/other_daemon_ex/../../third_party/opencv/jni/include -Ijni/other_daemon_ex/../dlib -I/home/huynq/Android/android-ndk-r11c/sources/cxx-stl/gnu-libstdc++/4.9/include -I/home/huynq/Android/android-ndk-r11c/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -I/home/huynq/Android/android-ndk-r11c/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -Ijni/other_daemon_ex -DANDROID -fPIC -DANDROID -fsigned-char -pie -fPIE -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -std=c++11 -frtti -fexceptions -isystem /home/huynq/Android/android-ndk-r11c/platforms/android-8/arch-arm/usr/include -c jni/other_daemon_ex/../dlib//dlib/threads/threads_kernel_shared.cpp -o ./obj/local/armeabi-v7a/objs-debug/face_landmark//dlib//dlib/threads/threads_kernel_shared.o
make: /home/huynq/Android/android-ndk-r11c/toolchains/llvm/prebuilt/linux-x86/bin/clang++: Command not found
/home/huynq/Android/android-ndk-r11c/toolchains/llvm/prebuilt/linux-x86/bin/clang++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs-debug/face_landmark//dlib/dlib/entropy_decoder/entropy_decoder_kernel_2.o.d -gcc-toolchain /home/huynq/Android/android-ndk-r11c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -fno-integrated-as -target armv7-none-linux-androideabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-exceptions -fno-rtti -O2 -g -DNDEBUG -fomit-frame-pointer -fstrict-aliasing -O0 -UNDEBUG -fno-omit-frame-pointer -fno-strict-aliasing -mfpu=neon -Ijni/other_daemon_ex/../../third_party/opencv/jni/include -Ijni/other_daemon_ex/../dlib -I/home/huynq/Android/android-ndk-r11c/sources/cxx-stl/gnu-libstdc++/4.9/include -I/home/huynq/Android/android-ndk-r11c/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -I/home/huynq/Android/android-ndk-r11c/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -Ijni/other_daemon_ex -DANDROID -fPIC -DANDROID -fsigned-char -pie -fPIE -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -std=c++11 -frtti -fexceptions -isystem /home/huynq/Android/android-ndk-r11c/platforms/android-8/arch-arm/usr/include -c jni/other_daemon_ex/../dlib/dlib/entropy_decoder/entropy_decoder_kernel_2.cpp -o ./obj/local/armeabi-v7a/objs-debug/face_landmark//dlib/dlib/entropy_decoder/entropy_decoder_kernel_2.o
make: /home/huynq/Android/android-ndk-r11c/toolchains/llvm/prebuilt/linux-x86/bin/clang++: Command not found
make: *** [obj/local/armeabi-v7a/objs-debug/TestSelectiveSearch/TestSelectiveSearch.o] Error 127
make: *** Waiting for unfinished jobs....
rm -f ./libs/arm64-v8a/gdb.setup ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/armeabi-v7a-hard/gdb.setup ./libs/mips/gdb.setup ./libs/mips64/gdb.setup ./libs/x86/gdb.setup ./libs/x86_64/gdb.setup
make: * [obj/local/armeabi-v7a/objs-debug/face_landmark//dlib//dlib/threads/threads_kernel_shared.o] Error 127
make: * [obj/local/armeabi-v7a/objs-debug/face_landmark//dlib/dlib/entropy_decoder/entropy_decoder_kernel_2.o] Error 127
Currently when detection is performed, the code reads the channels of a Mat object as input. But if it is in grayscale (Channels == 1) it is converted again to color:
detector.h
virtual inline int det(cv::Mat& image) {
if(image.empty()) return 0;
if(image.channels() == 1) {
cv::cvtColor(image, image, CV_GRAY2BGR);
} CHECK(image.channels() == 3);
dlib::cv_image<dlib::bgr_pixel> img(image);
mRets = mFaceDetector(img);
return mRets.size();
}
However, the Dlib documentation points out that: "Any built in scalar type may be used as a grayscale pixel type. For example, unsigned char, int, double, etc."
So bgr_pixel type is not the only alternative.
Hi @tzutalin ,
Is there a way to build dlib (only dlib) as a static lib and also get header files?
Hi, i'm trying to compile the library, and get an error:
$ ndk-build
Android NDK: ERROR:jni/jnilib_ex/Android.mk:webp: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that jni/jnilib_ex/../../opencv/jni/../3rdparty/libs/armeabi-v7a/liblibwebp.a exists or that its path is correct
The file is not found anywhere. I can see its part of OpenCV, but i guess it should be added to the readme
Hi,
I really cannot build this using:
As required I insert:
locally in the respective folders. Now, I changed in jni/Application.mk :
APP_PLATFORM := android-19 (from 8 since my app later will have this release as minimum version required)
#APP_STL := gnustl_static
APP_STL := c++_static
I use python build.py command and:
[armeabi-v7a] Compile++ thumb: miniglog <= logging.cc
In file included from jni/jni_detections/jni_pedestrian_det.cpp:14:
In file included from jni/jni_detections/detector.h:14:
In file included from jni/../dlib/dlib/image_processing.h:17:
In file included from jni/../dlib/dlib/image_loader/../image_processing/setup_hashed_features.h:8:
In file included from jni/../dlib/dlib/image_loader/../array2d/../geometry/../image_processing/scan_image_boxes.h:12:
In file included from jni/../dlib/dlib/image_loader/../array2d/../geometry/../image_processing/../image_transforms.h:28:
jni/../dlib/dlib/image_loader/../image_transforms/random_cropper.h:146:67: error: no member named 'round' in namespace 'std'
const unsigned long min_object_height_absolute = std::round(min_object_heightcrop_plan.rows);
~~~~~^
In file included from jni/jni_detections/jni_face_det.cpp:14:
In file included from jni/jni_detections/detector.h:14:
In file included from jni/../dlib/dlib/image_processing.h:17:
In file included from jni/../dlib/dlib/image_loader/../image_processing/setup_hashed_features.h:8:
In file included from jni/../dlib/dlib/image_loader/../array2d/../geometry/../image_processing/scan_image_boxes.h:12:
In file included from jni/../dlib/dlib/image_loader/../array2d/../geometry/../image_processing/../image_transforms.h:28:
jni/../dlib/dlib/image_loader/../image_transforms/random_cropper.h:146:67: error: no member named 'round' in namespace 'std'
const unsigned long min_object_height_absolute = std::round(min_object_heightcrop_plan.rows);
~~~~~^
[arm64-v8a] Compile++ : android_dlib <= jni_imageutils.cpp
[arm64-v8a] Compile++ : android_dlib <= jni_pedestrian_det.cpp
[arm64-v8a] Compile++ : android_dlib <= jni_face_det.cpp
1 error generated.
make: *** [obj/local/armeabi-v7a/objs/android_dlib/jni_pedestrian_det.o] Error 1
make: *** Waiting for unfinished jobs....
1 error generated.
make: *** [obj/local/armeabi-v7a/objs/android_dlib/jni_face_det.o] Error 1
Build Error
Android NDK: [x86_64] Modules to build: android_dlib
[armeabi-v7a] Compile++ arm : android_dlib <= jni_imageutils.cpp
[armeabi-v7a] Compile++ arm : android_dlib <= jni_pedestrian_det.cpp
[armeabi-v7a] Compile++ arm : android_dlib <= jni_face_det.cpp
[armeabi-v7a] Compile++ thumb: dlib <= threads_kernel_shared.cpp
[armeabi-v7a] Compile++ thumb: dlib <= entropy_decoder_kernel_2.cpp
[armeabi-v7a] Compile++ thumb: dlib <= base64_kernel_1.cpp
[armeabi-v7a] Compile++ thumb: dlib <= threads_kernel_1.cpp
[armeabi-v7a] Compile++ thumb: dlib <= threads_kernel_2.cpp
[armeabi-v7a] Compile++ thumb: jni_common <= jni_bitmap2mat.cpp
[armeabi-v7a] Compile++ thumb: jni_common <= jni_fileutils.cpp
[armeabi-v7a] Compile++ thumb: jni_common <= jni_utils.cpp
[armeabi-v7a] Compile++ thumb: jni_common <= rgb2yuv.cpp
[armeabi-v7a] Compile++ thumb: jni_common <= yuv2rgb.cpp
[armeabi-v7a] Compile++ thumb: miniglog <= logging.cc
[arm64-v8a] Compile++ : android_dlib <= jni_imageutils.cpp
[arm64-v8a] Compile++ : android_dlib <= jni_pedestrian_det.cpp
[arm64-v8a] Compile++ : android_dlib <= jni_face_det.cpp
[arm64-v8a] Compile++ : dlib <= threads_kernel_shared.cpp
[arm64-v8a] Compile++ : dlib <= entropy_decoder_kernel_2.cpp
[arm64-v8a] Compile++ : dlib <= base64_kernel_1.cpp
[arm64-v8a] Compile++ : dlib <= threads_kernel_1.cpp
[arm64-v8a] Compile++ : dlib <= threads_kernel_2.cpp
[arm64-v8a] Compile++ : jni_common <= jni_bitmap2mat.cpp
[arm64-v8a] Compile++ : jni_common <= jni_fileutils.cpp
[arm64-v8a] Compile++ : jni_common <= jni_utils.cpp
[arm64-v8a] Compile++ : jni_common <= rgb2yuv.cpp
[arm64-v8a] Compile++ : jni_common <= yuv2rgb.cpp
[arm64-v8a] Compile++ : miniglog <= logging.cc
[x86] Compile++ : android_dlib <= jni_imageutils.cpp
[x86] Compile++ : android_dlib <= jni_pedestrian_det.cpp
[x86] Compile++ : android_dlib <= jni_face_det.cpp
[x86] Compile++ : dlib <= threads_kernel_shared.cpp
[x86] Compile++ : dlib <= entropy_decoder_kernel_2.cpp
[x86] Compile++ : dlib <= base64_kernel_1.cpp
[x86] Compile++ : dlib <= threads_kernel_1.cpp
[x86] Compile++ : dlib <= threads_kernel_2.cpp
[x86] Compile++ : jni_common <= jni_bitmap2mat.cpp
[x86] Compile++ : jni_common <= jni_fileutils.cpp
[x86] Compile++ : jni_common <= jni_utils.cpp
[x86] Compile++ : jni_common <= rgb2yuv.cpp
[x86] Compile++ : jni_common <= yuv2rgb.cpp
[x86] Compile++ : miniglog <= logging.cc
[x86_64] Compile++ : android_dlib <= jni_imageutils.cpp
[x86_64] Compile++ : android_dlib <= jni_pedestrian_det.cpp
[x86_64] Compile++ : android_dlib <= jni_face_det.cpp
[x86_64] Compile++ : dlib <= threads_kernel_shared.cpp
[x86_64] Compile++ : dlib <= entropy_decoder_kernel_2.cpp
[x86_64] Compile++ : dlib <= base64_kernel_1.cpp
[x86_64] Compile++ : dlib <= threads_kernel_1.cpp
[x86_64] Compile++ : dlib <= threads_kernel_2.cpp
[x86_64] Compile++ : jni_common <= jni_bitmap2mat.cpp
[x86_64] Compile++ : jni_common <= jni_fileutils.cpp
[x86_64] Compile++ : jni_common <= jni_utils.cpp
[x86_64] Compile++ : jni_common <= rgb2yuv.cpp
[x86_64] Compile++ : jni_common <= yuv2rgb.cpp
[x86_64] Compile++ : miniglog <= logging.cc
[armeabi-v7a] StaticLibrary : libdlib.a
[armeabi-v7a] StaticLibrary : libjni_common.a
[armeabi-v7a] StaticLibrary : libminiglog.a
[arm64-v8a] StaticLibrary : libdlib.a
[arm64-v8a] StaticLibrary : libjni_common.a
[arm64-v8a] StaticLibrary : libminiglog.a
[x86] StaticLibrary : libdlib.a
[x86] StaticLibrary : libjni_common.a
[x86] StaticLibrary : libminiglog.a
[x86_64] StaticLibrary : libdlib.a
[x86_64] StaticLibrary : libjni_common.a
[armeabi-v7a] SharedLibrary : libandroid_dlib.so
[arm64-v8a] SharedLibrary : libandroid_dlib.so
jni/jni_detections/detector.h:42: error: undefined reference to 'cv::HOGDescriptor::detectMultiScale(cv::_InputArray const&, std::ndk1::vector<cv::Rect, std::ndk1::allocator<cv::Rect > >&, double, cv::Size, cv::Size, double, double, bool) const'
/Users/t/Downloads/compile/third_party/opencv/jni/../libs/armeabi-v7a/libopencv_objdetect.a(hog.cpp.o):hog.cpp:function std::vector<int, std::allocator >::resize(unsigned int, int): error: undefined reference to 'std::__throw_length_error(char const*)'
and it keeps going with errors like this for a very long while, ending with:
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [obj/local/x86_64/libandroid_dlib.so] Error 1
Build Error
I tried also your NDK v13b but the result is exactly the same.
I am working from a OSX environment.
What's wrong? :(
How to write and debug these code, could you teach us?
Luckly,First, I build Succuss!
I dont know what is the reason but it works on every phone but it does not work on some tabs. I dont know what is the problem. No crash report is generated but ANR occurs each time camera is initialised. Can Anyone Please help us?????
Hi,
I tried to setup everything as it should be to build the library (miniglog and opencv and dlib from the site) and I started the build having admin privileges, but I got an error:
In file included from jni/jni_detections/jni_face_det.cpp:14:
In file included from jni/jni_detections/detector.h:14:
In file included from jni/../dlib/dlib/image_processing.h:17:
In file included from jni/../dlib/dlib/image_loader/../image_processing/setup_hashed_features.h:8:
In file included from jni/../dlib/dlib/image_loader/../array2d/../geometry/../image_processing/scan_image_boxes.h:12:
In file included from jni/../dlib/dlib/image_loader/../array2d/../geometry/../image_processing/../image_transforms.h:28:
jni/../dlib/dlib/image_loader/../image_transforms/random_cropper.h:146:67: error: no member named 'round' in namespace 'std'
const unsigned long min_object_height_absolute = std::round(min_object_heightcrop_plan.rows);
~^
In file included from jni/jni_detections/jni_pedestrian_det.cpp:14:
In file included from jni/jni_detections/detector.h:14:
In file included from jni/../dlib/dlib/image_processing.h:17:
In file included from jni/../dlib/dlib/image_loader/../image_processing/setup_hashed_features.h:8:
In file included from jni/../dlib/dlib/image_loader/../array2d/../geometry/../image_processing/scan_image_boxes.h:12:
In file included from jni/../dlib/dlib/image_loader/../array2d/../geometry/../image_processing/../image_transforms.h:28:
jni/../dlib/dlib/image_loader/../image_transforms/random_cropper.h:146:67: error: no member named 'round' in namespace 'std'
const unsigned long min_object_height_absolute = std::round(min_object_heightcrop_plan.rows);
~^
[armeabi-v7a] Compile++ thumb: dlib <= threads_kernel_shared.cpp
[armeabi-v7a] Compile++ thumb: dlib <= entropy_decoder_kernel_2.cpp
[armeabi-v7a] Compile++ thumb: dlib <= base64_kernel_1.cpp
[armeabi-v7a] Compile++ thumb: miniglog <= logging.cc
[arm64-v8a] Compile++ : android_dlib <= jni_imageutils.cpp
[arm64-v8a] Compile++ : android_dlib <= jni_pedestrian_det.cpp
[arm64-v8a] Compile++ : android_dlib <= jni_face_det.cpp
1 error generated.
1 error generated.
make: *** [obj/local/armeabi-v7a/objs/android_dlib/jni_pedestrian_det.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [obj/local/armeabi-v7a/objs/android_dlib/jni_face_det.o] Error 1
Build Error
May I provide additional details?
I noticed it's a NDK related bug. Which version would be better to use?
Regards
Hey, I was trying to build following your tutorial exactly with
python build.py
But an error indicates the OpenCV is not present. Can you give any explanations on how to add it?
make: *** no rule to make target '/home/ezequiel/dlib-android/third_party/opencv/jni/OpenCV.mk'. Stop.
Also, which version exactly of OpenCV must be used?
Hi,
I want to use get_frontal_face_detector() method of dlib in android application. Is there any support for that?
OS: macOS 10.12
clang++ : Apple LLVM version 8.1.0 (clang-802.0.38)
step1: I want to use dlib and opencv on android project. The dlib-android build is ok. But when linking dlib with my source file. The compiler complains as follows:
_"USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_"
step2: I add dlib/all/source.cpp to my source files. But when compiling source.cpp, the compiler complains another error.
../matrix/matrix_utilities.h:2665:29: error: static_assert expression is not an integral constant expression COMPILE_TIME_ASSERT(pixel_traits<P>::num > 0);
step3: I also make a small test by using below command to compile dlib example face_detection_ex.cpp.
For dlib-android repo, the compiler complains with the same error as the step2.
For dlib repo, the compilation of face_detection_ex.cpp is ok .
g++ -std=c++11 -DDLIB_PNG_SUPPORT -DDLIB_JPEG_SUPPORT -DUSE_AVX_INSTRUCTIONS=ON -I.. ../dlib/all/source.cpp -I/usr/local/opt/X11/include/ -I/usr/local/Cellar/jpeg/8d/include -lpthread -L/usr/local/opt/X11/lib -lX11 face_detection_ex.cpp -o face_detection_ex -L/usr/local/Cellar/libpng/1.6.29/lib -lpng16 -L/usr/local/Cellar/jpeg/8d/lib -ljpeg
While looking into #13 issue (found at stackoverflow), I found that your way of using dlib face detection can be optimized for running about 2x-20x times faster:
virtual inline int det(const cv::Mat& image) {
LOG(INFO) << "com_tzutalin_dlib_PeopleDet go to det(mat)";
dlib::frontal_face_detector detector = dlib::get_frontal_face_detector();
Here you are constructing dlib::frontal_face_detector every call of detection function. Consider moving it into constructor - you will get up to 2x performance gain
dlib::cv_image<dlib::bgr_pixel> img(image);
mRets = detector(img);
If image (cv::Mat) will be not an BGR image, your code will crash. Consider adding something like this:
if (image.channels() == 4)
cv::cvtColor(image, image, CV_BGRA2BGR);
else if (image.channels() == 1)
cv::cvtColor(image, image, CV_GRAY2BGR);
Neither face detection nor shape prediction (landmarks) need color information. Consider converting all images into greyscales and running detector on them - this will give you 2x performance gain
No need to detect small faces.
Dlib face detector will detect faces with size of 80x80 and larger. While modern smartphones will capture 10+ MP images. Face detector will run several seconds for each frame.
I recommend you adding parameter that will limit minimal detected face size so you can downscale input image several times to skip small faces.
unsigned min_face_size = 200; //px
double k = 80.0 / min_face_size;
cv::resize(image, image, cv::Size(), k, k);
Also making region of interest and cropping image is extremely efficient in video processing
shape_predictor can be constructed once and made static
This object takes extremely large amount of RAM (about 100 MB) and construction time should be about 5+ seconds. If somebody will need several detectors (or construct/destruct it several times) - this object (shape predictor) will be deserialized several times, while its operator() is const. Documentation says that you can use one global shape predictor (static class member) safely from several threads
making Release build.
99% of Dlib's code is based on headers, and making debug build of your library will produce inefficient code. Consider running ndk-build in release mode with NDK_BUILD=0 param. This is also a possible solution of #13 issue
I am not developing Android code so I can't make PR for this. And all of this is just a suggestion. As you are the author - feel free to ignore them :)
Hi, I've created a new function in the jni_face_detect that takes the camera preview as raw bytes, the face box coordinates computed with Android API and I just need to detect the landmarks of one single face with dlib (I want to skip the face detection phase).
The raw bytes are converted from YUV to grayscale and then rotated, scaled and flipped according to my UI TextureView size.
The landmarks are identified in a very little time but once displayed on the device screen they're very flickery even if the face is still and the face box coordinates remain the same, there's always a "micro" variation in the landmarks coordinates. This doesn't happen using the function jniBitmapDetect provided with the original .cpp file, that uses, instead, bitmaps. In that case, the landmarks are always very stable. I guess I'm messing something up during the conversions or maybe I'm not passing the right pointers...
So, taking inspiration from #39 my code looks like
JNIEXPORT jobject JNICALL DLIB_FACE_JNI_METHOD(jniNewLandmarksDetection)(JNIEnv* env, jobject thiz, jbyteArray rawBytes, jfloatArray rect, jint width, jint height, jint widthB, jint heightB, jint rotation, jint scale) {
jobject jDetRet = JNI_VisionDetRet::createJObject(env);
g_pJNI_VisionDetRet->setLabel(env, jDetRet, "face");
jbyte* b_data = (env)->GetByteArrayElements(rawBytes, 0);
cv::Mat yuvMat = cv::Mat(height+height/2, width, CV_8UC1, (unsigned char*)b_data);
cv::Mat grayMat = cv::Mat(height, width, CV_8UC1);
cv::cvtColor(yuvMat, grayMat, CV_YUV2GRAY_NV21);
cv::Mat scaledGrayscale;
cv::resize(grayMat, scaledGrayscale, Size(heightB/scale,widthB/scale), 0, 0, INTER_LINEAR);
cv::flip(scaledGrayscale,scaledGrayscale,0);
jfloat* r = env->GetFloatArrayElements(rect,0);
dlib::rectangle rec(r[3], r[0], r[1], r[2]);
g_pJNI_VisionDetRet->setRect(env, jDetRet, r[3], r[0], r[1], r[2]);
DetectorPtr detPtr = getDetectorPtr(env, thiz);
dlib::cv_image<unsigned char> img(scaledGrayscale);
dlib::full_object_detection shape = detPtr->msp(img, rec);
for (int k=0; k<shape.num_parts(); k++) {
int x = shape.part(k).x();
int y = shape.part(k).y();
g_pJNI_VisionDetRet->addLandmark(env, jDetRet, x, y);
}
//Test, these two pics look good and they're identical
dlib::save_bmp(img,"/mnt/sdcard/DCIM/input.bmp");
cv::imwrite("/mnt/sdcard/DCIM/det.jpg", scaledGrayscale);
return jDetRet;
}`
Can anyone see the possible cause of the flickering?
When I am trying to build for armeabi error is given, seems that it is related to atomic lib
I'm trying to build a slightly modified version of the jni_people_det shared library (without changing imports just changing the name, just to see if I can build it on my own).
I've decided to put everything together into a single Android.mk file, therefore I've got everything inside the jni folder (without having two different Android.mk files).
I can't make it work since it doesn't find the required headers, it gives me <my-folder>\dlib-android/jni\detector.h:12:10: fatal error: 'dlib/image_loader/load_image.h' file not found
...what am I doing wrong here? Should I include every single .h that's required in detector.h?
-Please see attached file, it's txt since I can't upload a .mk, I've checked that the dlib folder path and miniglog folder path are correct-
Android.mk.txt
Thanks.
Hi, dlib repo added a simd for ARM Neon
Thank you so much
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.