Rhonda Software

Highest quality full cycle software development.

Expert in areas of Computer Vision, Multimedia, Messaging, Networking and others. Focused on embedded software development. Competent in building cross-platform solutions and distributed SW systems.

Offer standalone custom solutions as well as integration of existing products. Opened for outsourcing services.

Visit us at: http://www.rhondasoftware.com

OpenCV Haartraining: Detect objects using Haar-like features

Posted on : 02-06-2009 | By : rhondasw | In : OpenCV

293

OpenCV’s standart cascades allow to detect faces and eyes.  I wanted to create cascade in similar way to detect another objects:  pringles or plate for example.  I found some material in Net how to use OpenCV training tools, also I investigated training tool’s source  code myself  to found out, what training parameters can be tuned.

Prepare images.

For training, I needed thousands of images, containing my object with different lightning conditions and perspectives. After trying to find required number of pictures with Google ,  I understood, that it’s really difficult task =).  So I decided to take video with my object,  then I wrote simple program to crop object from video, frame by frame.  In such way,  I generated about 3000 positive samples (cropped images  with my object).  Resolution varied from 50×50 to 100×100.  The advantage of this method – you  get many samples with different reflections, illuminations and backgrounds.  It’s very important, that all these images “features” are various!

Negative samples I got  from Internet public databases…, there were about 5000 images of different resolution, which did not contain my objects.   I worked with BMP format, due to compression artefacts in some compression levels of JPEG.

Sample/Test data creation.

So I split all my images into 4 sets:

  • Positive images, containing my object – about 3000 images, for training.
  • Negative images – about 5000 images, for training.
  • Positive images – about 100 for testing.
  • Negative images – about 100 for testing.

Of course, I could use the same images for testing and training, but it’s not good.  Positive images should be be packed to OpenCV vec-file.  it can be done with createsamples program from OpenCV.  When packed, all images are resized to 20×20 – it’s good size for training speed.  Also during object detection, object with smaller size will not be found.   For negative samples,  I only created negative.dat(list of negative file names) with win dir \b command.

Training.

OpenCV implements Adaboost algorithm in haartraining. exe.  This tool  generates xml cascade file, which is used in haardetection tool for object detection.  There are some main characteristics of cascade:  number of stages, type of classifiers on each stage. These parameters can be configured when you launch haartraining. I configured it as per my training data (positives and negatives).

Training is finished, when required false alarm of cascade is achieved.  So cascade can contain less stages than nstage – it’s ok. It’s rather worse, when we achieve required number of stage, but required false alarm is not. It’s signal, that something is wrong either with content or with haartraining parameters.  Also maxfalsealarm is false alarm of stage, false alarm of cascade is multiplication of stage’s alarms.

I used P4 2.7GHZ with 2 GB and it took about !6 days! of permanent working to finally get cascade.  If you have Hyper Threading, you can recompile haartraining.exe with OpenMP support, it will speed up process a little bit =).

Testing.

Finally I got haarcascade.xml file. OpenCV perfomance.exe tool can be used for testing cascade.  I tested it on my testing content  – sorry for pun =).

Comments (293)

Hi… I am currently trying out face detection through parallelization… working on vs2008..
can u help me in how to write code of face detection to be multi threaded..

Hi John,
We don’t think that parallel code of viola-jones will be faster. Viola-Jones algorithm has random memory access. With two threads on the same image, it could work slowly due to memory access. We have the synchronous fast face detection see http://www.computer-vision-software.com/blog/2009/06/fastfurious-face-detection-with-opencv/. We have even more faster own face detection. If you are interesting it, you could discuss it with our marketing team (see about page for details).

Aleksey

Thanks for ur reply….
Can u suggest me the face detection using OpenMP….
and also how to recognize the detected faces… Wat database should i use for it ? ? ?

Hi all…

I’m an italian engineering student and I’m doing my final year thesis. We are trying to build an accessibility software for the blind. Because one of the preliminary tasks that need to be done is an object detection we thought to opencv-haartraining. We have some troubles and some specific questions for which we can’t find satisfying answers on the net.

