Mobile app crashes when detecting facial landmarks [closed]
Hi,
Recently github enabled opencv's extra classes through Python-for-android (including the face class). It has no trouble detecting the face binding boxes. It loads the LBF model, but then crashes when calling the 'cv2.face.fit' function on an android device. I am using opencv/opencv_contrib 4.0.1 and NDK 19. The relevant code is below:
img_1 = cv2.imread(ii_file)
img = cv2.cvtColor(img_1, cv2.COLOR_BGR2GRAY)
det = cv2.CascadeClassifier(lm_model)
faces = det.detectMultiScale(img)
l_det = cv2.face.createFacemarkLBF()
l_det.loadModel(lm_model_2)
ff_locations_01 = l_det.fit(img, faces)
Immediately after it calls 'l_det.fit(img,faces)', the stacktrace from adb logcat returns: ' F libc : /buildbot/src/android/ndk-release-r19/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:73: abort_message: assertion "terminating with uncaught exception of type std::length_error: vector" failed'. Here is the full crash report that follows:
*--------- beginning of crash
06-05 18:23:34.580 8134 8162 F libc : /buildbot/src/android/ndk-release-r19/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:73: abort_message: assertion "terminating with uncaught exception of type std::length_error: vector" failed
06-05 18:23:37.604 8134 8162 F libc : Fatal signal 6 (SIGABRT), code -6 in tid 8162 (SDLThread)
06-05 18:23:37.749 9203 9203 I AEE_AED : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-05 18:23:37.750 9203 9203 I AEE_AED : Build fingerprint: 'OUKITEL/U22/U22:7.0/NRD90M/1508468660:user/release-keys'
06-05 18:23:37.750 9203 9203 I AEE_AED : Revision: '0'
06-05 18:23:37.750 9203 9203 I AEE_AED : ABI: 'arm'
06-05 18:23:37.750 9203 9203 I AEE_AED : pid: 8134, tid: 8162, name: SDLThread >>> com.aniface.aface <<<
06-05 18:23:37.750 9203 9203 I AEE_AED : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
06-05 18:23:37.762 9203 9203 I AEE_AED : Abort message: '/buildbot/src/android/ndk-release-r19/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:73: abort_message: assertion "terminating with uncaught exception of type std::length_error: vector" failed'
06-05 18:23:37.762 9203 9203 I AEE_AED : r0 00000000 r1 00001fe2 r2 00000006 r3 00000008
06-05 18:23:37.763 9203 9203 I AEE_AED : r4 97425978 r5 00000006 r6 97425920 r7 0000010c
06-05 18:23:37.763 9203 9203 I AEE_AED : r8 960bfe49 r9 97422b28 sl fbd00bff fp 00000000
06-05 18:23:37.763 9203 9203 I AEE_AED : ip 00000000 sp 97422528 lr b158b7d7 pc b158e034 cpsr 200f0010
06-05 18:23:37.787 9203 9203 I AEE_AED :
06-05 18:23:37.787 9203 9203 I AEE_AED : backtrace:
06-05 18:23:37.787 9203 9203 I AEE_AED : #00 pc 0004b034 /system/lib/libc.so (tgkill+12)
06-05 18:23:37.787 9203 9203 I AEE_AED : #1 pc 000487d3 /system/lib/libc.so (pthread_kill+34)
06-05 18:23:37.787 9203 9203 I AEE_AED : #2 pc 0001d785 /system/lib/libc.so (raise+10)
06-05 18:23:37.787 9203 9203 I AEE_AED : #3 pc 000192c1 /system/lib/libc.so (__libc_android_abort+34)
06-05 18:23:37.787 9203 9203 I AEE_AED : #4 pc 00017034 /system/lib/libc.so (abort+4)
06-05 18:23:37.787 9203 9203 ...
Where is lm_model_2?
lm_model_2 = 'lbfmodel.yaml'. The file lbfmodel.yaml is in the same directory as main.py which is the apps root directory (internal storage). There seems to be no error in loading the yaml model. The model 'haarcascade_frontalface_default.xml' (lm_model) is in the same directory and the app has no trouble using that model.
can you be a bit more specific, about what you installed exactly, and how ?
did you check (filesize / md5sum) if the lbfmodel.yaml was downloaded correctly ?
Snippet:
Thanks supra56,
"can you be a bit more specific, about what you installed exactly, and how ?" - Using buildozer I included opencv and opencv_extras in the list of recipes. These recipes have been recently updated to include opencv's extra classes (13 days ago on my request) when building the apk through Python-for-android. The version of opencv and opencv_contrib is 4.0.1. The NDK is set to 19b. SDK=24, android.api=27.
"did you check (filesize / md5sum) if the lbfmodel.yaml was downloaded correctly ?" - yes, it works and is the right size. It works on my PC..
The app is also finding the face (bounded box) in the test image I'm using on the android device no problem. On the PC side it is all working ok, including finding the face landmarks.
FYI. Very sadly, I can't help you. I'm using OpenCV 4.3.0, linux on Raspberry Pi.
has anyone encountered the same problem on android?