OpenCV2.4.6 face detection sample issue(FileIOException)
Hello, I got a trouble to run OpenCV2.4.6 face detection sample program(OpenCV-2.4.6-android-sdk-r2.zip) on Android2.2.2 device(LG VM670).
Eclips informed that "FileIOException happen in FdActivity.java"
Finally, I solved this issue. But I can't understand this issue only happen on my device or general issue or not. Let me share it.
(Original code in line 72 : FdActivity.java in OpenCV Sample - face-detection)
mCascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml");
FileOutputStream os = new FileOutputStream(mCascadeFile);
In this case, FileIOException happen at new FileOutputStream(mCascadeFile). I was assuming that "FileOutputStream" will make new file if a file is not existing...then I had screwed up. I couldn't get a reason why "FileIOException" happen.
Finally, I solved this issue like below.
(Modified code in line 72 : FdActivity.java in OpenCV Sample - face-detection)
mCascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml");
mCascadeFile.createNewFile(); // CreateNewFile!
FileOutputStream os = new FileOutputStream(mCascadeFile);
Then face detection sample can work correctly.
I checked other OpenCV topics in this forum. But I couldn't find similar trouble in history. I'm not sure this issue only happen on my device and environment or not.
I just want to share this fact and I would like to get some advice from expert(For example, I missed some step to setup OpenCV enviroment...something like that)
Best Regards
Bgb.Tom
I don't know much about Java, but don't you then erase the loaded trained-classifier (the xml-file)? Maybe your path to lbpcascade_frontalface.xml was just wrong?
@Guanta, to shed some light on this, the cascade file comes packaged with the application in a jar file. since opencv can't read from zips, it has to get unpacked, written to disk, the cascade reads it in , and then it can be removed from disk again. it's as clumsy as it sounds.
@Guanta,"lbpcascade_frontalface.xml" is output stream file like @berak mentioned. Probably, it is correct and I checked cascadeDir.("/data/data/org.opencv.samples.facedetect/app_cascade"). it seems no problem.
am i wrong, or is andoid 2.2.2 "oldish" ?
also, the sample seems to write the temporary file to /mnt/private. where on gods earth is that even ? is that a ramdisk or something ?
if you're using the facedetection quite often, it might be worth copying the xml to some place on sdcard permanently, and read it in from there. it's just ~ 50kb iirc
@berak, Thanks for your advice about "xml to some place on sdcard permanently". I should try it some time.(I'm just beginner of OpenCV, Such advice is useful for me)
@berak: Thx for the clarification! I wasn't aware of that.