I’m writing here because this team seems to be highly specialized on OpenCV and haartraing. I’m wondering if I could contact one of your experts via mail – or other way – to explain my problem and try to get some help from you. We will appreciate very much if you could help us…

Hi CometK,

If you would like to consider work with us as 1 hour per $ scheme, you could contact our marketing team, see “about” page for details.

Aleksey

Hi

I got a problem with the performance test. Training worked so far (I guess). I used 200 positives and 800 negatives for a first run and after 11 nodes it stopped. When I try to test my cascade with performance.exe I get nothing. Same happens if I try to use one of the OpenCV implemented haarcascades:
C:\OpenCV\bin>performance.exe -data haarcascade_frontalface_alt.xml -info test_p
os_val.txt
+================================+======+======+======+
| File Name | Hits |Missed| False|
+================================+======+======+======+
| Total| 0| 0| 0|
+================================+======+======+======+
Number of stages: 22
Number of weak classifiers: 2135
Total time: 0.000000
22
0 0 -1.#IND00 -1.#IND00
0 0 -1.#IND00 -1.#IND00
0 0 -1.#IND00 -1.#IND00

Any suggestion?

thx

my test_pos_val.txt looks like this:

test_pos_val/img1.pgm
test_pos_val/img2.pgm
test_pos_val/img3.pgm
test_pos_val/img4.pgm
test_pos_val/img5.pgm

Try “test_pos_val/img1.pgm 1 140 100 45 45” format of line in your test_pos_val.txt (please, read other comments in the topic for more details).

thx, I didn’t find any hints regarding the performance.exe.

Why do we require coordinates for testing? Shouldn’t it test the image by its name alone?

I have the same problem with you,do you figure out?

Hi Chenwei,

I also had the same problem! I configured everything correctly, but still I had empty output. How I solved my issues:
I found another compilation of my openCV and used its opencv_performance and all of a sudden it worked out. Maybe you try that too! (I know it is no solution, but it is a point to start)!!

greets, Tobi

Hi,

You say :
“Training is finished, when required false alarm of cascade is achieved. […] . Also maxfalsealarm is false alarm of stage, false alarm of cascade is multiplication of stage’s alarms.”

But we cannot set false alarm of cascade, so how to know when the training will be finished exactly ?
Because, it won’t never reach nstages, and reach HitRate and FalseAlarm during a stage doesn’t mean it is OK…just mean step to the next stage…

Thanks,

There is a line in code (cvhaartraining.cpp):

required_leaf_fa_rate = pow( (double) maxfalsealarm, (double) nstages ) / nleaves;

so, when you define maxfalsealarm for one level and number of stages, application calculates required false alarm of whole cascade.

Also do you know if working with splits and tree is usefull ?
Is it in anyway faster for future detection ?
Thanks for your answer

I believe, influence of number of splits on quality of cascade is not well defined matter. Try different numbers and compare results for your particular task. I saw references to nsplits equaled 1, 2 and 4. There is no significant imact on detection speed as, in any case, the most of tested windows are filtered at initial levels. Good long cascade will save more time during detection than bad short.

Hello
I am having problems while executing haartraining.

I create the training set and everything seems ok (checked with flag -show activated), but training for example 20 stages, from stage nº 5 I get this message “Premature end of JPG file”, and a few stages later it ends with the message “Required leaf false alarm rate achieved. Branch training terminated”

When I test the xml file obtained its not able to detect anything, and I dont know what the problem is

Looking forward for any help 😀

Thanks

I got a question regarding different CPUs for haartraining.

I noticed that the results differ a lot from the same date with different CPUs…how is that possible?
Tested it on 2 single cores, 1 dual core and 1 quadcore with the same parameters and data. The number of features calculated each stage are very different. Stage 5 f.e. goes from 7 on quadcore to 65 on singlecore and the gap gets bigger in higher stages.

Is there an explenation for this?

From a cc3_face_detector.pdf :

Available RAM in the CMUcam3 processor is a major bottleneck in the implementation
of the face detector. Accounting for 8K stack, only 54K of ROM is available for
computations. Considering a lower resolution gray scale image of 176×144, the integral
image alone requires about 76K of memory (with 24 bit per pixel). Besides, there are no
floating point operations available on the board. The clock speed at 60 MHz isn’t terribly
fast either. Even with all these restrictions, it is possible to get baseline performance for
face detector in a controlled environment, in terms of both detection rates and speed. It
takes about 5-6 seconds for CMUcam3 to detect faces. It can report multiple detections
for a single face with an offset of few pixels.

