# How to read yaml model for opencv.face.FaceRecognizer in Android

**URL:** https://forum.opencv.org/t/how-to-read-yaml-model-for-opencv-face-facerecognizer-in-android/19262
**Category:** Android/Java
**Created:** [November 12, 2024, 9:22am UTC](https://forum.opencv.org/t/how-to-read-yaml-model-for-opencv-face-facerecognizer-in-android/19262 "2024-11-12T09:22:23Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Pici](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@Pici](https://forum.opencv.org/u/Pici)
#### Post date: [November 12, 2024, 9:22am UTC](https://forum.opencv.org/t/how-to-read-yaml-model-for-opencv-face-facerecognizer-in-android/19262/1 "2024-11-12T09:22:23Z")

</div>

In MainActivity.java I have included “import org.opencv.face.FaceRecognizer”.  
My yaml file is stored under res/raw. The file is then copy to a new folder has a directory **root**.  
I tried to get the model by FaceRecognizer.read( **root** )  
I also tried FaceRecognizer.load but it does not exist.  
My error message: java.lang.NullPointerException: Attempt to invoke virtual method ‘void org.opencv.face.FaceRecognizer.read(java.lang.String)’ on a null object reference  
What should I do?

My code:

protected void faceLoad() throws IOException {  
InputStream is2 = getResources().openRawResource(R.raw.test);  
File cascadeDir2 = getDir(“cascade”, Context.MODE\_PRIVATE);  
cascFile2 =new File(cascadeDir2,“test.yaml”);  
String root;  
root = cascFile2.getAbsolutePath();  
FileOutputStream fos2 = new FileOutputStream(cascFile2);

```
        byte[] buffer2 = new byte[4096];
        int bytesRead2;

        while ((bytesRead2 = is2.read(buffer2)) != -1){
            fos2.write(buffer2,0, bytesRead2);
        }

        is2.close();
        fos2.close();

        faceRecognizer.read(root);

```

}
