Ask Your Question

Maria Dimashova's profile - activity

2017-11-17 10:27:39 -0600 received badge  Great Question (source)
2016-09-02 06:08:42 -0600 received badge  Great Answer (source)
2016-09-02 06:08:42 -0600 received badge  Guru (source)
2016-01-28 07:34:43 -0600 received badge  Guru (source)
2016-01-28 07:34:43 -0600 received badge  Great Answer (source)
2015-06-13 06:51:37 -0600 received badge  Taxonomist
2014-12-09 13:43:38 -0600 marked best answer Do all opencv functions support in-place mode for their arguments?

in cases where this question arises.

For example, should I write:

Mat img = imread(filename);
{ 
  Mat tmp;
  cvtColor(img, tmp, CV_BGR2Lab);
  img = tmp;
}

(not in-place variant)

or:

Mat img = imread(filename);
cvtColor(img, img, CV_BGR2Lab);

(in-place variant)?

If some functions do not support in-place mode, how can I know about this?

2013-08-07 09:41:11 -0600 received badge  Good Question (source)
2013-03-07 03:39:28 -0600 received badge  Nice Answer (source)
2013-02-25 23:54:51 -0600 received badge  Good Answer (source)
2013-02-25 23:54:50 -0600 received badge  Good Answer (source)
2013-02-10 14:09:27 -0600 answered a question Convert opencv_traincascade intermediate output into xml

There are two applications to train cascade classifiers in OpenCV now, see http://answers.opencv.org/question/757/haartraining-vs-traincascade-object-detection/#759.

c-example-convert_cascade is for cascades trained by haartraining application and it does not support a format of cascades trained by traincascade application. This is why you got the exception.

For the conversion in your case you should run opencv_traincascade again with the same "-data" but set "-numStages 6". The application will load the trained stages, realize that there is required number of stages, write the result cascade in xml and finish a work.

Please also keep in mind that when you kill the application the last stage*.xml can be broken (partially saved). In this case you'll get an exception with the suggested conversion too because the broken xml can not be read. You can just remove the last stage xml or set "-numStages 5".

2013-01-30 13:18:06 -0600 commented answer Haartraining vs Traincascade : Object Detection

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

2013-01-30 13:06:22 -0600 commented answer Haartraining vs Traincascade : Object Detection

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.

2013-01-17 17:24:27 -0600 received badge  Good Question (source)
2013-01-08 03:09:58 -0600 received badge  Nice Answer (source)
2012-12-12 10:12:40 -0600 received badge  Nice Answer (source)
2012-12-12 10:12:33 -0600 received badge  Good Answer (source)
2012-11-25 10:29:30 -0600 answered a question Traincascade Error: Bad argument (Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.

I guess moderators will recommend you to open new question and not to ask more questions in the answer on your own question :)

Here it's said that -numPos is used in training for every classifier stage. OK, maybe we really have to specify that -numPos != vec-file samples count at that guide. Please, open the issue here with the link to this question.

0.9999999... is not a good value of minHitRate at least due to it will result in complicated classifiers even at first stages. And this breaks the idea of a cascade classifier to have weak classifiers at the beginning for rejecting a huge amount of background rectangles by cheaper checks of the first stages.

S depends on vec-file samples properties but you can also try to estimate this value. Suppose that the samples in vec-file have the equal probabilities to be rejected by a given cascade (be recognized as background). Of couse it's not true in reality but it's sutable for the estimation of vec-file size. In uniform case when you try to select falseNegativeCount positive samples to train i-stage you will select every new sample from vec-file with probability minHitRate^i. So to select falseNegativeCount samples you will try in average falseNegativeCount / minHitRate^i samples from vec-file. The increasing factor is small. E.g. if i=1, numPos=1000, minHitRate=0.99, falseNegativeCount=10 then you need to try in average ~10.1 samples from vec-file. More detailed formula about vec-file size with this assumption you can derive easy.

About wasting hours of work.. traincascade stores each trained stage immediately, so if you get an exception you can try to start training from current stage but with another training parameters and maybe with more rich vec-file.

I also don't recommend you to downgrade to 2.2. I did not find in the Git history my commit (due to files reorganization), but I fixed the following problem of traincascade: when traincascade tries samples from vec-file one by one and reaches the end of the file it have to finish the training, otherwise it will use duplicate samples. This was the bug.