Regards

[…] of training and test images. (For example, see these Haartraining articles by Naotoshi Seo, Rhonda Ltd. and Florian Adolf). I find this surprising and disappointing, since we humans can learn to […]

hi
I need to implement haar-like features in my application
can you please tell me how can I choose the exact features for my objects??
is there a relation or rule??

Hello,

I am working on my student research project and I’m trying to train a cascade for facedetection using OpenCV haartraining. After I collected my picture database I ran into some problems I can’t put my finger on. The training runs fine but when I want to test my cascade with performance.exe or detection faces I get nothing. Even if I try to detect faces I used in the training process. Been trying to run a successful training the last 2 months but now I’m running out of options and I really need some help.

Here is what I did:
First of all, Im working with OpenCV 1.0 on windows XP or Win7 32bit (tried both) on a Inter Core 2 Quad Q8300 @ 2.5 GHz with 4GB RAM. I tried using 2.0.0a but I couldn’t even create a positives vec-file because it crashed all the time.
I got a few thousand positive pictures with a resolution of 24×24 in *.pgm format and plenty of negatives. My positive info file looks like this:

img0001.pgm 1 0 0 24 24
img0002.pgm 1 0 0 24 24

The negatives file:
imgn0001.pgm
imgn0002.pgm

Then I created a vec file with createsamples.exe:
createsamples.exe -info positives.txt -vec positives.vec -num 1500 -w 24 -h 24

After that I started the haartraining process:
haartraining.exe -data haarcascade -vec positives.vec -bg negatives.txt -npos 1500 -nneg 3000 -nstages 25 -mem 1380 -nonsym -minhitrate 0.999 -mode ALL -w 24 -h 24 -minpos 1500

I can’t use more memory because I get error messages if I try ~1400+. I also tried different modes already and I ran a test with the MIT dataset to eliminate the possibility of my pictures being the problem. The result is always the same:
The training gets completed after 15-19 stages (depends on minhitrate and samplesize). Sometimes I had to create the cascade xml-file myself sometimes not…but the result was always the same:
performance.exe -data haarcascade.xml -info positives.txt -ni

I only get “missed” on every single image. Not one “hit” or “false”. Same result with facedetect.exe using my cascade.

Please, have You any suggestions on what I might be doing wrong? I’m clueless.

please, can’t anyone tell me what might be the problem?

I put my work on ice during exams period. But I’m really disappointed to see that I still didnt get any reply…I’m kinda dependant on you. Anyone?

Hi, Aldariel, let’s begin from simple task. Can you train cascade with 100 positive, 100 negative images and 2 stages? It’s worth to get results for such trivial cascade before trying to solve your practical task.

Hi, Aldariel,
I have the same problem with you. The difference is that I am working on eye detecting. The whole training is smooth going but all of the results of test pictures are missed! I have been troubled in several weeks. Have you solve the problem later? If you have any solution please help me! Thanks very much!

Hi, Hannah,
I have the same problem with you. Have you solve the problem later !!! If you have any solution please help me! Thanks.

Hi,
Iam new to opencv. In haartraining some times I get Error: bad flag (parameter or structure field) () in function cvReleaseMat, cxarray.cpp

If I give lower value to -nsplits, the error was not coming. What does it mean exactly, I didn’t understand it. Please reply to me. Thanks in advance.

Hi,
I am trying to detect numbers from Electric meter reading captured by webcam. For testing I took 20 samples of number ‘6’ and trained them. I created test samples using opencv_createsamples. My classifier is able to recognize the letter 6 for those test samples. But when we create testsamples with createsamples utility, it automatically crops the image and give it to classfier. When we give test samples that are created by our own, ( giving its boundaries as 0 0 width height) then my classfier is not recognizing.

One more point is when I saw the resultant output image, it is showing the sliding window in red color. Although the sliding window falls in correct area of the test image its not recognizing it.

