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

FAQ: OpenCV Haartraining

Posted on : 10-11-2009 | By : rhondasw | In : OpenCV

53

Hi All, before posting your question, please look at this FAQ carefully! Also you can read OpenCV haartraining article.  If you are sure, there is no answer to your question, feel free to post comment.  Also please, put comments about improvement of this post.  This post will be updated, if needed.

Positive images


Why positive images are named so?

Because a positive image contains the target object which you want machine to detect. Unlike them, a negative image doesn’t contain such target objects.

What’s vec file in OpenCV haartraining?

During haartraining positive samples should have the same width and height as you define in command “-w -h size”.  So original positive images are resized  and packed as thumbs to vec file. Vec file has header: number of positive samples, width, height and contain positive thumbs in body.

Is it possible to merge vec files?

Yes, use Google, there are free tools, written by OpenCV’s community.

I have  positive images, how create vec file of positive samples?

There is tool in C:\Program Files\OpenCV\apps\HaarTraining\src createsamples.cpp.  Usage:

createsamples -info positive_description.txt -vec samples.vec -w 20 -h 20

What’s positive description file?

The matter is that, on each positive image, there can be several objects. They have bounding rectangles: x,y, width, height.  So you can write such description info of image:

positive_image_name  num_of_objects x y width height x y width height …

Text file, which contains such info about positive images is called description file. So during vec file generation,  really objects are packed, but not whole image. Essentially vec file is needed to speed up machine learning.

Do I always need description file, even if I have only one object on a image?

Yes, with createsamples you need description file.  If you have only one object, it’s bounding rectangle may be bounding rectangle of whole image. If you want, write your own tool for vec file generation =)

Should lightning conditions and background be various on positive images?

Yes, it’s very important. On each positive image, beside object, there is background. Try to fill this background with random noise, avoid constant background.

How much background should be on positive image?

If you have much background pixels on your positive images in comparison with object’s pixels – it’s bad since the haartraining could remember the background as feature of positive image.

If you don’t have background pixels at all – it’s also bad. There should be small background frame on positive image

Should all original positive images have the same size?

No, original images can have any size.  But it’s important that width, height of this rectangle have the same aspect ratio as -w -h.

What’ s  -w and -h should I put in createsamples? Should it be always square?

You can put any value to -w and -h depend on aspect ratio of the target object which you want to detect.  But objects of smaller size will not be detected! For faces, commonly used values are 24×24, 20×20. But you may use 24×20, 20×24, etc.

Errors during vec file generation: Incorrect size of input array, 0 kb vec file,

-First check you description file: positive_image_name should be absolute path name without spaces like “C:\content\image.jpg” not “C:\con tent\image.jpg” or relative path name.

-Avoid empty lines in description file

-Resolution of original positive image file should be not less, then -w -h parameters you put.

-Check that positive images are available in your file systems and not corrupted.

-There can be unsupported formats. Jpeg, Bmp, PPM are supported!

Example of vec file generation!

Let’s working directory be C:\haartraining. In it there is createsamples.exe. There is folder

C:\haartraining\positives. So create description file positive_desc.txt.

positives\image1.jpg 1 10 10 20 20

positives\image2.jpg 2 30 30 50 50 60 60 70 70

or

C:\haartraining\positives\image1.jpg 1 10 10 20 20

C:\haartraining\positives\image2.jpg 2 30 30 50 50 60 60 70 70

You should avoid empty lines and empty space in image’s path

createsamples -info positive_desc.txt -vec samples.vec -w 20 -h 20


Negative images


What negative images should I take?

You can use any image of OpenCV supported formats, which does not contain target objects (which are present on positive images). But they should be various – it’s important! Good enough database is here

Should negative images have the same size?

No. But the size should not be less than -w -h, which were put during vec file generation.

What’s description file for negative image?

It’s just text file, often called negative.dat, which contains full path to negative images like:

image_name1.jpg

image_name2.jpg

Avoid empty lines in it.

How many negative/positive image should I take?