The answer on the question about 2000 positives. To be sure that you can train a good cascade, try to use traincascade with default parameters on well-tried vec-file. Maybe you should start to play with parameters on this vec-file (not your) and definitely with LBP features (LBPs decrease wasting the time). For the choosing numPos, I think you can follow something like this numPos=0.9xNum_in_vec and you can also get more accurate estimation of this coefficient (instead of 0.9) in the uniform case (it's easy).

About tips on studing the traincascade code. As usual, from top to more details.. Here classical Haar is the best feature to get understanding faster (especially where features are processed by ADABoost because Haar is ordered (not categorical)). For an optimization the integral images are intensively used in cascades (keep it in mind). Don ... (more)

2012-11-24 05:36:57 -0600 received badge  Nice Answer (source)
2012-11-23 05:50:08 -0600 commented answer Traincascade Error: Bad argument (Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.

Yes, you still need to keep in mind this formula. That fix was only about to throw an exception with error message for a user if there are not enough positive samples for the next stage training, because there was an assertion in that point of the code before.

2012-11-23 02:52:58 -0600 commented answer Error in parameter of traincascade?

@icedecker You wrote that you prefer to use the formula, but a bit confused with it. I tried to describe it in more details here (http://answers.opencv.org/question/4368/traincascade-error-bad-argument-can-not-get-new/). Please check this if you're still interested.

2012-11-23 00:06:24 -0600 answered a question Traincascade Error: Bad argument (Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.

Hi,

First of all, I have to note that you copied my formula description incompletely. I wrote at that issue: "S is a count of samples from vec-file that can be recognized as background right away". With the partial description of S from the question, the formula does not make sense at all :)

For the document you asked.. I don't remember that I wrote this formula anywhere except the issue. The formula is not from any paper of course, it just follows from how traincascade application selects a set of positive samples to train each stage of a cascade classifier. Ok, I'll describe my formula in more details as you ask.

numPose - a count of positive samples which is used to train each stage (do not confuse it with a count of all samples in vec-file!).

numStages - a stages count which a cascade classifier will have after the training.

minHitRate - training constraint for each stage which means the following. Suppose a positive samples subset of size numPose was selected to train current i-stage (i is a zero-based index). After the training of current stage, at least minHitRate * numPose samples from this subset have to pass this stage, i.e. current cascade classifier with i+1 stages has to recognize this part (minHitRate) of the selected samples as positive.

If some positive samples (falseNegativeCount pieces) from the set (of size numPose) which was used to train i-stage were recognized as negative (i.e. background) after the stage training, then numPose - falseNegativeCount pieces of correctly recognized positive samples will be kept to train i+1-stage and falseNegativeCount pices of new positive samples (unused before) will be selected from vec-file to get a set of size numPose again.

One more important note: to train next i+1-stage we select only the samples that are passed a current cascade classifier with i+1 stages.

Now we are ready to derive the formula. For the 0-stage training we just get numPose positive samples from vec-file. In the worse case (1 - minHitRate) * numPose of these samples are recognized as negative by the cascade with 0-stage only. So in this case to get a training set of positive samples for the 1-stage training we have to select (1 - minHitRate) * numPose new samples from vec-file that are recognized as positive by the cascade with 0-stage only. While the selection, some new positive samples from vec-file can be recognized as background right away by the current cascade and we skip such samples. The count of skipped sample depends on your vec-file (how different samples are in it) and other training parameters. By analogy, for each i-stage training (i=1,..numStages-1) in the worse case we have to select (1 - minHitRate) * numPose new positive samples and several positive samples will be skipped in the process. As result to train all stages we need numPose + (numStages - 1) * (1 - minHitRate) * numPose + S positive samples, where S is a count of all the skipped samples from ... (more)

2012-11-22 10:55:55 -0600 answered a question FeatureDetector giving conversion error on image set

You have to pass

vector<vector<KeyPoint> > keypoints;

for a vector of images (see the part of the documentation you mentioned above).

2012-11-20 11:39:30 -0600 marked best answer What is the most effective way to access cv::Mat elements in a loop?

I need to process cv::Mat elements and there is not special OpenCV function that performs my task. So I have to iterate the elements in loop. What is the more effective way of elementwise access? cv::Mat iterators, cv::Mat::at() method, maybe pointer arithmetic by hand or something else?