0
Facemark fm = Face.createFacemarkKazemi();

fm.loadModel("assets/face_landmark_model.dat"); <--error

build.gradle(Module:app):

sourceSets {
        main {
            jni.srcDirs = ['src/main/jniLibs/'] 
            assets.srcDirs=['src/main/assets/']
} }

How fix that?

Project tree structure

bob torus
  • 35
  • 2
  • 12

1 Answers1

1

Access the file using assest manager.

AssetManager mngr = myContext.getAssets();
fm.loadModel(mngr.open("assets/face_landmark_model.dat"));

If you don't have context variable, try to create one.

Context context=getApplicationContext();
fm.loadModel(context.getAssets().open("assets/face_landmark_model.dat"));
Bala555
  • 119
  • 1
  • 6
  • I get "Unhandled exception: java.io.IOException" in fm.loadModel(mngr.open("assets/face_landmark_model.dat")); then I add try and catch block but again have error "No file with given name found" – bob torus Nov 19 '18 at 11:13
  • If you create the assets folder manually, check the following link. https://stackoverflow.com/a/26706866/6650476 – Bala555 Nov 19 '18 at 11:59
  • can u please add the stack trace and try this fm.loadModel(context.getAssets().open("face_landmark_model.dat")); – Bala555 Nov 19 '18 at 12:19
  • and I convert InputStream to String it is correct [because loadModel(String Model)] ? – bob torus Nov 19 '18 at 13:03