It depends on your task.  For real cascades there should be about 1000 positive images and 2000 negative images e.g.

Good enough proportion is  positive:negative = 1:2, but it’s not hard rule! I would recommend first to use small number of samples, generate cascade, test it, then enlarge number of samples.

Launch haartraining.exe (OpenCV\apps\HaarTraining\src)


Example of launching

Working directory is C:\haartraining with haartraining.exe tool and samples.vec file.

Let’s negative images are in C:\haartraining\negative, in this case negative.dat should be like this:

negative\neg1.jpg

negative\neg2.jpg

So in C:\haartraining launch this:  haartraining -data haarcascade -vec samples.vec -bg negatives.dat -nstages 20  -minhitrate 0.999 -maxfalsealarm 0.5 -npos 1000 -nneg 2000 -w 20 -h 20 -nonsym -mem 1024

  • w  h  is the same, you put during vec file generation
  • npos nneg  – number of positive samples and negative samples
  • mem – RAM memory, that program may use
  • maxfalsealarm – maximum false alarm, that stage may have. If big false alarm – it could be bad detection system
  • minhitrate – minimal hit rate, that should stage have at least
  • nstage – number of stages in cascade

What’ s falsealarm and hitrate of stage?

You should read theory of adaboost about strong classifier. Stage is strong classifier. In short:

  • For example you have 1000 positive samples. You want your system to detect 900 of them. So desired hitrate = 900/1000 = 0.9. Commonly, put minhitrate = 0.999
  • For example you have 1000 negative samples. Because it’s negative, you don’t want your system to detect them. But your system, because it has error, will detect some of them. Let error be about 490 samples, so false alarm = 490/1000 = 0.49. Commonly,put false alarm  = 0.5

Are falsealarm and hitrate depend on each other?

Yes, there is dependency. You could not put minhitrate = 1.0 and maxfalsealarm = 0.0. .

Firstly, the system builds classifier with desired hitrate, then it will calculate it’s falsealarm, if the false alarm is higher than maxfalsealarm, the system will reject such classifier and will build the next one. During haartraining you may see such:

N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
+—-+—-+-+———+———+———+———+
| 0 |25%|-|-1423.312590| 1.000000| 1.000000| 0.876272|

HR – hitrate

FA – falsealarm

What’s falsealarm and hitrate of whole cascade?

Cascade is linked list (or three) of stages. That’s why:

  • False alarm of cascade = false alarm of  stage 1* false alarm of  stage 2* …
  • Hit rate = hitrate of  stage 1 * hitrate of stage 2* …

How many stages should be used?

  • If you set big number of stages, then you will achieve better false alarm, but it will take more time for generating cascade.
  • If you set big number of stages, then the detection time could be slower
  • If you set big number of stages, then the worse hitrate will be (0.99*0.99*… etc). Commonly 14-25 stages are enough
  • It’s useless to set many stage, if you have small number of positive, negative samples

What’s weighttrimming, eqw, bt, nonsym options?

Really all these parameters are related to Adaboost, read theory. In short:

  • nonsym – If you positive samples are not X or Y symmetric, put -nonsym, -sym is default!
  • eqw – if you have different number of pos and neg images, it’s better to put no eqw
  • weighttrimming – for calculation optimization. It can reduce calculation time a little, but quality may be worse
  • bt – what Adaboost algorithm to use: Real AB, Gentle AB, etc.

What’s  minpos, nsplits, maxtreesplits options?

These parameters are related to clustering. In Adaboost different week classifier may be used: stump-based or tree-based.  If you choose nsplits > 0, tree-based will be used and you should set up minpos and maxtreesplits.

  • nsplits – minimun number of nodes in tree
  • maxtreesplits – maximum number of nodes in tree. If maxtreesplits < nsplits,  tree will not be built
  • minpos – number of positive images, that can be used by one node during training.  All positive images are splitted between nodes. Generally minpos  should be not less than  npos/nsplits.

