In my app,I've the below code:
object FaceDetection {
private val faceModel = "haarcascade_frontalface_default.xml"
private lateinit var faceCascade: CascadeClassifier
fun loadModel(activity: Activity) {
faceCascade = CascadeClassifier(File(activity.filesDir, "das").apply { writeBytes(activity.assets.open(faceModel).readBytes()) }.path)
}
}
Which is fail with the above mentioned error, I saved 2 copies from the xml
file, one in the xml
folder and one in main/java
folder, but none of them is working, where shall I put this file, and how to call it if there is something wrong in my call above?
I tried solving it as:
private fun loadModel(activity: Activity) {
var res = activity.resources
faceModel = res.getXml(R.xml.haarcascade_frontalface_default).text
faceCascade = CascadeClassifier(File(activity.filesDir, "das").apply {
writeBytes(activity.assets.open(faceModel).readBytes())
}.path)
}
But got an error:
res.getXml(R.xml.haarcas…frontalface_default).text must not be null