Post date: Mar 12, 2012 10:48:11 PM
Because I hate stumbling across a tutorial that is exactly 100% the thing I need only to find that it says "this is a work in progress" and doesn't actually include the part I need I want to put a placeholder here while I work on a realy tutorial page rather than do the same.
The code and cascade training steps need to be done in the opposite order from the articles because training the cascade file is pretty useless if you don't know what you're going to do with it.
Getting the cascade classifier file built isn't too difficult. The hard part was finding which tools to use. The tools are actually bundled with OpenCV. Once again very smart people making this seem easy. I just couldn't figure out how to find said file or how to use it. It's not the best documented and typically referenced using a slightly different name than it actually has.
After I had muddled about and finally gotten it working I found Naotoshi Seo's fantastic tutorial on it.
The tool he references, haartraining, has recently been replaced by traincascade however the syntax is very similar. My totorial will be simplified and this less detailed than His.
First you will need to compile the C++ OpenCV library. Createsamples and Traincascade are not included in the Java/Android package. If you never plan on doing any other C++ development I will be putting together my tutorial using only cmake and mingw. The OpenCV install guide actually has about eleven ways to do it for several different OSes. It's pretty complete. Mine will be specific but aimed at folks who are just trying to get object detection working for some other project.
The short answer for those who may get lost in the additional details of Naotoshi's tutorial (such as stitching toghether multiple .vec files) is:
1. Collect a sample set of images - the more the better. Different lighting, different angles, different sizes, etc are all important.
2. Stitch them together into a single file in .vec format with createsamples. The tool will also do some randomized transformation of the images you feed it. It will rotate, squish and flip your iamges to create more samples. Technically you can create your samples from a single image with this tool but it is not an adequate replacement for a large sample set.
3. Feed your stitched together samples into opencv_traincascade to create a cascade classifier xml file.
Documentation on opencv_traincascade is here. You can just run opencv_traincascade -h to see the arguments. Most of them are the same as haartraining and Naotoshi's tutorial actually explains what they need in a little greater detail.
The -data -vec and -bg arguments are required. The -numPos -numNeg -h and -w arguments will use default values if they are not specified so unless you used the exact height, width and number of files as the defaults then you should consider those required as well.
Run it once without them to see the default values.
Just knowing it's called opencv_traincascade instead of "traincascade, which can be found in the apps directory" will help you find other references to it.