Errors and stranges during haartraining!

  • Error (valid only for Discrete and Real AdaBoost): misclass – it’s warning, but no error.  Some options are specific to D and R Adaboost.  So your haartraining is ok.
  • Screen is filled with such | 1000 |25%|-|-1423.312590| 1.000000| 1.000000| 0.876272| – your training is cycled, restart it. First column should have value < 100
  • cvAlloc fails. Our of memory – you give too much negative images or sample.vec is too big. All these pictures are loaded to RAM.
  • Pay attention you put the same -w and -h, as during vec file generation
  • Pay attention, that number of positive samples and negative samples, you put in -npos -nneg are really available
  • Avoid empty line in negative.dat file
  • Required leaf false alarm rate achieved. Branch training terminated – it’s impossible to build classifier with good false alarm on this negative images. Check your negative images are really negative =),  maxfalsealarm should be in [0.4-0.5]

OpenCV XML haarcascade


During haartraining, there are txt file in haarcascade folder, how can we get XML  from them?

There is OpenCV/samples/c/convert_cascade.c. Use like:

convert_cascade –size=”20×20″ haarcascade haarcascade.xml

How can I test generated XML cascade?

 There is OpenCv/apps/HaarTraining/src /perfomance.cpp. You need have positive images(not used during training) and positive description file.  Use like:

performance -data haarcascade -w 20 -h 20 -info positive_description.txt -ni

performance -data haarcascade.xml -info positive_description.txt -ni

Time and Speed of haar cascade generation


Average time to generate cascade on PC?

It depends on task and your machine.  I generated cascade for face detection, for this used such parameters: -nstages 20 -minhitrate 0.999 -maxfalsealarm 0.5 -npos 4000 -nneg 5000 -w 20 -h 20 -nonsym -mem 1024.  It took 6 days on Pentium 2.7GHZ 2GB RAM.

What is OpenMP?

The OpenMP (Open Multi-Processing) is an application programming interface (API) that supports multi-platform shared memory multiprocessing programming in C, C++ and Fortran on many architectures, including Unix and Microsoft Windows platforms“. If you have MT processor, you can use it.  In code you should add OpenMP defines and put compile options.  For example in VisualStudio2005: Properties->C/C++->Language->OpenMP support

Is it possible to improve speed of haartraining?

Yes, one of possible ways is to use parallel programming. We have realized OpenCV haartraining using MPI for linux cluster. You can read it here

Object detection with OpenCV XML cascades


Is it possible to detect rotated faces?

Yes. It is impossible to generate cascade, which can detect face in all orientations. But you can generate cascade for each orientation separately. For this you need positive content of rotated faces. You can try to generate cascade with OpenCV , add -mode ALL, with it tilted haar feature will be used. But it’s badly implemented, at least in OpenCV 1.1. If you want you can add your own feature to opencv haartraining – it’s not too hard.

Another approach is to write head pose estimator. Then rotate your pictures, so that you have frontal face and detect it with OpenCV default face cascade

Is it possible to recognize gender, attention, race with  Haar features?

We tried, but could not do it with OpenCV haartraining. That’s why for such classification, we used our own gender and attention classificators. Of course you can use Adaboost for this task, which is implemented in haartraining, but we did not get good results.

Is it possible to detect faces in real time?

Yes.  On PC default OpenCV facedetector takes about 200 ms for 640×480 picture, about 5fps – it’s not real time. We have changed facedetector and get about 15 fps – which is real time. You can see results  here and here

Comments (53)

Hi, first of all, thanks for this information, it’s really useful and explains a lot, my question it’s about the performance tool. you see, i know how to use it but my doubt is in the later table for the ROC plot, i know that the column 3 it’s the hit rate and its rank goes from 0 to 1 always (where 0 is bad and 1 its great!), and the 4 column it’s the false alarm rate but what is his rank??

Thanks for your help

how to train on Linux?

If you have compiled linux version of opencv_haartraining, use it with the same parameters as windows version.

hello,

can I use two xml files at the same time?
one xml is use to detect face, one xml is use to detect hand
can my program detect these two things concurrently?

