Ask Your Question
5

Haartraining vs Traincascade : Object Detection

asked 2012-07-25 04:46:02 -0600

Bia6969 gravatar image

updated 2012-07-25 06:09:54 -0600

Hello!

I wanted to do an app that was able, through a picture, to recognize staplers. I've done a quick search and i went with Haartraining. (Not sure if it was the right choice! Comments?) The thing is, i've only trained the classifier with few positive and negative examples (46 and 30) and as far as i understand, it's recommended to have at least a 1000 of each. The quantity it self ain't a problem, but i hear it takes about a day to run haartraining when you have that amount of pictures.

Then, i thought: maybe traincascade would be a better choice! Now i'm all confused..

Please, let me hear what YOU THINK :D Thanks in advance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
7

answered 2012-07-25 06:55:55 -0600

Maria Dimashova gravatar image

updated 2012-07-25 06:57:21 -0600

Hello!

I would advise you to use traincascade app. haartraining is an obsolete version of a cascade training, it's less supported and does not develop. Once, in one of the following OpenCV revisions, you can not find it. traincascade is the newer c++ app for the training. In contrast to haartraining, trancascade supports not only Haar features, but LBP too (and as I know HOG too). See the doc.

But keep in mind that if you use Haar features you'll not see a significant difference in time of training for both apps, because they do the same work in this case. You should try the LBP features instead of Haar if you want to train a cadcade within ~hour instead of ~day (with default parameters, ie with larger positive and negative examples count than you used). LBP features are also ~3 times faster than Haar in the detection (they are real-time on mobile platforms on VGA).

So your best bet is traincascade + LBP.

edit flag offensive delete link more

Comments

@Maria: another guy that didn't know of traincascade :D

yes123 gravatar imageyes123 ( 2012-07-25 09:11:24 -0600 )edit

[Bia6969] So, let's say i wanna change my root and try traincascade + LBP, correct me if i'm wrong:

-I'd still have positive and negative folders. I'd still create a vector through the opencv_createsamples. - The difference would be at the trainning stage, right? I'd use opencv_TRAINCASCADE INSTEAD OF opencv_HAARTRAINING.

-Then what? I understand i'd have to change my detect.cpp, but how? There aren't that many code examples from traincascade. i mean, my detect uses cvHaarClassifierCascade and i'm guessing i'd have to use other structs, but where can i see which ones?

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-07-26 02:26:46 -0600 )edit

[Maria] The usage of traincascade is very similar to the usage of haartraining app. Some parameters have slightly different names. There are some new ones e.g. "-featureType" (HAAR or LBP). See the doc on training http://docs.opencv.org/doc/user_guide/ug_traincascade.html. For detection there is a class CascadeClassifier. See the doc on detection http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html#cascadeclassifier. It can work with old and new file format of trained cascade. Example of its using is facedetect.cpp sample.

Next time please ask a clarifying question as a comment for the order. It's really not an answer. Or, if it's independent, open a new question thread (this time it's not this case). Thanks.

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-07-26 02:27:35 -0600 )edit

Is there any pretrained LBP cascades for faces\face parts? How training time depends on number of samples?

mrgloom gravatar imagemrgloom ( 2013-01-29 08:24:26 -0600 )edit

Yes, a couple of trained LBP cascades can be found here http://code.opencv.org/projects/opencv/repository/revisions/master/show/data/lbpcascades. I don't know how lbpcascade_profileface.xml was trained (e.g. which vec-file was used). lbpcascade_frontalface.xml was trained by me on vec-file http://code.opencv.org/projects/opencv/repository/revisions/master/changes/data/vec_files/trainingfaces_24-24.vec; the used parameters of traincascade app are listed in the cascade xml. At that time I did not have a goal to train as good as possible LBP cascade, so that cascade is just an example (but working well !) and I'm sure you can train even better LBP cascade for faces.

Maria Dimashova gravatar imageMaria Dimashova ( 2013-01-30 13:06:22 -0600 )edit

Of course, more numPos and numSet you set, more time is need. It's hard to say exactly how training time depends on a number of samples because it's also highly depends on your training datasets and other parameters. From my experience the most time-consuming part of traincascade is selecting the negative examples to train each new stage because they have to be recognized as positive samples by all previous (already trained) stages. I.e. traincascade spends significant time in searching the samples of negative base that are very similar to positives (faces).

Maria Dimashova gravatar imageMaria Dimashova ( 2013-01-30 13:18:06 -0600 )edit

even in other forums it says LBP is the most convenient to use since it has fastest training. But i am curious if cascade training can detect object in different orientation and rotation? can it be compensated with rotated positive samples?

bertumen.wj gravatar imagebertumen.wj ( 2016-08-28 20:00:00 -0600 )edit

@bertumen.wj, please don't post answers, if you have a question or comment.

berak gravatar imageberak ( 2016-08-28 23:48:09 -0600 )edit

Also, let me please ask, if you have a question in 2016, about something in 2012 then it is always better to open a new question and link the old one inside it. The users of this questions are almost all disappeared from the scene, apart from some core devs. Furthermore your question will get lost here.

So please, open up a new question and stop opening arcane old ones!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-08-29 04:35:58 -0600 )edit

Can I use features other than haar, lbp or hog? If so what are the modifications I need to make?

amlan gravatar imageamlan ( 2017-02-17 12:07:52 -0600 )edit

Question Tools

6 followers

Stats

Asked: 2012-07-25 04:46:02 -0600

Seen: 14,393 times

Last updated: Feb 17 '17