Search code examples
androidc++opencvandroid-ndkandroid.mk

Android NDK accessing XML file


I am trying to build a lib written in C++. This lib uses OpenCV and needs to access some xml files for face part recognition. Somehow the file access isn't given and I get an error when running

CascadeClassifier faceCascade.load(faceCascadeFile);

I get an error at this point, because the file cannot be opened. The xml files should be contained in the OpenCV lib which is included via Android.mk

OPENCV_INSTALL_MODULES:=on
include ./jni/opencv/sdk/native/jni/OpenCV.mk

I also tried copying the .xml files into my jni folder and including them in my Android.mk

LOCAL_MODULE           := usit
LOCAL_SRC_FILES        := gfcf.cpp haarcascade_frontalface_default.xml haarcascade_eye_tree_eyeglasses.xml haarcascade_mcs_eyepair_big.xml haarcascade_mcs_nose.xml

Still I don't get access to this file. I tried to inspect the built lib, but couldn't find any way to see if the files are somewhere available.


Solution

  • You have to push the file on the device, directly to the storage or with the assets. Have a look here and there.

    If you choose to push the file on the storage, you can easily access it with:

    string faceFile = "/sdcard/Download/haarcascade_frontalface_alt2.xml";
    CascadeClassifier classifier;
    classifier.load(faceFile);