thx

Hi, unfortunately, there is no code in OpenCV for two concurrently executed cascades. You could easy implement two threads for executing cascades concurrently, though.

yes,of course. but u have to change the sample codes a little bit :)

Hi..I’ve a problem with createsamples. I’ve made directory “haartraining” as you show in your example. In this directory there are:

* createsamples.exe

* positives —-> it is a directory in wich there are png files of my object I want to detect. All images are 120 x 150 pixels. Each image is named as “hand (1).png”

* positive_desc.txt —> positives\hand (1).png 1 0 0 120 150
positives\hand (2).png 1 0 0 120 150
becouse each image contains only the object I want to detect.

So, when I run createsamples -info positive_desc.txt -vec samples.vec -w 20 -h 20

command prompt show this result:
info file name:
vec file name : samples.vec
BG file name:
num: 1000
BG color: 80
invert: FALSE
max intensity deviation: 40
max x angle: 1.1
max y angle: 1.1
max z angle: 0.5
show samples: False
scale: 4
width: 20
height:20

Windows Vista throws a message like this: ” createsamples.exe has terminated…Windows: There is a problem that prevents the proper functioning of the program”

Can you help me?

Thanks

What version of OpenCV do you use? With versions 1.1 and 2.0 it’s impossible to get “scale: 4” line in response to “createsamples -info positive_desc.txt -vec samples.vec -w 20 -h 20” because of source code:


if( showsamples )
{
printf( "Scale: %g\n", scale );
}

So, you will see “Scale: 4” (not “scale: 4”) only if you use “-show” parameter with createsamples.

Hai, i’m riki, Mr Andrey, is it possible to make a personal_frontal_face.xml that generates from my face only, so when it is applied, it will detect my face only, not any one else, so it would be a smart face verification apllication. Is it possible..?, if yes, how to make it…?

Hi, Riki, it’s possible, but you have to provide haartraining with number of negative samples containing faces of other people. Original algorithm of opencv’s haartraining automatically crops and resizes negative images (for example landscapes without faces) to get negative samples (images with size about 20×20 like positive samples). It gets hundreds of millions of negative samples for several thousands of positives. In your case you need 1) to prepare negative faces-samples manually
2) to modify haartraining code to use negatives samples instead of automatic processing of negative images. Of course, you will not be able to prepare 100000000 faces of “not-you”, so you will not be able to get 20-stages cascade. But, I think, you can build several stages and check the result.

After that you will need to execute your “personal” cascade only on windows which passed general face detection cascade (or merge these two cascades).

Hi..I wanted to add some more features for haar training. But i am not sure where to add.. is adding another cvHaarFeature() in icvCreateIntHaarFeatures() the right way?

