OpenCV2.4.6 face detection sample issue(FileIOException)

asked 2013-08-01 02:40:15 -0600

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

edit retag flag offensive close merge delete

Comments

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 gravatar imageGuanta ( 2013-08-01 03:12:33 -0600 )edit
1

@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.

berak gravatar imageberak ( 2013-08-01 03:24:43 -0600 )edit

@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.

bgb.tom gravatar imagebgb.tom ( 2013-08-01 03:38:45 -0600 )edit

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 gravatar imageberak ( 2013-08-01 03:44:57 -0600 )edit

@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)

bgb.tom gravatar imagebgb.tom ( 2013-08-01 04:00:26 -0600 )edit

@berak: Thx for the clarification! I wasn't aware of that.

Guanta gravatar imageGuanta ( 2013-08-01 05:18:48 -0600 )edit