Can anybody help me in these issues. Iam not able to figure it out why that is happening.
Thanks in Advance.

Hi

Is anyone know if it is possible to apply viola-jones face detector on existing images ? Thanks in advance.

Boris

Hi Pouet,

Yes, it is possible. See http://opencv.willowgarage.com/wiki/FaceDetection for more details.

Aleksey

Hello,I really need your help.

My steps as following:

Positive images – about 400 images,every image is 19*19
F:\face\positives
Face000001.pgm
……………………
Face000400.pgm

F:\face\positives\positive_desc.txt
\face00001.pgm 1 0 0 19 19
……………………
\face00400.pgm 1 0 0 19 19

Negative images – about 559 images,every image is 19*19
F:\face\negatives
B1_00001.pgm
……………………
B1_00559.pgm

F:\face\negatives\bk.txt
\B1_00001.pgm
……………………
\B1_00559.pgm

then,i use command

createsamples -info F:\face\positives\positive_desc.txt -vec F:\face\pos.vec -num 400 – w 19 -h 19

this step is ok!

next ,i use command

haartraining -data -data F:\face\data -vec F:\face\pos.vec -bg F:\face\negatives\bk.txt -npos 400 -nneg 559 -mem 15360 -mode ALL -w 19 -h 19

screen apears :

Tree classifiers
1-2-3-4-5

Parent node:5
**** 1 cluster ****
POS:396 400 0.990000

and then, it is stop ,i don’t know why this phenomenon appear.

Im working with OpenCV 1.0 on Windows Server 2003 on a Inter(R) Xeon(R) CPU E5520 @2.27GHz,2.26GHz with 15GB RAM

Hi, Chenwei, please read http://www.computer-vision-software.com/blog/2009/11/faq-opencv-haartraining/ topic. In particular, “Andrey Soldatov Said On 31-03-2010” and “Andrey Soldatov Said On 14-04-2010” posts.

Hello

I got the same problem with Aldariel said on 20-02-2010

I am confused with the performance test.

I used 1000 positives and 2600 negatives for running and after 8 nodes it stopped.

When I try to test my cascade with performance.exe I get nothing. Same happens if I try to use one of the OpenCV implemented haarcascades:

performance.exe -data haarcascade_frontalface_alt.xml -info F:\face\positives\testing.txt

F:\face\positives\test
1.jpg
2.bmp

F:\face\positives\testing.txt
test\12.bmp
test\13.jpg

+================================+======+======+======+
| File Name | Hits |Missed| False|
+================================+======+======+======+
| Total| 0| 0| 0|
+================================+======+======+======+
Number of stages: 22
Number of weak classifiers: 2135
Total time: 0.000000
22
0 0 -1.#IND00 -1.#IND00
0 0 -1.#IND00 -1.#IND00
0 0 -1.#IND00 -1.#IND00

why??

Hi, Chenwei, please, see read my answer ‘Andrey Soldatov Said On 25-02-2010’ to Aldariel. You must use format

