Mobile app crashes when detecting facial landmarks [closed]

asked 2020-06-10 08:35:11 -0600

updated 2020-06-11 02:31:16 -0600

berak gravatar image

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 ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-07 01:12:41.914607

Comments

Where is lm_model_2?

HomanH gravatar imageHomanH ( 2020-06-10 11:47:57 -0600 )edit
1

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.

SonofPoseidon1982 gravatar imageSonofPoseidon1982 ( 2020-06-10 13:17:02 -0600 )edit

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 ?

berak gravatar imageberak ( 2020-06-11 02:29:48 -0600 )edit

Snippet:

face_cascade = cv2.CascadeClassifier(face_cascade)
facemark = cv2.face.createFacemarkLBF()
facemark.loadModel(lbf_model)

status, images_test, _ = cv2.face.loadDatasetList(test_images, test_images)

for image in images_test:
    frame = cv2.imread(image)
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray_frame, 1.3, 5)
    if len(faces) > 0:
        status, landmarks = facemark.fit(frame, faces)
        for f in range(len(landmarks)):
            cv2.face.drawFacemarks(frame, landmarks[f])
    else:
        print("No Face Detected")
    cv2.imshow('Landmark_Window', frame)
supra56 gravatar imagesupra56 ( 2020-06-11 04:35:23 -0600 )edit
1

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.

SonofPoseidon1982 gravatar imageSonofPoseidon1982 ( 2020-06-11 05:27:24 -0600 )edit

FYI. Very sadly, I can't help you. I'm using OpenCV 4.3.0, linux on Raspberry Pi.

supra56 gravatar imagesupra56 ( 2020-06-11 05:56:13 -0600 )edit

has anyone encountered the same problem on android?

SonofPoseidon1982 gravatar imageSonofPoseidon1982 ( 2020-06-13 22:35:49 -0600 )edit