FaceRecognizer trained XML to Cascade Classifier (2.4.13)?

asked 2016-07-07 11:17:23 -0600

mrfromage gravatar image

If you like exciting stories, keep on reading! If not, just scroll to the short version.

I started using OpenCV 2.4.13 a few weeks ago. Why didn't I use the newer version instead? Because the examples were mostly for 2.4.x and you know you're happy if you even find a Java example. ;)

The beginning stuff made so much fun! Find a face on a picture, on webcam source, on a video... So, after the beginner's stuff, I coded a program in Java which scans a whole directory (with subdirs) and lists up and saves the filenames (+timecodes) in which the chosen face was found.

This is pretty cool! But always searching for haarcascade_frontalface_alt can be damn boring. So I cloned and altered the program: now it looks for human faces and saves the frames to an image list, which are then passed to the FaceRecognizer, trained and saved as XML.

The problems up to this point were an odyssey! No fisher-, eigen- oder lbph-facerecognizer methods for Java 2.4.13! So I had to compile a DLL in C++ for later import in Java. I'll spare you with my C++ compiler problems (had to use MSVC++ 2012 finally). And I will not complain about opencv_ffmpeg2413_64.dll, which allows me to access MPeg4-files but prohibits the use of .avi Files (at least on my machine, so I have to turn them on/off as I need it). After somehow managing to get this running (because I put it all into a Java package, which is somewhat import for the DLL method names), I got it done and the found human-face-frames are actually being given to the FaceRecognizer, then .trained and .saved as XML.

Yey! :)

=== SHORT VERSION MARKER ===

But if I try to load the just generated XML file (with FaceRecognizer.save) in my opencv programs, it says:

"error: (-2) The node is neither a map nor an empty collection in function cvGetFileNodeByName"

That's because I use the CascadeClassifier instead of FaceRecognizer for Loading XML Files. But the FaceRecognizer is the only one I can train faces with in Java (opencv 2.4.13).

So what shall I do?

I like the way how CascadeClassifier gives me the option to detectMultiscale and then passes the result to a loop, so I know the region where the face(s) are found. But if I don't wanna export the frames to files and then use opencv_traincascade.exe manually I have to use the damn FaceRecognizer with the predict method, right?

Thanks in advance.

edit retag flag offensive close merge delete

Comments

1

"searching for haarcascade_frontalface_alt can be damn boring."

my advice: stick with boring, don't try to outsmart everyone else, as long you don't have a clue. you simply cannot use a trained recognition model for detection, those are 2 totally different operations.

berak gravatar imageberak ( 2016-07-08 01:18:33 -0600 )edit

I see, berak. Thanks for the quick reply. At first I had the silly believe the XML format would be universal in opencv. When I found a method to save a trained face as XML, I was a bit too naive (to believe in such an easy solution).

mrfromage gravatar imagemrfromage ( 2016-07-08 01:39:40 -0600 )edit

You are still mixing up stuff, the models generated for detection generalize over a class, as where the models generated for face recognition are individual specific and do not generalize o_O

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-08 04:31:07 -0600 )edit

I'm very sorry because I really thought I made clear, that I already found out about the incompatiblity between FaceRecognizer and CascadeClassifier. Or do I understand you wrong now. Is there no way to train and save face data in order to load and use it for face detection?

mrfromage gravatar imagemrfromage ( 2016-07-08 04:41:15 -0600 )edit

again you are mixing stuff --> you cannot simply use a recognizer to capture data for detection ...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-07-08 04:47:17 -0600 )edit

Aye. So, could I save the cropped, grayscaled and equalized face images to a dir and let run the opencv_traincascade or opencv_haartraining tool to get my wishful xml file to use with CascadeClassifier? Would that work? :D

mrfromage gravatar imagemrfromage ( 2016-07-08 04:59:02 -0600 )edit
1

you would still need negative (non-face) images.

again, if you want to collect samples to train a detection, - there is no point in using the FaceRecognizer class at all.

berak gravatar imageberak ( 2016-07-08 05:01:57 -0600 )edit

ok thanks a lot u2!

mrfromage gravatar imagemrfromage ( 2016-07-08 06:36:07 -0600 )edit