[positive filename] [# of objects] [[x y width height] [… 2nd object] …]

for testing.txt. As I can see, you use only file names without description of objects on the image.

i’m researching about facial emotion recognition. i explain use Genetic Algorimth to reduce haar-like feature. Haar-like feature use in object detective is very good, but in “facial emotion recognition” i don’t know how it work? anyone can help me, or suggest me an algorimth better

Hi Vhoangly,

See: Alex said on 27-04-2010 at http://www.computer-vision-software.com/blog/2009/11/faq-opencv-haartraining

Aleksey

I use 3290 positive images and 5940 negative images for training. It takes about 24 hours. but unfornatetly my cascades are inferior to OpenCV’s standart cascades.

Should i normalized the samples before trainning? I wish to get better performance.What should i do??

Any suggestions and comments from you will be appreciated.Thanks !

Hi, Chenwei, could you clarify, what is the problem with your cascade – too many false positives or false negatives? What test content do you use to compare your and OpenCV cascases? About normalization: of course, you should crop objects down to their boundaries, but you must not make precise normalization so that two particular points of the object should be absolutely the same on all samples.

hi Andrey. Could you tell me that whether I should do the Hist Equal on the positive faces (like Mit faces.)

Hi Andrey Soldatov,

My cascade has many false positives.

For instance,I use a image for testing which contains ten faces .OpenCV’s standart cascades can detect ten faces. but my cascades can detect only five faces?

In order to achive high detection rate,what should i do?

Many thanks for your help!

Hi, BTW you have “false negatives” (it means that your cascade says “no face” but it’s wrong).

Try to use more positive samples or change cropping of your positive samples. To choose the direction, you can run OpenCV cascade over your training set. Is its quality good enough? If no, analyze the cause. May be, your positive samples contain non-frontal faces or faces rotated too much. If yes, you will get boundaries of faces (possibly, different from your cropping). Try to train your cascade with your positive samples cropped this way. Sure, it’s a cheat but it’s good way to investigate dependencies of haartraining. If cascade trained on such samples will not be better, you will have to add more various positive samples.

Hi John! I m working on hand gesture recognition…..As u discussed about collecting images of the required object frame by frame from the video. How can i possibly do that ………… if u have the code. thanks

with profound regards!

Hello

I have a general question. Is it possible to create a haar classifier for license plates? I think because of the different numbers and letters it is hard to get good results for detection. I tried also some test with 200 pos but the result was very bad.

Hi Bogus,

Haar detection method (viola&jones) works +-15 degree distortion. If it is ok for you, you could try Viola&Jones. But I don’t belive that it will have great quality by default. Most probably you have to add additional method or heruistics to improve quality of cascade.

Aleksey

Hey Aleksey, thanks for your reply.

What do you mean exactly with the additional methods for the improvement?

hi.do you mean the default x y z is not good enought when i creat sample

Hi Alex!
thanks for the earlier reply ……….. I am applying haar training for various hand gestures detection…….. i apply a 20 stage cascade……….. no. of splits is taken 2……. false alaram rate= 0.5 ……….. my set of positive is images is 2000 n negitve = 500 ………. after executing haartraining……… 14 stages reach in couple hours still after a day it never proceeds beyond 14th stage………………i began the training from start for 3 times bt never worked……… can u suggest wat can be done for successful training ……….. if any parameter values should be changed………….. also symetric or asymetric should be used for hand gestures…………. vl be waiting for ur reply….. thanks

with profound regards!

hello!
can anybdy help………… i am using haartraining for hand gestures detection….. it gives error at 14th stage cascade . the error is “Could not open the file storage. Check the path and permissions” ……… cn some one suggest somethng to proceed………… thanks

with profound regards!

hi!
I am using haar training for hand detection………… I receive the following error………… can anybody help plz ………….

Parent node: 15

*** 1 cluster ***
POS: 1990 2000 0.995000
NEG: 402 1.56032e-007
BACKGROUND PROCESSING TIME: 29801.68
Required leaf false alarm rate achieved. Branch training terminated.
Total number of splits: 0

Tree Classifier
Stage
+—+—+—+—+—+—+—+—+—+—+—+—+—+—+—+—+
| 0| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15|
+—+—+—+—+—+—+—+—+—+—+—+—+—+—+—+—+

0—1—2—3—4—5—6—7—8—9–10–11–12–13–14–15

OpenCV Error: Unspecified error (Could not open the file storage. Check the path
and permissions) in unknown function, file ..\..\..\..\ocv\opencv\src\cxcore\cx
persistence.cpp, line 4765

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application’s support team for more information.

Hello!

I am working on haar training of different hand gestures………… how multiple cascades are loaded into the system simultaneously, and each cascade is responsible for a specific hand posture. Is there anyway to do it……….. plz help me out in this

regards

Hi, Yasir, there is a simple way to use several cascades:

for (int i = 0; i < n; i++) cascades[i] = (CvHaarClassifierCascade*)cvLoad(cascade_names[i]); ... for (int i = 0; i < n; i++) CvSeq* objs = cvHaarDetectObjects(image, cascades[i], ...); You need to do it for each of your cascades. Does not it work for you?

Hi! How can i improve the default-classifier by letting the user on a website (face detection in still images) “say” that a detected face isn’t one so that the algorithm will work better next time? i searched a lot but only found stuff about creating a classifier from scratch.
best regards, Alex

Hello Alex,

The Haar-based classifier training in OpenCV is based on conventional “bulk” AdaBoost algorithm which requires all the positive and negative images in advance. You need to research online AdaBoost methods. Here is a couple of references from the first page of Google result:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.123.8390&rep=rep1&type=pdf
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.98.4662&rep=rep1&type=pdf

We did not experiment with these methods, so can not really tell you much about it, except for this hint.
Good luck!

Best regards,
Sergey

hi
this is atul from india when i am running haarconv dir output.xml 20 20 to change the fille to xml file
i am finding error-:

unspecified error(width must be positive integer and (x+ width) must not exceed window width.(stage 0, 0,node 0,rect 0))
in function cvReadHaarClassifier,..\…\…\src\cvhaar.cpp(1630)

please anyone do help me.. i will be realy very thankful..

Hi, Atul. I believe, you use incorrect (too small) size of sample. You should replace “20 20” with the size used during training.

But another question, for which purpose do you use haarconv? OpenCV creates xml file in the end of training and there is no need to make it manually. Besides, OpenCV package contains convert_cascade.exe if you need to convert temporary results of training to xml to perform some tests while cascade is not ready yet. In both cases of haarconv and convert_cascade you must specify correct size of sample.

Hello,

I’m just wondering that how to interpret the resulting xml-file? There are tags like , , , , , ..

Could you explain me those and the values included?

Tags like “feature”, “rects”, “threshold”, “light_val”, “right_val”…

In general, you need some knowledge about the Viola-Jones object detection algorithm and Haar features. You can start from wiki pages or from http://opencv.willowgarage.com/documentation/c/object_detection.html. There is short description of Haar features. Or read http://research.microsoft.com/en-us/um/people/viola/Pubs/Detect/violaJones_CVPR2001.pdf. But simple description of the parameters is as follows.

‘feature’ – a rule to get one number from multiple points of image. Object detection algorithm gets several (or several hundreds) such numbers from image and then analyzes them to return answer if it can detect the object.

Haar features are calculated based on two rectangles on image (To be more precise, on window of some size got from Viola-Jones algorithm. This size is encoded in xml in ‘size’ field.) as sum of intensity of pixels on each rectangle. Then results for two rectangles are summed with weights (sum = sum1 * weight1 + sum2 * weight2). 5 numbers for each rectangle mean: (x, y, width, height, weight). Pay attention that the coordinates are related to window and not to whole image.

Then the algorithm compares sum with ‘threshold’ and decides if feature is ‘pro’ or ‘con’ to say that an object detected. As a result of the comparison it selects ‘left_val’ or ‘right val’. negative value is ‘con’, positive is ‘pro’.

On each stage the algorithm sums values ‘pro’ and ‘con’ for several features and compares this sum with stage_threshold. If sum is lager than ‘stage_threshold’, window is considered as passed the stage.

If some window passed all stages it passed whole classifier.

hi andrey, please give some more explanation regarding weak classifier and its error calculation ,

ie, the selection of weak classifier, by AdaBoost

then the value of Harr feature can it be -ve or +ve (both)?

thank you in advance

Hi shri, I’m not sure regarding the question. Please, clarify ‘can it be -ve or +ve (both)’. Value of Haar feture can be positive or negative because weight of a rectangle can be positive or negative. After comparison of feature with threshold the algorithm chooses one of positive values: ‘left_val’ or ‘right val’.

Hi, I’m not sure that the “threshold” could be used directly during the comparison, because the value of the “threshold” given in the .xlm file are always much less than 1.
I guess there is some “normalization method” should be applied to the threshold, like the variance of the sub window??
But in fact, I’m not sure……, because I havn’t generate the right result myself yet……

Hey, does anyone knows how to use the xml file threshold values exactly. I am making a Hardware implementation of Viola jones and its very important to know the exact way to use the threshold value.

What i perceive is — Calculate variance – calculate Standard deviation from it – and multiply it with the Threshold and then compare it with the normal feature value

Is it correct or there is something more.. some normalization factor of some sort etc..

sid.

Any answer to Edward Li’s doubt? Anyone please.

Hi Edward,

I’ve the same doubt…
I read that the variance normalization is suggested by Viola and Jones as a mean of reducing that effect of different lighting conditions.
So, for to realize an implementation of Viola and Jones, the threshold value given in the .xml must be multiplied for the variance….

I’m not sure….Someone can explain it better?

hi

some one please tell how to get the threshold and left val and right val as explained by anrey, as am new to haar training.

I’m not sure I understood you. If you just want to use haartraining, all these rules are inside OpenCV algorithm, so you don’t actually need to know anything of them. Please, confirm if you need some more explanation about internals of the algorithm.

thanks for the reply,i got the answer from the function icvCreateCARTStageClassifier which is in cvhaartraining.cpp, ( left val and right val and threshold are adaboost algo dependent)

about the haar feature value: sum of black rectangle value -sum of white rectangle ,

depending on the values the sum will be -ve or +ve.

thanks once again for the reply

Hi all.
Dose anybody build OpenCV with TBB support ?
Dose in work ?
I try but with out any result. I build OpenCV with TBB support, it linked to tbb.dll, but when running OpenCV use only one core and work only with one thread.
Is in possible use multicore when training haar files.

Hi all.
Dose anybody build OpenCV with TBB support ?
Dose in work ?
I try but with out any result. I build OpenCV with ЕИИ support, it linked to tbb.dll, but when running OpenCV use only one core and work only with one thread.
Is in possible use multicore when training haar files.

Hi, the positive images for haartraining can be a large image with the object inside? or positive images only can have the object?

Hi,

I read that the variance normalization is suggested by Viola and Jones as a mean of reducing that effect of different lighting conditions.
So, for to realize an implementation of Viola and Jones, the threshold value given in the .xml must be multiplied for the variance….

I’m not sure….Someone can explain it better?

Hi Andrey:

I’m trying to understand how this can be implemented but I’m not sure how can I do it. I would really appreciate if you could see what I understand and correct me if I’m wrong.

I understand I have to create a predefined set of features lets say 1,000 of them and then, try one classifier per feature so I start selecting which features are the best following ADaboost method.

What I’m not sure is how to apply the feature on the integral image, I mean, once I have integral image I have to divide it in subwindows right?.

If the base would be 20×20. should I have no overlapping windows or should I have as many subwindows as possible??.

For example, my first subwindow would be at coords (1,1,20,20)… then, the second one should be at (2,1,21,20) or at (21,20,40,20) ???

And the last question, once I have my subwindows, how do I apply my features? Should the feature fit into the whole subwindow or it can be smaller? In case it can be smaller, Should I pass it position by position all over the subwindow??

I’m sorry but the document of Viola doesn’t seem too clear to me.

Thanks in advanced

Hi everyone,
I have successfully trained a face detector using Haar feature. Does anybody know how to use LBP feature instead of Haar ? (with openCV, of course). Thanks in advance 🙂

Hello,
Iam new to opencv. My english is poor.@@
I have same problem as Srinivas A said on 15-04-2010

In haartraining some times I get Error: bad flag (parameter or structure field) () in function cvReleaseMat, cxarray.cpp

What does it mean?Why it happened?

Hi, I am going to create my own classifier (human hand). I have prepared about 5000(80×80 in pixel) positive images (trained in base 24 x24), but the performance not so good.

Could you tell me how to enhance the performance? And how many positive and negative training samples is good?

Thanks for your kind attention!

This is probably a stupid question but is it possible to just stop the training at a certain stage and get the reultant xml file from that? I’ve been frozen at Stage 18 for almost two days now. The output has just been stuck at:

Number of features used : 125199

Parent node: 18

*** 1 cluster ***
POS: 3454 3510 0.984046

Any advice would be much appreciated..

Andrey, Alex:
Thanks for the great feedback. I have been following your responses but I am having similar problems as others in training my cascade. I am trying to create a closed fist detector.
1. I have 400 positive and 400 negative images. The both sets are 640×480 VGA images. The positive images have an ROI marked for positive training and specified in the text file. E.g. positives.txt looks like

positives\cube_201.jpg 1 197 306 187 164
positives\cube_202.jpg 1 407 127 192 136
positives\cube_203.jpg 1 413 132 192 134

The negatives.txt looks like

negatives\Negative_1.jpg
negatives\Negative_2.jpg
negatives\Negative_3.jpg

2. To create the .vec file, I use the following syntax with createsamples
opencv_createsamples -vec positives.vec -info positives.txt -num 36 -w 18 -h 18

and then
opencv_createsamples -vec positives.vec PAUSE
to view the vec. The samples looks alright, so the next step is to create the cascade.
3. To create the xml file, I use
opencv_haartraining -data haarcascade -vec positives.vec -bg negatives.txt -nstages 15 -minhitrate 0.9 -maxfalsealarm 0.5 -npos 400 -nneg 400 -w 18 -h 18 -nonsym -mem 1024

However, trainer seems to hang up near node 11 or 12. I remember adding more negative images e.g. 1000 images but it still seems to hangup with something displayed like POS 355 1.0
a. Is there a ratio of pos:neg images to use to avoid hanging up? We tried relaxing the hitrates a bit but then classifiers performs very bad.
b. I also saw in one of the post above that making the size of the negative images larger will help (VGA -> XGA or higher), this doesn’t seem apparent to me.
4. As an alternate solution, I tried the traincascade, so my syntax is
opencv_traincascade -data “C:\Training\T1\casc” -vec positives.vec -bg negatives.txt -npos 400 -nneg 400 -numstages 12 -precalcValBufSize 1024 -precalcIdxBufSize 1024 -w 18 -h 18 -minHitRate 0.99 -maxFalseAlarmRate 0.5 -featureType HAAR
the trainscade not only appears to run faster, it also doesn’t hang up and provides an XML file if it can’t progress in the training anymore. Also, even though I have specified -numstages 12, the trainer still seems to go beyond these stages till 14-15 sometimes. What gives?

Is it better to use haartraining or traincascade to create the xml file? VJ framework is supposed to be really straightforward but I am having a lot of difficulty getting to work. Pls advise.

How can we get or create haar cascade xml file for fruits and flowers

hi.. can you help me to detect complete and extract this body from an image ?

Hello ,
I want to increase the accuracy for gender classification.its hardy 30 to 40 % nw. Atleast I want it upto 80%.
I’m using 112×92 size image in pgm format.
While classifing gender its fluctuating and many time give incorrect result.
And I hav downloaded haarcascade file.
If I trying to change the pixel or hd image it give error “buffer size not matched” something like it.
I dont know much more about it.
Please help me.
What should I do to increase accuracy.??
If u want more details please mail me on swadesh287@gmail.com
I’ll give you details of my project..means what I hav done.

I’m doing this in visual studio.using cpp.
With the help of open cv.

Hi Vasiliy,

I am trying to train my classifier for recognizing food products in images. So far I have created (just for testing purposes) 6 positive images and 2 negative (and whole bunch of different configurations 1:2 and so on). When I run the program from the command line I get an error : Cascade classifier cant be trained. Check the used training parameters. OK so my images all are 20x20pixels, and this is the command line I am using for training :
C:\Users\Thalia\Desktop\klasyfikator\open\opencv\build\x64\vc10\bin\opencv_traincascade.exe -data klasyfajer -vec samples.vec -bg negativeNew.txt -numStages 3 -miniHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 6 -numNeg 2 -w 20 -h 20 -mode ALL -precalcValBufSize 256 -precalcldxBufSize 256 — My computer is 64-bit Windows 8.

I would also like to ask if it is possible to train the classifier to detect different types of food products so for example when it sees tomato it knows it is tomato, when it sees potato it knows it is potato and so on?

i want to know how can i download this software and from where i data can collect for object detection

hey..am using linux for performing haar training…after creatin positive.txt file i tried to create samples by using the command opencv_createsamples -info positive.txt -vec vecfile.vec -w 24 -h 24 ….but itz giving an error like this:
parse errorDone. Created 0 samples
can u plz help me….

Visit my article from here. I mentioned all required steps.
http://thinkingweb.co/opencv-haar-cascade-classifier-training/

why do we require coordinates for testing? shouldn’t it check the entire image and detect the required image?

Write a comment