Face Detection using OpenCV Haarcascades in Android | Jay Rambhia’s Blog
I was working on this app which required face detection and pose estimation. I was already using Native code for some other processes (edge detection, etc) so I figured I’d use Haarcascades in native code only. It was a bit of hassle to configure how to send xml file to JNI or whether it would load the cascade once I pass the filename to the native code.
So I looked around a bit. I tried to look into the examples provided with opencv sdk and found out that I had to write the whole xml file to FileOutputStream so that it could be accessed in the native code.
Making XML available to the native code
First I stored the XML file in assets/ folder.
Once this is done, you can pass the file and relevant Mat objects to the native code.
I’m not editing the native function name here so you need to change it appropriately.
This returns if face is found or not. If face is found it draws on the retvalMat.
So this was pretty easy to do and return a good output.