Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android crashed when calling CascadeClassifier.detectMultiScale(matGray, facesRect) #1133

Open
runzedong opened this issue Jan 28, 2019 · 4 comments

Comments

@runzedong
Copy link

runzedong commented Jan 28, 2019

Overview

I'm doing face detection on Android side. The application is supposed to read from a video file and do face detection on frames.

Device

Google Pixel 2

Artifacts Used

    implementation 'org.bytedeco:javacv:1.4.4'
    implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-arm'
    implementation 'org.bytedeco.javacpp-presets:ffmpeg:4.1-1.4.4:android-arm'

Questions

I'm using FFmpegFrameGrabber to extract frames, and convert frames to OpenCV mat with OpenCVFrameConverter.

But the app will crash at the last step when detecting faces on each mat by calling detectMultiScale method.

It complains OpenCL function is not available when calling opencl_check_fn from opencv-4.0.1/modules/core/src/opencl/runtime/opencl_core.cpp:326.

  • Does this mean the libs are not configured properly in this project or it's because the device doesn't support OpenCL, which indicates JavaCV relies on OpenCL supported devices?
  • And the directory shown from the log confuses me as well cause it tried to look up the directory home/travis/build/javacpp-presets. But I don't know where this dir come from? Travis CI?
  • I also tried an OpenCV sample android application on the same device and it works well even though it calls the same method but import from org.opencv.objdetect.CascadeClassifier.
    So it feels like the error is JavaCV specific?
    Link of the sample is here

Error log

The error log posted at below:

2019-01-28 14:36:46.259 1267-1267 A/libc: /buildbot/src/android/ndk-release-r18/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:73: abort_message: assertion "terminating with uncaught exception of type cv::Exception: OpenCV(4.0.1) /home/travis/build/javacpp-presets/opencv/cppbuild/android-arm/opencv-4.0.1/modules/core/src/opencl/runtime/opencl_core.cpp:326: error: (-220:Unknown error code -220) OpenCL function is not available: [clGetPlatformIDs] in function 'opencl_check_fn'
    " failed
2019-01-28 14:36:46.259 1267-1267 A/libc: Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 1267 (ls.samplejavacv), pid 1267 (ls.samplejavacv)

Sample Code

    val faceVideoFilePath = "sdcard/Download/face_tracking_test.mp4" //the test video
    val videoGrabber = FFmpegFrameGrabber(faceVideoFilePath) //init the frame grabber
    val converterToMat = OpenCVFrameConverter.ToMat() //init the frame2mat converter
    val faceDetector: opencv_objdetect.CascadeClassifier // create the CascadeClassifier
    var videoFrame: Frame
    var videoMat: Mat

    while(true){
                videoFrame = videoGrabber.grab()
                if (videoFrame == null) break

                videoMat = converterToMat.convert(videoFrame)

                val videoMatGray = Mat()
                cvtColor(videoMat, videoMatGray, COLOR_BGRA2GRAY)

                val faces = opencv_core.RectVector()
                faceDetector.detectMultiScale(videoMatGray, faces) 

               // may draw rect on face if get faces result return
    }


@runzedong
Copy link
Author

ok. so I downgrade the artifact to use OpenCV 3.4.3, and this error is dismissed and no crash again. But I'd like to remain it open and curious about it's not compatible with 4.0.1.

@saudet
Copy link
Member

saudet commented Jan 28, 2019 via email

@runzedong
Copy link
Author

Just give a bit update. I checked out the latest version with 64-bit builds and it works as expected. So I will close this issue. Updated gradle is below:

    implementation 'org.bytedeco:javacv:1.4.4'
    implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-arm64'
    implementation 'org.bytedeco.javacpp-presets:ffmpeg:4.1-1.4.4:android-arm64'

@saudet
Copy link
Member

saudet commented Jan 30, 2019

I was able to reproduce something like that in the emulator. It looks like the C++ runtime crashes on the exception thrown when checking for OpenCL, something that happens only on 32-bit ARM for some reason as explained at android/ndk#785. In any case, thanks for reporting! Now, we'll need to fix this...

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

No branches or pull requests

2 participants