0

I have following code block to load haarcascade_frontalface_alt.xml and check it. And I'm sure that haarcascade_frontalface_alt.xml file path is true. Do you have any idea about this issue?

public static void FaceDetector (Mat image){

    String cascade_name="/home/ismailkaratepe/AndroidStudioProjects/FaceDetectionApp/app/src/main/res/haarcascade_frontalface_alt.xml";
    CascadeClassifier faceDetector = new CascadeClassifier(cascade_name);
    faceDetector.load(cascade_name);

    if (faceDetector.empty()) {
        System.out.println("Face cascade failed to load.");
        return;
    } else {
        System.out.println("Face cascade loaded successfully.");
    }
    ...
}

This always prints Face cascade failed to load. What's wrong?

1 Answers1

0

According to this:

You can not access an application's home directory, on an unrooted device. This would have been a MAJOR security hole.

You need to have a look about where to store files on android and then read your xml file from there

Here there is an example which shows you how to read a file from your local app folder.

File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyAppDir");
Community
  • 1
  • 1
GPPK
  • 6,546
  • 4
  • 32
  • 57
  • 1
    Thank you very much :) My problem is solved with your solution. I copied my .xml file to phone storage. Then in code I gave xml in phone storage path, application runs fine . – İsmail Karatepe Jan 15 '16 at 21:52
  • @İsmailKaratepe i am facing the same problem as you had. Please guide me – Abdul Muheet Jan 11 '18 at 05:10