Very good material! Thank You!
Now my question: I’m understood this phrase –
“No, original images can have any size. But it’s important that width, height of this rectangle have the same aspect ratio as -w -h”
- that “this rectangle” is rectangle about recognizing object. Is this right?
I’ve found answers for all my questions but this…(

PS: I’m sorry, my English is not good :-[

For training we supply number of positive images, cropped to remove extra background down to boundaries of object. Cropped positive pictures are marked by surrounding rectangle (position and size of this rectangle is saved in positive images list). When you make this markup, you have to retain aspect ratio. Haartraining application will scale your positive images to size of (w,h) and this process must not disturb proportions of object.

Hi

My problem is that I get while executing Haartraining, I get a ,xm. file but its not able to detect anything.

While training I start getting message “Premature end of JPG file” and training ends around stage 7 with the message “Branch training terminated”

Any help pleaseee

Thanks

Hi,

It is an excellent blog for opencv.

I have a question about the training data file.

Following link is another opencv realized with PHP.

http://www.svay.com/blog/index/post/2009/06/19/Face-detection-in-pure-PHP-%28without-OpenCV%29

My question is that if we can convert the opencv data file to detection.dat.

Thanks

I’ve looked at the article and believe we could develop a tool for converting detection.dat to opencv xml and vice versa.
If you are interested in such program/script please feel free to contact our sales/marketing team (consult About page for more info).

Hi,
I’m just wondering if somebody else also encounters endless loops in haar training (OpenCV 1.0 and 2.0 on 64bit Linux). I tried to increased my training data (>2000 pos and >2000 neg samples) but after some hours nothing happens anymore.
The output looks like this:

Parent node: X

*** 1 cluster ***
POS: 2754 2768 0.994942

The “NEG” line never shows up after ‘n’ stages (n~8 of 15) … I have an instance running for ~1 week now other look like that too. Any hints what happened? Will it terminate if a certain falsealarm rate cannot be achieved or will it try again and again and thus ending up in an endless loop?
Thx and greetings,
Andreas

Andreas, yes, endless loop happens if haartraining cannot extract enough negative samples (small images) from your negative images. Try to replace negative images with others of bigger size or more multifarious. You can stop training, change images and restart training. It will continue from the last successful stage.

Thanks for your answer. All of my positive and negative samples have the same size 18×18. Can I add negative images with different dimensions to finally finish training?

I have a problem when training a cascade of classifier to detect an object which is the letter E. I started with a 70 samples positive set and 300 negative samples. the result was not satisfying since my detector sometimes detect black or white regions. I have the same question of Andreas. In my negative set, may a include images of arbitrary size, or i should resize all images to -w -h of the detection?

Hi, Lara45. The algorithm requires big negative images, the bigger the better (for example 1280×1024 for positive samples 20×20), don’t use images of size –w –h – it will not work. Haartraining will automatically extract millions of small negative samples from your negative images, so it need images with millions of subregions.

I would like to know if it’s possible to have haarcascade XML generator running on Mac OSX.

Greetings,

Rui Sobral

Hi, i want to thank you for not answer my question, i dont know why you dont want to answer it

Hi Andrey,
Thx for reply. Do u know any source where i can download my negative images instead of wasting time downloading each one alone. I tried http://tutorial-haartraining.googlecode.com/svn/trunk/data/negatives/ but still having problems.
Just one more question, for my positive samples, i constructed them by hand and created the vector file of -w 10 -h 15 (the code indicates that those are distorted when processed). First i tried to not include a lot of background edges with the letter, it didn’t work (bad detection), then i included edges for bg, the performance still not satisfying me :( . Any suggestion???? since unlike faces, this letter (E) presents concavity then features will be aplied on a portion of the background while processing.
Thx

One more question, I have to know what does -nneg and -npos refer to in the call for opencv_haartraining function,

Thx

hi, pls explain this

— Should all original positive images have the same size?
No, original images can have any size. But it’s important that width, height of this rectangle have the same aspect ratio as -w -h. —

does it mean that original image must be a square if -w and -h in createsamples is 20×20 ?

I think it mean all original pos sample have the same aspect ratio
ex: 20*20 = 30*30 = 40*40 =>the ratio is 1:1
20*40 = 40*80 = 80*160 =>the ratio is 1:2

one more q. — How much background should be on positive image? —

i have original image with face and some background.

then i make positive_desc.txt file were i crop face with bounding rectangles ( for exapmle img\image1.jpg 1 10 10 200 200 )

so, i want to know — must be some background only in original image?

or i must crop face and some background with bounding rectangles ( for exapmle img\image1.jpg 1 0 0 210 210 )?

tnx.

Hi. I wanna create a database for smile detection. For this purpose, should I include non-smile mouth images in negative images set?
Thanks.

Hi Reisanibal,

I don’t think that haar training is the best approach for this task. Smile and none-smile are too similar classes. You could have a lot of false positives with Viola-Jones approach.

Aleksey

Hi, thanks for the reply. Could you suggest a better approach for smile detection than haar training?
Thanks again.

I had a question, why should time is double each stage when executed “haartraining.exe”.

hello ! I had created my classifier,but when I wanted to run it I get strange Error massage :”OpenCV Error: Unspecified error (width must be positive integer and (x + width)
must not exceed window width. (stage 0, tree 0, node 0, rect 0)) in cvReadHaarCl
assifier, file ..\..\..\src\cv\cvhaar.cpp, line 1988″
please help me …

xml of cascade has sx sy and <_>a b c d e parameters. In this example (a+c) must be < = sx and (b+d) must be <= sy. The error, you mention, appears if (a+c) > sx. Of course, any valid cascade meets these conditions. Are you sure you have valid cascade? You can check xml manually.

Hello,
for train a Haarcascade I need the positive.vec file (created from the positive.txt) and the negative.txt description file.
Am I right?

Now I would like to create a vec file from more than 1000 positive images. The createsamples utility just creates a vec file for a maximum of 1000 samples. Is it possible the create a vec file with more than 1000 samples?
Cheers,
Henner

Try ‘-num 2000′ parameter. 1000 is just default value.

Of course … I didn’t notice this parameter.
Thank you Andrey

Second question:
Whats the difference between haartraining and traincascade?
Is it true that traincascade needs the output from haartraining as input?
First I thought they have the same usage …
So long

haartraining is legacy from OpenCV 1 and traincascade is new object-oriented implementation with c++ functions of OpenCV 2. There are some differences in format of intermediate files (and bugs), but they are almost the same.

Are there any differences between the implementation of the cascade (output) from OpenCV 1 and OpenCV 2?
In my first program I implemented the haarcascade.xml from OpenCV 1 … it runs very good. Yesterday I wanted to implement the cascade.xml from OpenCV 2 … I just got an OpenCV GUI Error message … “Unspecified error (The node does not represent a user object (unknown type?) in function cvRead, .\cxpersistence.cpp(5061)”
Is it generally possible to generate a cascade with OpenCV 2 but use it for OpenCV 1?

I found an example program on http://opencv.willowgarage.com/wiki/FaceDetection
but I didn’t get it started. It compiles and builds with no errors and no warnings. I just got the message “Usage: facedetect –cascade=\”\” [filename|camera_index]“.
Didn’t he find my webcam?

OpenCV 1 and 2 use same format of cascades. “The node does not represent a user object” appears if you don’t prepare FileNode when call cvRead. Do you call cvRead in your program? Could you share part of your code where you declare variables for this function?

“Usage: facedetect cascade=” appears if you don’t add “–cascade=”your_cascade.xml”" parameter when you start this sample. What command do you use to start the sample?

EDIT (I was not exactly right with my answer): OpenCV 2 added cv::HaarClassifierCascade class in addition to cvLoadHaarClassifierCascade and cvHaarDetectObjects functions. This class works with the same xml cascades as legacy functions. These cascades can be trained with haartraining application.

But besides, OpenCV 2 added class CascadeClassifier which works with xml of different format and has slightly different functionality (they added other features except haar and removed some flags of detection). These cascades can be trained with traincascade application.

New-style CascadeClassifier can load old cascade but in this case it’s only wrapper for old-style functions. If new-style cascade is loaded, CascadeClassifier will treat it by its own new code.

1.
Hey Andrey, I tried to solve the problem with creating an image and release it afterwards, but it doesn’t work:
IplImage* temp = cvCreateImage(cvSize(8,8), IPL_DEPTH_8U, 1);
cvReleaseImage(&temp);

It seems to be a bug (see these links):
http://www.openframeworks.cc/forum/viewtopic.php?f=10&t=1853
http://opencv-users.1802565.n2.nabble.com/face-detection-cvLoad-td4467872.html

The error appears by loading the cascade:
CvHaarClassifierCascade *cascade;
char *cascadeName = “haarcascade.xml”;

// load the classifier
cascade = ( CvHaarClassifierCascade* )cvLoad( cascadeName, 0, 0, 0 );

// initialize memory buffer for the face detector
storage = cvCreateMemStorage( 0 );
cvLoads loads object from file. It provides a simple interface to cvRead. After object is loaded, the file storage is closed and all the temporary buffers are deleted. Thus, to load a dynamic structure, such as sequence, contour or graph, one should pass a valid destination memory storage to the function.

p.s. What means FileNode? :[

2.
I don’t use any command, because the console close after compiling the program.

2.
facedetect.exe –cascade=”haarcascade.xml”

I got it and it works ^^

1.
It seems to be a bug … see these links
http://staff.science.uva.nl/~rvalenti/index.php?content=projects
http://opencv-users.1802565.n2.nabble.com/face-detection-cvLoad-td4467872.html

I tried to create a image and release it afterwords, but it did work =(

hi!
I am using haar training for various hand gestures detection………… I receive the following error………… can anybody help plz …………. I have positive images = 2000 and negative images = 500

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.

Normaly the program ends and creates the output haarcascade.xml file, if it oversteps the false alarm rate… It seems that the program can’t create this haarcascade.xml file.

Your directory structure should loks like this:
…/haarcascade/
0/AdaBoostCARTHaarClassifier.txt
1/AdaBoostCARTHaarClassifier.txt
2/AdaBoostCARTHaarClassifier.txt
3/AdaBoostCARTHaarClassifier.txt
4/AdaBoostCARTHaarClassifier.txt
5/AdaBoostCARTHaarClassifier.txt
6/AdaBoostCARTHaarClassifier.txt
7/AdaBoostCARTHaarClassifier.txt
8/AdaBoostCARTHaarClassifier.txt
9/AdaBoostCARTHaarClassifier.txt
10/AdaBoostCARTHaarClassifier.txt
11/AdaBoostCARTHaarClassifier.txt
12/AdaBoostCARTHaarClassifier.txt
13/AdaBoostCARTHaarClassifier.txt
14/AdaBoostCARTHaarClassifier.txt
15/AdaBoostCARTHaarClassifier.txt
…/haarcascade.xml

http://opencv.sourcearchive.com/documentation/1.0.0-6.1/cxpersistence_8cpp-source.html

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

I got an OpenCV GUI Error message … “Unspecified error (The node does not represent a user object (unknown type?) in function cvRead, .\cxpersistence.cpp(5061)”
how can i get rid of this problem plz ??+ Ididn’t call cvread before

Could you clarify, do you use sample program from OpenCV (haartraining.exe for example) or write your own program. Please, provide command line in 1st case and part of your code with call of cvRead or cvLoad or .load and declaration of its arguments in 2nd case.

Bob,

I suspect you encounted the issue with non-initialization of static haar_type variable inside harr.cpp. During initialization of haar_type variable, some important information is registered, that is used later to help parse XML file during cvLoad call. Depending on OpenCV version, operation system and static vs dynamic library linkage, it might happen that this static variable is not initialized before cvLoad is invoked, and then you may get this error.
To resolve the issue, you need to invoke some function in object detection library *before* invoking cvLoad for haar cascade file. This forces initialization of all static variables including haar_type.
cvReleaseHaarClassifierCascade with pointer to empty cascade worked fine for me.

CvHaarClassifierCascade * cascade = 0;
cvReleaseHaarClassifierCascade(&cascade);
cascade = (CvHaarClassifierCascade) cvLoad(path);

Best regards,
Sergey

Hi all!!!

I implemented a face recognition system based on OpenCV HaarCascadeClassifier and eigenfaces. Now I want to review the code and use new functionality of OpenCV.

I start to read and I found the next text:

flags – This parameter is not used for new cascade and have the same meaning for old cascade as in function cvHaarDetectObjects.

It’s mean that cascades trained with the new traincascade app doesn`t supprot this flags? Some of them are very usefuls sometimes.

Thanks for your answers!

Unfortunately, you are right, cv::CascadeClassifier with cascade trained by traincascade doesn’t support these flags. As sample cascades provided by opencv are in “old” format, I believe it’s better to use haartraining with cvHaarDetectObjects or cv::HaarClassifierCascade::detectMultiScale (its OOP form) if you needn’t new features of “new” cascades.

Write a comment