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

294

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 (294)

Hello there. First of all, thanks for the article. However, I have a few questions regarding HaarTraining. When using the createsamples.exe, we need to create a document that contains all the image files. Then, do we need to specify our area of interest in the file itself? For example, I create a positives.txt. Then, in the the file should I write:

//image.jpg 1 140 100 45 45

So if I set up everything in C:/Temp, then the command should look like:

C:/Temp/positives/image.jpg 1 140 100 45 45

Am I correct?

Any help would be very much appreciated.

Sincerely,
Nicholas Nuing

Yes for haartraining you need create positive.vec file, containing positive images thumbnails!

There are 2 ways:

1) Create vec file from one image using
createsamples -img face.png -num 10

This method will take face.png and start changing this picture: illumination, distortion, angles… So you will have 10 new positive pictures from face.png

image1.jpg 1 140 100 45 45
image2.jpg 1 100 200 25 35 // one face on picture with rect coordinates
image3.jpg 2 110 90 45 45 410 390 25 35// 2 faces on one pictures

createsamples –info positive.txt

In this case, rectangles will be cropped from images and will be packed into vec file.

2) Create vec file from many positive images.
For this purpose you need positive.txt, containing

while using createsamples i am not able to generate
.vec file i need the information about positive.txt and negative.dat i.e where i have to place positive images, negative images , positive.txt and negative.dat files and how to create positive.txt and negative.dat.
i tried createsamples it is giving error like incorrect size of input array(no positive rows or cols) otherwise
it is generating .vec file with 0kb size i.e empty .vec file

There are 2 ways to generate vec file using createsamples.exe

1) You take one positive cropped img1.jpg for example:
createsamples -img img1.jpg -num 10 -bg negatives.dat -vec samples.vec -maxxangle 0.6 -maxyangle 0 -maxzangle 0.3 -maxidev 100 -bgcolor 0 -bgthresh 0 -w 20 -h 20

negatives.dat – is just list of negative images like:
negative/negimg1.jpg
negative/negimg2.jpg

2) You take several positive images. In this case you need to create description file positive.txt like:
[positive filename] [# of objects] [[x y width height] [… 2nd object] …]
[positive filename] [# of objects] [[x y width height] [… 2nd object] …]
[positive filename] [# of objects] [[x y width height] [… 2nd object] …]

createsamples –info positive.txt -vec samples.vec -w 20 -h 20

we r placing positive images in one folder with name positivecars and negative images in another folder with name negativecars .
we create positive.txt like
positivecars/pos1.png 1 100 40 99 39
positivecars/pos2.png 1 100 40 99 39
.
.
.
.
we create negative.dat like
negativecars/neg1.png
negativecars/neg2.png
.
.
.
.
we placed positive.txt,negative.dat,positivecars and negativecars in c:/programfiles/opencv/bin

in command prompt we give
c:/progarmfiles/opencv/bin>createsamples -vec samples.vec -info positive.txt -w 20 -h 20

then we got the error as

“Incorrect size of input array(non-positive cols or rows) in function cvInitMatHeader,c:\user\vp\opencv\cxcore\src\cxarray.cpp(182)”

if u have any other solution to detect the objects
please send me the detail information to my mail or this blog
thank u in advance i hope u can solve my problem

after haartraining we r getting text files with XML code .
for each and every image we r getting individual text file with XML code . can we merge those text files are not . if yes wat is the procedure . if no how do i get single XML file for all the images
. give me the procedure

Hello, Anusha!

Did you successfully create the xml haar file for cars detection? If yes, could you send in to me on oleynick.igor (at) gmail.com?

Hi
I am working on Opencv haartraining for hand shape identification and I can not even identify object in positive images used for training.

I have followed the following steps:

1) I Created a folder “temp” under c: and then two other folders namely positives and negatives under temp folder
i.e, the path of temp is c:\temp
the path of positives is c:\temp\positives
the path of negatives is c:\temp\negatives
2) Placed 4 of my positive images in a folder called rawdata and placed that folder inside the folder positives .
i.e, the path of rawdata is c:\temp\positives\rawdata

3) Placed 7 negative images in the negatives folder

4) created a batch file “create_list.bat” in the negatives folder which contains the following line:

dir /b *.bmp > infofile.txt

5) Double clicked on the bat file.
infofile.txt is created and contains lines like the following lines:

image2619.BMP
image2620.BMP

6) Copied performance.exe, createsamples.exe and haartraining.exe from the bin folder of Opencv folder

copied all .dll files from the bin folder of Opencv and pasted them in
(i) temp folder

(ii) in temp\positives folder

(7) pasted objectmarker.exe in positives folder and also pasted the .dll files associated with objectmarker.exe in the positives folder

(8) Double clicked on objectmarker.exe and marked objects of positive images one by one.

The following keys were used:
save added rectangles and show next image
exit program
add rectangle to current image
any other key clears rectangle drawing only

info.txt file is created with following content

rawdata/1.bmp 1 39 68 94 123
rawdata/2.bmp 1 70 55 74 112
rawdata/3.bmp 1 27 47 71 114
rawdata/4.bmp 1 39 59 59 86

(9) in command line the following commands were given

c:\> cd temp
c:\temp> createsamples.exe -info positives/info.txt -vec data/positives.vec -num 1 -w 24 -h 24

positives.vec file got created in data folder

(10) in command line the following command is given

haartraining.exe -data data/cascade -vec data/positives.vec -bg negatives / infofile.txt -npos 4 -nneg 7 -nstages 20 -mem 1000 -mode ALL -w 24 -h 24 -nonsym

The last few lines of output looks like…………….

Precalculation time: 0.03
+—-+—-+-+———+———+———+———+
| N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
+—-+—-+-+———+———+———+———+
| 1|100%|-| 1.000000| 1.000000| 0.000000| 0.000000|
+—-+—-+-+———+———+———+———+
Stage training time: 0.00
Number of used features: 1

Parent node: 7
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+—+—+—+—+—+—+—+—+—+
| 0| 1| 2| 3| 4| 5| 6| 7| 8|
+—+—+—+—+—+—+—+—+—+

0—1—2—3—4—5—6—7—8

Parent node: 8

*** 1 cluster ***
POS: 1 1 1.000000

(11) folder 0,1,..,8 are created in side the data/cascade folder and each folder contains a file

AdaBoostCARTHaarClassifier.txt

(12) copied haarconv.exe file and pasted them in temp file

(13) in command line the following command is given

c:\temp>haarconv.exe data/cascade output.xml 24 24

output.xml file gets created..

But when I am trying to use this xml file to detect object it is not working at all..

Thats why I felt that I must have done something wrong while following the above steps

I shall be really grateful to u if U kindly go through my text and let me know where I have gone wrong…

One more thing that I want to know is about the sample size….what does it actually mean??

Hello Vasiliy Mun,

First of all thank you for your blog. I am working on training haar classifier for hands. I had the images database and the info file of the positive and background files. But I have two problems:
1. Is it like that we should create vec files for evry image individually and merge them?
2. How to create the negative image description .dat file (I didn’t understand that part in your blog).

Thank you,

Regards,
Prathik

1) Negative.dat – is just text file with
neg_image1.jpg
neg_image2.jpg

You can create it like
Windows: dir /b /s > negative.dat. You should be in directory with images
Unix: find [image dir] -name ‘*.[image ext]’ > negative.dat

2) if you have many positive images, you should have positive.txt with(description of rectangles, containing faces on this images)
pos_image1.jpg 1 140 100 45 45
pos_image2.jpg 1 100 200 25 35 // one face on picture with rect coordinates
pos_image3.jpg 2 110 90 45 45 410 390 25 35// 2 faces on one pictures

and use this command createsamples –info positive.txt

3) you can create vec file one by one and then merge them. I have tool to merge vec file.

Thank you for your reply…I have no problem with the positive images… I created positive vec files… but the problem i had is when I created the .dat file for negative images it says cant read the negative images… I don’t understand why it says so… I am more than happy if you help me out in this issue… by the way what is the tool you are using for joining the vec files… i am using the one in this link http://note.sonots.com/SciSoftware/haartraining/mergevec.cpp.html#m17ed6bb… once again thank you very much for your reply…

1) This mergevec is ok.
2) Error occured because during haartraining, program reads negative file from negative.dat file and try to load image using cvLoadImage( URI ),
-negative.dat file should contain absolute full path to files like
C:\content\…..
or
– relative path if images and negative.dat in the same directory as program.

Hello,

I got it working… Thank you…

I am working on training haarclassifier for different objects. i started to train cars first while using createsamples i am getting error like incorrect size of input array(non positive rows and cols) or it creates .vec file with 0kb i.e empty .vec file
I am using .png images for trainging
I need information that where to place the folders contain positive and negative images, where to place positive.txt and negative.dat and how to create positive.txt and negative.dat

Hi Anusha,
Put to folder with program negative.dat and positive.txt.

1) Negative content can be anywhere, it will be described in negative.dat. Negative.dat is just list of negative images. It can be created in WinShell
dir /b /s > negative.dat. In Unix find [image dir] -name ‘*.[image ext]’ > [description file].

2) positive content can also be anywhere. Positive.txt is also list of file with metainfo about objects( in your case cars )

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

It’s usually created manually or if you cropped frame by frame from video file with cars you can automatize this process.

Hello all,

Is there any haartrained gender classifier available that can be used. If not please explain the steps involved in approaching the gender classification problem of facial images (20×20) with either Adaboost haar classifiers or SVM based classifers.

Thank you for the reply and have read the blog also.
I have some questions
1] Can we do haartraining of a gender classifier with females as positive images and male as negative images using the opencv haartraining tools and if so would it be atleast 80% accurate.
2] Which is the best approach for gender classification? please provide steps
3] What is meaning of extraction of haar like features from a human face and performing the decision routines on it , could you elaborate on it more?

1) Hello, I was one of 2, who has developed gender classifier. Of course you can use haar features and train with female as negative and male as positive or vice versa. But you will have problems with illumination and background. So your method will work on images, which are close to training samples. But on real video, it’s hard to reach 80%

2) we use SVM and load to it 100 features. This features are selected with Adaboost from 100000 of features. It’s not haar features, it another one.

Hi,

We are building an metrics system which requires camera capture and detecting faces, their gender and also face recognition and tracking. Believe you have all the components we are looking for. Is it possible to get a demo version of your software so that we could see how it works integrated with our system?

hi,
i wanted to know that how opencv has saved the list of (all possible) haar features for a 24*24 subwindow. in what format (is it a text file or an xml file) and in which directory.
from where can i get an exhaustive list of haar features?
is there a formula or programming routine that can generate all the possible haar features for a 24*24 subwindow.

There is programmin routine – icvCreateIntHaarFeatures.

Hello Once again,

As I mentioned on the previous post… I tested training hand classifier with some low resolution images it gave me a classifier… but now I am taking some large images with resolutions varying from one image to another… but this is taking too long for me… I am doing my first stage I ran it for almost 6 hours

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

and it is still continuing… is it like that it takes lot of time or am I going in a wrong way…

please let me know, I have no clue and I am stuck up at this step….

Thank you.

Something is wrong unless you use Pentium 3 =) with 512 mb of RAM =))

1) Positive images e.g. with hands should be with the same resolution and be packed to vec file

2)If you use many negative images( > 1000 images ), you should run program with 1GB.

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

and FA = 1.000 – false alarm means that program could not find good features.

Also there is bug in OpenCV implementation with endless loop, but it is not your case.

3) check that your filesystem is ok also. Could you pause program and see when it is now ?

Hi!

You mentioned about endless loop bug in OpenCV implementation. Can you write something more about it ?

I’m traing to train cascade for car detection and haartraining looped at seventh satge:
+—-+—-+-+———+———+———+———+
| N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
+—-+—-+-+———+———+———+———+
| 1|100%|-|-0.825302| 1.000000| 1.000000| 0.077048|
+—-+—-+-+———+———+———+———+
| 2|100%|-|-1.641505| 1.000000| 1.000000| 0.077048|
+—-+—-+-+———+———+———+———+
| 3|100%|-|-1.066380| 0.999641| 0.666698| 0.210608|
+—-+—-+-+———+———+———+———+
| 4| 71%|-|-1.582837| 0.999641| 0.666698| 0.208983|
+—-+—-+-+———+———+———+———+
| 5| 59%|-|-1.032772| 0.999282| 0.518605| 0.209500|
+—-+—-+-+———+———+———+———+
| 6|100%|-|-1.032772| 0.999282| 0.518605| 0.209500|

+—-+—-+-+———+———+———+———+
| 128|100%|-|-1.032772| 0.999282| 0.518605| 0.209500|
+—-+—-+-+———+———+———+———+
| 129|100%|-|-1.032772| 0.999282| 0.518605| 0.209500|
+—-+—-+-+———+———+———+———+
| 130|100%|-|-1.032772| 0.999282| 0.518605| 0.209500|
+—-+—-+-+———+———+———+———+

Can somebody tell me how to solve this problem ?? I restarted proccess of training and recieved the same result – looped 7th stage.

There are many simple workarounds of the problem to limit number of classifiers in a stage, for example add condition “seq->total < 50” to do-while loop in icvCreateCARTStageClassifier in cvhaartraining.cpp (It’s acceptable to finish the stage with FA = 0.518605, as in your example). Unfortunately, if endless loop takes place, it may mean some algorithmic problems with your samples or parameters. Your task can be too complex for the algorithm. So, may be, it’s better to replace negative samples with other pictures, to try other parameters of haartraining or to increase number of positive and negative samples.

Ya I gave different resolutions for the positive images, which is a worng assumption… I took the images with same resolution know… its working..

Thank you for ur quick replies… I will lwt u know if i have any issues… thank you once again…

Hi!

I’m trying to work with the haartraining program (on windows) and I am finding that it memory leaks and crashes. I am also getting a “Error (valid only for Discrete and Real AdaBoost): misclass” in in my output before the training begins. If you know anything about this error your help would be greatly appreciated.

Thanks for your time

This error means nothing. Please look at main() in haartraining.cpp file.
Ya, there are some memory leaks in original OpenCV. You can make fixes by your own or just use more RAM =).
Crashes often happens due to our of memory, when create opencv matrix structures.

Hi!

I’m a newbie in HaarTraining. I’ve collected 200 positive samples. Can you please show me how to generates 1000 samples from the first 200 images using creatsamples.exe? Are there anyway to do so?

Thank you!

Hi!

1. Use
createsamples -img image_name -num 10 -bg negatives.dat -vec samples.vec -maxxangle 0.6 -maxyangle 0 -maxzangle 0.3 -maxidev 100 -bgcolor 0 -bgthresh 0 -w 20 -h 20

negative.dat looks like:
negative/img1.jpg
negative/img2.jpg

This method will put positive image with distortions and angle rotations to you negatives and create 10 positive images. Use flag -show to see results.
This will create vec file.

2) create vec file from positive image one by one
3) merge vec files.

Hi!

Thanks very much for your reply!

Like I said before, I have 200 positive images. So I still wonder how I can create 200 vec-file and then merge them together. It must take a lot of time. Can you recommend to me some tools to speed up that processes?

Thanks again for your time and consideration!

1) to speed vec file generation you can write Perl script or simple cmd file to launch createsample.exe several times with different original image files

2) to merge vec file here is good enough program
http://tutorial-haartraining.googlecode.com/svn/trunk/HaarTraining/src/mergevec.cpp

Thanks a lot!

I will try!

nice article!
ive done some haartraining as well. i believe i understood most points of it but still few quetions:

1. “object with smaller size will not be found”
actually, im wondering if training is done on fixed positive sample size(say 20×20), what’s the size range can trained classifier recognise? i noticed it can actually detect larger object but how?

2. original positive images do not have to be same size, right? in your case they vary between 50×50 and 100×100. Size normalisation is done with createsamples.exe by -w -h paras, right?
and So DO with negative samples, i suppose? just to confirm this with you coz i have not checked this with source code.

3. three haartraining parameter meanings are not clear to me and didnt find good explaination on net either
-weighttrimming
-eqw: is it better to have equal weight? why default is not equal?
-minpos:

4. the lastest tests i ran with 1650 positives and 3019 negs, 20×20, and some other important paras:
-nsplits 2 -minhitrate 0.999 -maxfalsealarm 0.5 -mode ALL -bt GAB !!-minpos 150!!
guess what? it took entire week(7days) to just train up to 13 nodes!!! The 13th alone took more than 80 hours! on 2G dual core, 2G mem mini mac.
i suspect it is due to -minpos 150 setup coz this is the only different one i used from other tests

5. can you share your negative samples somehow?

thanks in advance!

1. xml cascade contains rectangle description within window 20×20 – it is relative x,y coordinates. Then during detection, scanning window is scaled larger and rectangles are also scaled. It is not good to scale window smaller, because some rectangles will be overlapped.
That’s why objects bigger than 20×20( you can chose 10×10 during training of course =) ) are not detected.

2. Yes, positive images are packed to vec file – internal opencv thumbnails. It is simple resize with some additional noise filtration.
Negatives are not changed at all

3. weighttrimming: If you know theory of Adaboost, you should know, that there are weights, which are used during training. But if weights are small, we can get rid of them to speed up training, but lose some quality of course.

initial weights can be equal or not equal, read about Adaboost =)

minpos: During training you can use clustering, this parameter means how much positive image to use for cluster training.

4. Yea, i know, it is slow. Don’t use -mode all, and use -nsplits 1 – it is simple stumps not tree. it will be faster during training. Use 2 GB of RAM.
You can compile OpenCV with OpenMP support – it will be also faster

5. http://tutorial-haartraining.googlecode.com/svn/trunk/data/negatives/

thanks!

yes i just start learning adaboost and dont know very much about the theory. get some ideas through tests first.

i must done sth really wrong: with two classifier trained over a week on different object, one has 14 nodes(mentioned above) and another has 20, none of them is working 🙁 even use training samples as test samples, still didnt detect anything!

ill take your suggestion to give simpler parameters and trained on more pos&neg sampels and another hard work week!…i mean for machines…

I would recomend, take for example 50 positive and 100 negative ( 1 : 2 ) and build cascade. It should be fast
Test on this training set – if ok, test on another samples.

Then enlarge step by step, positives and negatives ( 1 : 2 )

Hi,

I’m developing a system to recognize objects such as identifying different phone models. As example I want to recognize the phone models as Nokia N70, N73, SE 810 etc by observing the video getting from webcam.

Could you pls suggest some methods to extend Haar training for object recognition. And is Haar training flexible for object rotation ?

Best Rgds

Indi

Yes, open cv haartraining can be used for object detection. Object rotaion in opencv is very limited – it’s required tilted haar features. Mode ALL can add tilted features, but it does not work well.

You would try to detect one model – for example Nokia N70. Collect images with this model: different color, background conditions, lightning conditions….

Hi Indi,

I wonder your case are very specific. Based on our experience haar training is not so good approach for rotation invariant detection. See Vasiliy’s comment. We have own successful invariant object detection: currency and other objects can be detected see videos e.g. http://www.computer-vision-software.com/blog/2009/04/object-recognition.

We will be glad to resolve your specific computer vision task. So, if you are interesting and ready to work with us, you could find contacts of our marketing on “about” page.

Aleksey

Hi,
I am working on Face detection systems.
I have a question.
Is it possible to do Haar training with rotated faces with the purpose of detecting rotated faces?

Regards,

Nasim

Hi Nasim, you should use tilted haar features to detect rotated faces.
By means of OpenCV haartraining launch cvhaartraining with key “-mode ALL” and try. You can look at icvCreateIntHaarFeatures in cvhaartraining.cpp to understand what features will be generated in this case.

Dear Vasiliy,
Thanks
I have found several xml files for eye detection, profile face detection, upper body,…… but I didn’t find any xml file for rotated faces. what’s wrong with rotated faces? is it really possible to detect rotated faces with this method? Have you ever heared someone tried to do this?
thank you once again…

With OpenCV features even tilted ( -mode ALL ) it’s difficult to detect rotated faces. It’s better to add new feature set like in
Here is article: Fast Multi-view Face Detection ( Jones, M.; Viola, P. ).
Also there is variant to estimate face position and then rotate face and then detect it with default OpenCV cascade ( Rowley method ).

Hello…

First of all, THANKS!!!!, it’s a great article, i’m trying to train a haar classifier for pedestrians, but i have a question, in the potisitive images, all must have the same size (example: 14×28), but the image or
silhouette of the person it’s has to be the same?? i mean, if i have 2 images but in one the person it’s close and the other image have a person but a little far from the scene, this images will work?

Thanks for the help

Hello Alejandro,

1) Original positive images maybe different size, but when you prepare positive vec file, these images will be resized and be packed to the same size example 14×28, and “image information” will be changed or lost e.g. positve samples are cropped from original images and resized to the same size.
So, original image or silhouette of the person may be different.

2) Also you can read article by Viola and Jones: Detecting Pedestrians Using Patterns of Motion and Appearance, TR2003-90 July 2003

Hi,

Thanks for answer so quickly, and also thanks for the article of viola (i didn’t know they have it), but i have two more doubts, first, the data coordinates of the bounding rectangle that points to the person has to be calculated in the original image or must be in the resize image (14×28). And two, once i got the list of coordinates like this:

pos_image1.jpg 1 140 100 45 45
pos_image2.jpg 1 100 200 25 35
pos_image3.jpg 1 120 130 30 20

it’s just to type in a command window :

createsamples -info samples.dat -vec samples.vec -w 20 -h 20

to create the .vec file?, the samples.dat is the file containing the info of pos_image.

Thanks again for the help

Bounding rectangle should be calculated in coordinates of original images. Then this rectangle will be cropped and resized to (14×28)

Hello, Thanks again for the answer, but i’m lost (sorry), my doubt is in the description file (sorry), i mean:

i have images of 64×128, so, i have to create the description file, example:

pos_img1.jpg 1 7 20 64 128

and once i finish the file, then i create the .vec file

OR, i resize the images to 14×28, and then create the description file, example:

pos_img1.jpg 1 7 20 14 28 (i’m sure that the x,y coordinates changes with the resize)

that’s it

I’ve tried OpenCV for quite a while now but never used the face detection part yet. How long does it take to generate the samples .vec files and train it? ‘coz right now I have one command prompt still processing the .vec sample file and I don’t see anything being created. I can’t tell tell if it’s actually working or malfunctioning.

Generate *.vec file is fast 10 minutes will be far enough =) Training after that to detect face can take about 7 days or even weeks… depend on parameters in haartraining, number of positive/negative images and of course your machine.

Hi!

I got a problem while trying to create samples.
I created a info.dat file containing entries of the form :

img1.jpg 1 40 36 45 39
img2.jpg 1 102 76 38 48

And when i used the command “createsamples -info info.dat -vec positives.dat -w 20 -h 20”, it finishes almost instantly and shows this :

“info.dat(3): parse errorDone. Created 2 samples”

Could someone explain to me what i’m doing wrong here? Any help would be appreciated.

Thanks

Info.dat is correct, maybe empty line at end of info.dat? img1.jpg and img2.jpg should be in the same directory as createsamples in your case.

PS: It’s better to use this vec extension after -vec =)

Sorry. “positives.dat” was a typo. I used “positives.vec” for creating samples.

And one more thing. The vector file is getting created. So should i actually bother about the “parse error”. I mean, will the vector file be flooded with garbage values when this error shows up? Or can i safely use this vector file for haartraining?

Oh and i checked the info.dat file, there was no empty line at the end of file.

Thanks a lot for your fast response.

When generate vec file use key -show to see what images are really packed.

The “-show” command worked. The images being packed were the right ones.

Using this vector file, i started the training. I used 150 positive samples and 300 negative samples. (the object to be detected is a hand, FYI)

This is what i executed :

haartraining -data haarcascade -vec positives.vec -bg negatives.dat -nstages 20 -nsplits 2 -minhitrate 0.999 -maxfalsealarm 0.5 -npos 150 -nneg 300 -w 20 -h 20 -nonsym -mem 768 -mode ALL

And the training gets over in less than 3 hours. It shows “Required leaf false alarm rate achieved. Branch training terminated”. This happens during the 10th node. It also shows “Total number of splits : 0”.

Of course, the trained classifier was not able to detect anything. So what is going wrong here? Could you help?

Thanks!

I’m kinda confused by the order of what we need to do here. If I’m using a single positive image to generate my positive .vec file, is this order correct?
1. Get the four sample and test positive and negative test image sets
2. Generate positive .vec file using single positive image and test negative images..right?
3. Generate .xml file using .vec positive file, but for the parameters,
– bg refers to background description file of which image? The train positive or negative images?

– npos , which positive samples? the test or the train one?

– nneg , again, test or train one?

4. Use performance.exe to test the image.

Been wondering about this stuff cuz the last two attempts didn’t work; one didn’t get any circles, and another input everything as circles. Right now the third one is still processing, and probably gonna take hours or days even, and I don’t even know whether I inputted the correct stuff.

1) You need generate xml cascade. For this you need prepare positive content and negative content.
a. For negative images you need create negative.dat file – just list of filenames.
b. Positive images should be packed to opencv internal vec file – it’s done because all positive images should be the same size.
There are several ways how to create vec files:
-Each positive images can be converted to one vec file. Then these vec files are merged to Resulting Vec file with special tool – see comments above
-You can create positive description file for your positive images, then launch opencv createsample tool to create Resulting Vec file

2) to generate cascade, launch haartraining with negative.dat and Resulting_Vec_file

3) then you should test your cascade – if it work or not =). You can do it with perfomance.exe tool. For this tool you should again have positive desc file for positive testing images.

hey vasiliy,
can you tell me where i can download pics for the negative samples

also do all images have to be grayscale

@prathik
dude did you download ur database of pos and neg images ??
if so can you give me the link plz??

thnx in adv 🙂

http://tutorial-haartraining.googlecode.com/svn/trunk/data/negatives/
All images should be grayscale – it should have one color channel.

Hi again, sorry for be annoying, but i have another problem, i tried to train a Haar clasifier for pedestrian detection, so i have this data:

Positive images: 50 all in grayscale, w=64 h=128 obtained from http://cbcl.mit.edu/software-datasets/PedestrianData.html

Negative images: 100 all in grayscale, w=640 h=480 obtained from http://tutorial-haartraining.googlecode.com/svn/trunk/data/negatives/

using a program call “imageclipper” (from http://code.google.com/p/imageclipper/) i obtain the data of the rectangles, i have it like this:

Pos/per00001.jpg 1 7 20 64 128
Pos/per00003.jpg 1 11 16 64 128
etc.

once i have this i do: createsamples -info Sam.dat -vec Sam.vec -w 14 -h 28 to obtain the .vec file

once i have this i do the Haar training with: haartraining -data haarcascade -vec Sam.vec -bg Neg.dat -nstages 13 -nsplits 0 -minhitrate 0.999
-maxfalsealarm 0.5 -npos 50 -nneg 100 -w 14 -h 28 -nonsym -mem 512 -mode BASIC

Then the program star and show me this:
Data dir name: haarcascade
Vec file name: Sam.vec
BG file name: Neg.dat
Num pos: 50
Num neg: 100
Num stages: 20
Num splits: 0 (tree as weak classifier)
Mem: 700 MB
Symmetric: FALSE
Min hit rate: 0.999000
Max false alarm rate: 0.500000
Weight trimming: 0.950000
Equal weights: FALSE
Mode: BASIC
Width: 14
Height: 28
Applied boosting algorithm: GAB
Error (valid only for Discrete and Real AdaBoost): misclass
Max number of splits in tree cascade: 0
Min number of positive samples per cluster: 500
Required leaf false alarm rate: 9.53674e-007

Tree Classifier
Stage
+—+
| 0|
+—+

Number of features used : 67193

Parent node: NULL

*** 1 cluster ***
POS: 50 50 1.000000
NEG: 100 1
BACKGROUND PROCESSING TIME: 0.03
Number of presorted indexes: 67193
Number of precomputed features: 67193
Precomputing data, that may take a few minutes…
……………………………………………………………………..
……………….
Precalculation time: 0.52
+—-+—-+-+———+———+———+———+
| N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
+—-+—-+-+———+———+———+———+

and then it crash, i don’t know what i’m doing wrong, please tell me (sorry for be so annoying again).

pd. by the way, the pc where i’m doing this is a Dell optiplex 755, so i’m sure that’s not the problem.

again, THANKSSS!!!

1. Check negative image resolution is more than 14×28
2. During creating vec file, use -show to be sure vec file is ok
3. Try to change res to square like 14×14 as temp workarround and check.

With what error program crash? Run-time error? Or any output with error?

1. The resolution of the negative images are 640×480.
2. i use the -show and i see the all the image with size 14×28 so i suppose it’s fine (when i do the training i use the images with size 64×128, do i have to use that of 14×28 or the createsamples do this crop?).
3. i’m basing my training in the article “Object detection using scale-specific boosted parts and a Bayesian combiner” of Hannes Kruppa and he use this parameters, but i’ll try it anyway.

the error that appears is “haartraining.exe has encountered a problem and needs to close.”

Alejandro, also increase mem to 1GB, if possible.
When you prepare vec file, you can use any image, they should be described in positive.dat file.
When vec file is prepared, you can delete all positive images, they are stored in vec file and haartraining should be launched with vec file and with -w -h of vec file.
createsample cropped all images to 14×28, if you put it in -w -h.

Hi!!

Problem solved, apparently the error was in the -nsplit value, i have it in 0 so, i changed to 1 and voilà, it works!!!, know i’m gathering images to create a better pedestrian classifier. I got another question, earlier you said that you have positive images from different size, my question is that the object of interest must have the same proportion in all images (although the images are of different size) or is not really necesary?

by the way, thank you very much for all your help, thank’s to you i clarify many doubts about this classifier.

Hi Vasiliy,

I`d your advise on something.

When I run createsamples with 405 positive images, the output is like this.

Does the last few lines indicate success or failure?

Info file name: info.txt
Img file name: (NULL)
Vec file name: positives.vec
BG file name: (NULL)
Num: 1000
BG color: 0
BG threshold: 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
Width: 20
Height: 20
Create training samples from images collection…
info.txt(406) : parse errorDone. Created 408 samples

I actually used 405 images but it says 408 samples were used. And I dont know what to make out of the “parse errorDone”. Does it indicate success? failure?

Btw, when I run the training later with 405 positives and 405 negatives, the training ends in just about 5 mins.

it means, that info.txt is bad. Make sure, all images in info.txt really exist. Remove empty lines in text file ( symbol \n )

Hello, it’s me again! jaja

For know i’m gathering the database that i need, but i was wondering, for a pedestrian classifier what is better:

one with positive images of diferent people but few positions, or one with positive images of less people but more positions (positions = i mean movement secuences).

What do you think??

Hi Alejandro,
First I would try one position, but several people with this position.

Dear Vasiliy Mun,

Thank you for your excellent post.

I have a problem of haartrainning too. My training gets stuck in stage 5. Btw, I have followed this site:

http://note.sonots.com/SciSoftware/haartraining/mergevec.cpp.html#m17ed6bb..

Still I have problem…
Anyways… I am still trying to solve the problem.

I have a one question to you. How to implement Real AdaBoost (RAB)using this OpenCV? The default algorithm in OpenCV is Gentle AdaBoost(GAB).

I know there is command -bt RAB to train the cascade or to get xml file using haartraining.exe

I want to have confidence measure of the detected object. I mean, I want to display, how confident the detector is when it detects the object. I know it is possible in OpenCV but I don’t have any clue where to start.

Thank you very much.

Hi switspk,

1. there is bug in OpenCV with endless looping. It can be fixed with encreasing RAM and changing negative images. Based on amount of RAM, haar features are generated and with these features, needed false alarm could not be reached, so we have endless loop

2. Look at icvBoostNextWeakClassifierRAB in cvboost.cpp, it is used if -bt RAB. I did not understand, what do you mean: How to implement RAB?

3. There is cvRunHaarClassifierCascade, in it there is stage_sum. If stage_sum > thresh, you see object – you can use it as heruistik when detecting object for your confidence measure

Thank you for quick reply…

I didn’t know about the endless looping bug. Thank you. I have changed negative images and increased amount of RAM. Let’s see if the problem can be solved.

About RAB:

By implementing RAB, I mean to say: how to use RAB capability of opencv. It has already been implemented. All I want is to display the confidence of the detector while detecting an object. For example: the detector has confidence of 0.8 on the detected object or confidence of 0.2 on the detected object.

In usual implementation of AdaBoost, only the sign of summation of strong classifiers are used for determination of object or non-object. If the sign is positive, the object under consideration is “object” if sign is negative, it is “non-object”. Is not it? In RAB, values of summation of strong classifiers are used.

Yes. I want to use those values.

I would definitely be looking into icvBoostNextWeakClassifierRAB & cvRunHaarClassifierCascade.

Thank you very much

So for confidence you may use stage_sum in runhaarcascade function, the bigger the sum “the better” object you detect.

I checked for the “stage_sum”, as you have said, but I could not figure out how I could output this “stage_sum” from the cvRunHaarClassifierCascade function.

Please help.

You can disregard the previous questions and ill just ask 1 simple question.

When using haartraining, if the background processing time is very small (under 1 second) does this mean something is wrong or is it ok that the first few steps are < 1 second as shown below:

*** 1 cluster ***
POS: 993 1000 0.993000
NEG: 2979 0.341276
BACKGROUND PROCESSING TIME: 0.08
Precalculation time: 0.66

Hi Peter S,

it’s ok, first stage is very simple.

Thank you for the reply also have another quick question or two 🙂

I created a classifier off 40 unique photos then used create_samples.exe and pushed it out to 1000 positive photos.

I am also using 3000+ unique negative photos.

The classifier I created finds the object I am looking for very nicely if the background it is shown on is dark or 1 absolute color (like dark blue), does this have to do with the negative files I am using, a setting I forgot to use I used haar training or create samples (like a luminosity setting?) or anything else I am overlooking such as the amount of unique positive images or a setting in the actual program?

For the second question is there any quick way to check for a mirrored version of the object your classifier is trying to find? Lets say I train a cascade with just images of the left hand, is there any way to make the classifier find a mirrored version (so the right hand) at the same time without having to create another cascade and running a second classifier at the same time?

Thank you,
Peter S.

Peter S,

1) You should add background noise to your positive images. Now your features are depend on background – it’s root of problem.
There were similar comments on this blog, please try to find.

2) you can flip image =) using OpenCV, but it will be really slow. Also you can change source code to calculate mirrored features.

Thank you, I thought as I am clipping the images so the object I am only trying to find is shown in the box from when using createsamples that the background wouldn’t be an issue but I guess I was wrong, I will try making some images with background noise then use createsamples with -img on it and see my results.

Also, yeah stupid me totally forgot about cvFlip. Odd though when flipping the image and running the classifier on it again I did not see a performance drop at all, but it may just be that the initial searching wasn’t really costly in terms of performance.

Thank you,
Peter S.

Hi vasily mun, your post is really interresting.

For my thesis, I have to detect a goldfish in an aquarium, the background of the aquarium is white and the lighting may just change a bit.

1. So for the negative pictures, may just take like 200 pictures sample of the aquarium with diffent lighting? or is it better to also put random picture (example : of a street or of a building?)

2. Also, I took picture of the goldfish and I crop them. The size of my positive cropped picture is not the same.
example :
http://img201.imageshack.us/img201/1775/052jpg00000163035600960.png
http://img201.imageshack.us/img201/328/065jpg00000005018400520.png
So must i crop them with all the same size? like 120*120 or this is good?
If it’s good with height and weigh must i put when i use the createsamples ?

3. Are test samples just for testing the xml files that i will make?

Thanks you very much

Hi Phil,

1) detection only on background of aquarium, it’s ok to use aquarium with diffent lighting.
2) It’s better to use with the same width and height.

3) You should have another images( not that you use for training ) – it may be the same fish, but another color, etc.. to be sure, that you detector is working. On training samples, testing is useless.

Hi Vasiliy

I am trying to improve results for a classifer doing factory rack entry detection. I opted for a haar classifier since the image processing is used to servo a robot and hence needs to be fast.

Now, I used 200 positive images with rack entry points in them. And 200 negative images of racking without entry points in them. I am trying to detect the entry points.

I find that I get only 50 % hit rate with ~25 % missed and ~25% false positive. I am trying to bring my positive hits up and reduce my false positives as well.

Any thoughts on where I can start ?

Is there any way I can control the features selected by the classifier ?

How can I get more visibility in the feature selection during training and classification ?

Any advice will be very useful.

Cheers
tectok

You should change source code. All available feature in OpenCV are generated in cvCreateTreeCascadeClassifier->icvCreateIntHaarFeatures

1. Use similar rack entry – it’s very common question, you can read my recomendations in another comments: detect fish, detect hand….

Hiiiiiii!!!, It’s me again, i have a question, for the negative samples, it obvious that these pictures cannot have the objetc to detect, is there any problem if i use the images obtain from a video of the background of the scene of the positive images, i mean, there is any problem with images in sequence?.

and other thing, the size of the negative images can be different, or must be the same size?

Thanks for your help!

Hi, please answer my question, please!!!!

Alejandro,
Please read blog carefully, I answered. Of please remind me your question.

hello, i look but you dont answer, here it’s the question:

for the negative samples, it obvious that these pictures cannot have the objetc to detect, is there any problem if i use the images obtain from a video of the background of the scene of the positive images, i mean, there is any problem with images in sequence?.

and other thing, the size of the negative images can be different, or must be the same size?

Thanks for your help!

Hi Alejandro,

1. Negative images can have different size
2. Positive image should be maximized cropped. If there is BG in positive image, it should be filled with noise.
Negative images should not contain object to detect.

How much of time takes to identify an object. I have tried object detection method to identify human but it took nearly one minute. But i need to track human in a video can i use this method?

thanks in advance

Nikkey,

It is dependent on your task, frame size, scale factor etc and of course what fps you want. Often, haar detection is used as only first (or last) step of an object detection algorithm, other steps are heuristics (or additional methods).

im using 25fps. my task is track a human from a video. video may be in outdoor or indoor. so can you give some solution?

Nikkey,

You didn’t say frame size. I assume that VGA frame and 25fps is needed, only pattern detection algorithm (haardetection) is not enough for covering these requirements. You need at least combination of methods or discuss with our company and we could provide solution for you, see “about” page for details.

sorry for late reply.
At the moment i am trying to detect human in a image. size of image is 450×300. It has 3 human object. Eventhough It identify 3 human bt it took 1min. why s happening?
Is capturing time depend on training?

Hi,

I have big problem.

I want to get “neighbors” value from “cvHaarDetectObjects” function which is called by “detect_and_draw” function in “facedetect”

While printing, I have used r->neighbors where “r” is a structure of type CvAvgComp:
CvAvgComp* r1 = (CvAvgComp*)cvGetSeqElem(faces, i);

With-in “cvHaarDetectObjects” the return value is also of type CvAvgComp.

What I am getting is just some random value.
Even if I, forcefully, define “neighbors” to some constant value like “36”, printed value is always random.

+ I tried to change the name of this “cvHaarDetectObjects” function(it has all together 4 instances), but it could not be build. There is some strange error. Problem with my MSVC2008???

Thanks a lot, in advance.

Hi Vasiliy Mun,

I’m sorry i couldn’t respond for quite some time as I had some stuff to attend to.

I tried haartraining again including the suggestions you gave last time. But still no luck. It goes till 15th stage and then stops abruptly saying “Required leaf false alarm rate achieved. Branch training terminated”. So what am i doing wrong now? Is it because i’m only using a limited number of samples (200)? Because most of the tutorials mention using around 5000-7000 samples.

“Required leaf false alarm rate achieved. Branch training terminated”, it means that with current set of feature it’s impossible to get detector with needed false alarm on current set of negative images. It’s very strange.

1. What set of negative image you use? It’s ok, that you use small number of negative image, but at the same time, you should use small number of positive. Positive:negative = 1:2 proportion.

Hello, my problem is using createsamples.exe
I write this: opencv-createsamples.exe -vec sample.vec -info pos.txt -w 14 -h 14 -num 1000.
I have 100 pictures, and pos.txt file is as follows:

C:\Program Files\OpenCV2.0\bin\samples\img1.jpg 1 72 119 230 86
C:\Program Files\OpenCV2.0\bin\samples\img2.jpg 1 35 76 170 56
C:\Program Files\OpenCV2.0\bin\samples\img3.jpg 1 56 79 172 62

the program gives this: pos.txt(1) parse errorDone. Created 0 samples

Images exist and I think everything is fine, so please help me :S

Thanks
Alen

Hi, try to change the

C:\Program Files\OpenCV2.0\bin\samples\img1.jpg to

samples\img1.jpg maybe the problem is in the “Program Files” because there is a space.

Is there a way to decode/decipher what’s in the XML file? I want to know if the first two Haar features for face are the same as in the Viola-Jones original attempt.

Hi Munim, about OpenCV xml file.
It consist of stage. Each stage is classical Adaboost STRONG classifier. Viola and Jones used cascade of Adaboost strong classifier.
Adaboost strong classifier is linear combination of week classifiers. So let’s see stage 0 in OpenCV xml cascade. Adaboost week classifier is called tree – it can be stamp based( just one node ) or real tree. Rect features is in this way x,y, w, h, weight.

stages
stage 0
trees
tree 0
root node
feature
rects
3 7 14 4 -1.
3 9 14 2 2.

Hello,

I saw Vasiliy Mun suggesting to turn off the tree splitting (with -nsplits 0), but i was wondering.. when does turning it on help? i mean in what situations would/could it improve the results?

and also.. what does the “splitting” do exactly? i have done some googling but i couldnt find any page explaining what its actually for.

Thanks

Rappie

PS. this is a second post, it seems the site got the dates wrong for my first post, because i was posting that one from the google cache 🙂

-nsplits 0 means that you use stump as week classifier e.g. like in classical Adabost, just binary function.

-turn on splitting means, that you use real tree( with more than one root node ) as week classifier. For this you split samples into clusters and “teach” each node in its cluster, if say in simple.

Trees are better than stump in common situation, because hitrate is better.

Thanks for your quick response!

I have a few more questions though 🙂

It seems the following arguments are kinda connected, but i can’t seem to find out what they actually do:

-nsplits
-maxtreesplits
-minpos

I’ve been tinkering a bit but i cant seem to get any cluster bigger than 2, hairtraining.exe then ignores them because it is too small.

So i guess my questions are:
1. Could you explain those 3 arguments in your own words, because the man page isnt very informative 🙂
2. Whats the difference between the ‘weak classifier tree’ and the ‘tree cascade’?
3. How do i get bigger clusters?

Thanks

Hi Rappie,

-nsplits > 0 means, that in week classifier will be used nsplits node at least
-maxtreesplits – max number of tree nodes.
-min pos – is minumun number positive images for one cluster.
Number of clusters depend on nsplits. So all positive images are divided into clusters.

Clusters are needed to improve hit rate. For example, week classifier( one node ), says on positive image, that it does not contain object – it’s bug.
In stump-based case, this image will be wrong recognized.
In tree-based case, this image is given to next node, if this node says it does not contain object, this images is given to third node and ….

So hitrate is improved, false alarm will not be changed too much.

Ok so if i got it right… it should be like this:

for each stage:
positives: 5000
negatives: 10.000

Then i use -nsplits 5 for example, and -minpos 1000.

This would result in having 5 clusters of 1000 images for each training stage. And each node in the weak classifier tree will have its own seperate cluster of 1000 positives to train on. Is this correct?

I still dont understand the -maxtreesplits argument though.. you said it was the ‘max number of tree nodes’. Would this mean that if i use -nsplits 10 and -maxtreesplits 5, it would be maxed out at 5? Or are we talking about a different kind of tree here? In that case.. which tree? 🙂

Thanks for your help so far, by the way 🙂

Hi
I was using HAARTRAINING with this parameters:

-data data/cascade -vec C:\temp2\data\vector.vec -bg C:\temp2\negative\infofile.txt -npos 500 -nneg 900 -nstages 20 -nsplits 1 -mem 1300 -mode BASIC -w 24 -h 24

but only stay in 3 stage, when this parameters FA=0.0000000, my training stanby in:

POS:384:451
—-??

is this parameters(FA=0) my trainning stop?
or opencv have any bug?

Hi jedota,

Well FA = 0.0000 means, that false alarm is 0 – it’s very good. It means, that 3 stages are enough to achive needed false alarm.
But this case is very strange, possible bug in your negative images =)

ok,
when you write”possible bug in your negative images =)”

this is:

they aren’t enough negatives (945)?
or the size is wrong ?(24×24) cropped of Bioid?

my txt file is:

Bioid_0001.bmp
Bioid_0002.bmp

and go on!

Regards

Hi, jedota,

Size is wrong. If you use -w = 24 -h = 24 in haartraining for positive images, negative images should not be of this size. They should be for example 200×200.

thaks

this is valid for un genre detector??

women=positives
men=neg

regards

I posted a message here before about goldfish detection in an aquarium. With your advices I succed the haartraining 🙂

But I have a question, actually the fish that I detect are in “horizontal rectangle” because my positive sample are horizontal rectangle.

But Is it possible to do it with rectangle with an orientation. Do you understand what I mean?
The positive sample are style rectangle but with different orientation.

Thanks you

Hi Phil,

1) with OpenCV adaboost, it’s very difficult to achive this.
You may try to train with -MODE ALL option, in this case if you will use rotated objects as positive, you will get classifier to detect rotated only object.
2) Then you need classifier, which on picture could detect object orientation to decide what classifier to use.

Another method is use key point matching or rotation-invariant algorithms

Hi there,

I want to get “neighbors” from cvHaarDetectObjects which is being called by “detect_and_draw”

I have used cvAvgComp as following:

CvSeq* faces = cvHaarDetectObjects( img, cascade, storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize(15,10) );

CvAvgComp* r1 = (CvAvgComp*)cvGetSeqElem(faces,i);

When printed using “r1->neighbors”, it only gives me some random value… any one has a solution???

Hi switspk,

Please look into cvHaarDetectObjects, where faces is filled. neighbors is filled, if FIND_BIGGEST_OBJECT is turned on, in another cases, it’s not filled, you should add it yourself

Hi Vasiliy,

I could not find this “FIND_BIGGEST_OBJECT” in cvHaarDetectObjects. Is that why you said “you should add it yourself”? Should I introduce this new variable “FIND_BIGGEST_OBJECT”?
I suppose this “FIND_BIGGEST_OBJECT” is a flag.

Could you please explain a bit more.

btw, i am using very old opencv, version 1.0 : )

and one more thing… all these comments are supposed to be sorted using dates, right?(except for replies) but they are not.
eg. my comment posted on 04-11-2009 appears before your comment posted on 11-09-2009.

: ) just being curious

Hi switspk,

1) In Opencv 1.1. in cvHaarDetectObject:
bool find_biggest_object = (flags & CV_HAAR_FIND_BIGGEST_OBJECT) != 0;
….
if( find_biggest_object )
{
..
comps[idx].neighbors++;
comps[idx].rect.x += r1.x;
comps[idx].rect.y += r1.y;
comps[idx].rect.width += r1.width;
comps[idx].rect.height += r1.height;
..
}

if( !find_biggest_object )
{

}
else
{
result_comp = *comp;
}

if( find_biggest_object && result_comp.rect.width > 0 )
cvSeqPush( result_seq, &result_comp );

return result_seq;

2) I meant, that above logic in 1.1. is when FIND_BIGGEST_OBJECT flag is on, otherwise neighbors is not filled.

Thank you Vasiliy for quick response,

Now, I understand that boolean flag (“FIND_BIGGEST_OBJECT”)’s job.

But, I am using 1.0, not 1.1… and this 1.0 is so primitive wrt 1.1, and there is not such bool in 1.0. I have tried 1.1 once, but strangely it failed to compile in my computer.

Anyways, I should work bit hard to figure it out.
Thank you

[…] 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, […]

hi, thanks for your answers its really helpful.
i wanna train a cascade from cars ( frontal ), i wanna know what to do with pictures that contains more than a target object? is this good to take more than one sample from a picture? i.e. i took a picture from high way.

Hi Samiran,
Yep, you can take all objects from picture, cropping them. If you use createsamples.exe to generate vec file, you will need positive description file, where you write bounding rectangles of these objects on picture, read FAQ about this (http://www.computer-vision-software.com/blog/2009/11/faq-opencv-haartraining/).

Hello, Samiran!

Did you successfully create the xml haar file for cars detection? If yes, could you send in to me on oleynick.igor (at) gmail.com?

Hello, Samiran!

Did you succed in creating the haar xml file for cars detection? If you did, could you send it to me on oleynick.igor (at) gmail.com?

Hello,

We are looking into doing hand detection for a project. We are looking into different approaches, including haar cascades. I would like to try the haar training approach, but I am just surprised at the large number of images people report to use in the training – I am surprised by how do they get hold of such large number of images. Is there some source where I can get large numbers of hand images from?

Thanks

Hi Aipcaish,

1) I also had such problems. I took video with object – it was plate, then frame by frame cropped plate from video with cropper, that I wrote.
You can do the same
2) You need positive images with different BG, lightning condition – read FAQ on this blog, maybe there are some “police” hand databases =)

Hi, I like to detect human body in video surveillance, So is it possible to use haar-like feature for background subtracted object, that means after background subtraction we get human in white pixels. So is it possible to detect that object?

Hi Nikkey,

It is dependent on perspective. Haar Detect are not for background subtraction, this algorithm is using for object detection. For human you can find cascades in opencv, but it doesn’t have quality enough.

Ya, i know we cant use haar for background subtraction. I am asking can we use haar features for shape detection (shapes are in white color in black background) ?

You could try to do it. Haar basis could approximate any shape theoretically. We tried to use haar feature for barcode detection, but we didn’t have good enough result.

Hi Vasiliy,

Thanks for the excellent tutorial and FAQ. I was able to learn from your webpage in one day which I was not able to from the OpenCV documentation for almost a week.

I am trying to detect the star that appears on our flag. By all means this should be a straightforward classifier without the complexities of face, hand or pedestrian detection. I keep getting the False Alarm Rate Achieved msg which from your posts I see is quite bad.

To start with I have used 200 positive and 106 negative images. The negatives I took from the links posted by you. The positives are generated using createsamples. I followed the First method mentioned by http://note.sonots.com/SciSoftware/haartraining.html for creating positives. Hence I have 200 images with the star in different orientations with different backgrounds. This method changes the orientation of the star and pastes it on the first 10 negative images. Is this ok?

I will increase the number of negatives to see if the False alarm rate achieved is fixed. Any other reasons as to why this would happen considering that the classifier in my case is a very simple one? (I used nsplits 2 which I will change to 0 and check)

Thanks in advance!

Hi Mel,

even so simple object as the star on flag could have a lot of the lighting condition variations, also, fabrics of flag could be different. So, I recommend to use more content with more variations for haar training.

Hello
I’m Japanese, and studying OpneCV.
I have one quetion about haartrainig.

POS: 6879 7000 0.982714
50%

This number [NEG:] is go slowly when the stage number increases.
I don’t know the reason.
I use 7000 positive images and 3000 negative images.
Image size is 30×30.
Is it better to use more negative images?
Please tell me what should I do.

regards

POS: 6879 7000 0.982714
50%

This number [NEG:] is go slowly when the stage number increases.

When the stage number increses, negative samples have to pass more complex cascade
with all previously built stages.

Andrey, thank you for your answer.

I think I try to study more about haartraining in detail.

Can I ask how to change this procedure with another feature like sift, lbp etc.

Hi,

I’m trying to create the vec file for my positive samples with createsamples just cant think of what I am doing wrong.
I start with the following commands:
opencv_createsamples -info test_pos.txt -vec test_pos.vec -w 20 -h 20

I get to following:
Create training samples from images collection…
test_pos.txt(1) : parse errorDone. Creates 0 samples

My test_pos.txt looks like this:
pos/img1.jpg 1 1 20 20
pos/img2.jpg 1 1 20 20

I tried it with [x y width height] and without, same result.
Do I even have to make a vec-file if all my positives have the same resolution or is there another way to do it?

thanks in advance!

Sometimes I get: “opencv_createsamples.exe has encountered a problem.” with ModName: msvcrt.dll. Depends on if I entered [x y width height] in the test_pos.txt or not.

But still no result. I tried different Image formats but I made sure that its grayscale single channel.

My test_pos.txt looks like this:
pos/img1.jpg 1 1 20 20
pos/img2.jpg 1 1 20 20

Did you try:
pos/img1.jpg 1 0 0 20 20
pos/img2.jpg 1 0 0 20 20

The format of the description_file_of_samples is as follows:
[filename] [# of objects] [[x y width height] [… 2nd object] …]
[filename] [# of objects] [[x y width height] [… 2nd object] …]

I had the feeling it had to be something simple like this ^^ I still get the same error thou. Only this time its right after “Create training samples from images collection…” without saying anything about a parse error.

Shiny,

Please explain your problem with more details. Unfortunately, it is too difficult to understand what you meant.

Can somebody please tell me how long the haartraining of 50 positives and 100 negatives (image size 28 x 16) would approximately take? 5 hours? 1 day?

I am running the haartraining.exe since 6 hours now, the taskmanager shows high activity (changing, so I guess it’s not hung), and since 6 hours I see this window:

——
(…)
Parent node: 1

*** 1 cluster ***
POS: 4 4 1.000000

I started haartraining exe this way:
c:\train\haartraining -data data/cascade -vec positives.vec -bg negatives/negatives.txt -npos 4 -nneg 7 -nstages 20 -mem 1000 -mode ALL -w 28 -h 16 -nonsym

I did read in another post that positives and negatives should not have the same size. I hope that this is not the problem.
If anybody reads this and can tell me if I should stop or keep waiting, it would be really great.

Thank you much in advance!
Paul

Can somebody please tell me how long the haartraining of 50 positives and 100 negatives (image size 28 x 16) would approximately take? 5 hours? 1 day?

I am running the haartraining.exe since 6 hours now, the taskmanager shows high activity (changing, so I guess it’s not hung), and since 6 hours I see this window:

——
(…)
Parent node: 1

*** 1 cluster ***
POS: 4 4 1.000000

I started haartraining exe this way:
c:\train\haartraining -data data/cascade -vec positives.vec -bg negatives/negatives.txt -npos 4 -nneg 7 -nstages 20 -mem 1000 -mode ALL -w 28 -h 16 -nonsym

I did read in another post that positives and negatives should not have the same size. I hope that this is not the problem.
If anybody reads this and can tell me if I should stop or keep waiting, it would be really great.

Thank you much in advance!
Paul

Paul,
really, haartraing extracts many negative samples (with size as positive sample) from each big negative picture, may be a thousand. If you choose nneg negative pictures with size equaled to positive sample, haartraining will extract only 1 negative sample from each negative picture.

On each stage, before start of training this stage, haartraining searches nneg (or almost nneg) negative samples which were not filtered before this stage from all possible negative samples. If you have huge set of negative samples (big size of negative pictures), this search can be completed. But if you had only nneg negative samples (if size of negative picture is equaled to size of positive sample) and some of them were filtered on previous stage, this search will not be successful, haartaining will check samples in infinite loop.

So, if you use 28×16 positive samples, choose 1280×1024 negative images and wait couple of seconds for “-npos 4 -nneg 7”.

Hye!I have to get started myself a project concerning the recognition of an object -on which i have’t decided yet-also by working with OpenCV,but before that…I read your comments and I have one question:Does all this work also on Win Vista?
Thanks a bunch!

I am working with objectmarker.exe, however want to do in lines of code that makes this application
ie open every positive image and select with your mouse the area of interest and generate a file. txt
with x, y w and h cordenadas…

Hi, Alejandra. If you have a question, could you clarify it, please? I didn’t understand if I can help you.

hi, can you tell us more details on how you cropped the objects from the videos, frame by frame? and.. have you tried using the haarcascade_fullbody.xml in opencv to detect the body? Thank you very much!

We wrote a program that worked by following steps:
1. Open a video. First frame and cropping rectangle are shown.
2. Adjust position of cropping rectangle around the object.
3. Press a key to save cropped frame, show next frame and cropping rectangle.
4. Repat from step 2.

I’m not sure, may be, you’ll be able to find similar program in the Internet. If
you prefer to write your own tool, but without using video processing, use
VirtualDub, Export to image sequence function to split video to image files.

Hi,

Great and comprehensible article! I was just wondering whether you have used the haarcascade_fullbody.xml for detecting humans because I tried using it; however, it only works on some images wherein some even have wrong detections.

Also, I’m wondering if I use Haartraining for detection of binarized silhouettes be more effective than using actual images of people?

Can you suggest any tools or libraries that can detect binarized silhouettes accurately?

Thanks!

Hi, haartraining effectively uses grayscale information from samples. I guess, it’s not the best way to remove grayscale information and convert images to bitmap form.

Hello Vasiliy Mun ,

I have been following your tutorial, and the tutorial at “http://note.sonots.com/SciSoftware/haartraining.html”. I am trying to train sign language, specifically character “B” . I tried to train 4 times , but every time i get an error … “Required leaf false alarm rate achieved. Branch training terminated.”

I have following two questions, I would greatly appreciate if you could help.

1) In Positive images do we have to necessarily supply the position in which the the required gesture “B” is present in picture , or the whole positive image can be considered a character B. Example:

I know this is okay —> Positives/b1.jpg 1 39 68 94 123
Is this ok ? —> Positives/b1.jpg {i am using this one …}

2) Can you explain me this error , thoroughly please , “Required leaf false alarm rate achieved. Branch training terminated.” . I get it that my negative images are not right, but i am using 100 pics from the negatives database you provided.

I am using grayscale images, positives 50 and neg 100, i have done everything right , till merging vec files, i am always stucking at haartraining. Thanks

Hi, Shahab,

1) You have to use form “Positives/b1.jpg 1 39 68 94 123”. If you have images cropped down to sign boundaries, you can use constant “1 0 0 ” (if you have images of constant size) for each positive image. You must define exact boundary of sign. Don’t use images with character B “somewhere in center”.

2) “Required leaf false alarm rate achieved. Branch training terminated.” is not an error message. It’s a message about successful finishing of branch training. If it’s printed in the very beginning of the process, it may mean some problems with your parameters or input files. If you use “Positives/b1.jpg” rows it list of positive images, are you sure you get correct vec file with all your images? You may use “createsamples –vec -num -w -h -show” to check your vec file. How many positive samples you made from your 50 positive images? Please, pay attention, if you made 5000 samples, you need to use several thousand negative images. In any case 50 images is insufficient to get good cascade.

Hi, Andrey Soldatov

Thanks for the reply. For point 1) , now i have cropped all the 50 images and my positives.dat file looks something like this ,

Positives/b37.png 1 155 18 86 178
Positives/b31.png 1 97 01 118 223
Positives/b48.png 1 92 05 127 219
Positives/b2.png 1 123 10 106 230
Positives/b40.png 1 103 02 133 223
Positives/b44.png 1 116 04 127 232
Positives/b5.png 1 99 08 125 215
Positives/b46.png 1 107 09 125 216
Positives/b22.png 1 125 05 116 213
Positives/b6.png 1 148 20 94 180
Positives/b13.png 1 122 03 119 232
Positives/b16.png 1 179 39 100 178
Positives/b15.png 1 122 04 122 227
Positives/b49.png 1 111 04 114 211
Positives/b30.png 1 117 11 113 219
Positives/b10.png 1 117 03 124 222
Positives/b38.png 1 105 49 91 165
Positives/b12.png 1 124 04 114 222
Positives/b11.png 1 112 05 120 221
Positives/b41.png 1 111 09 126 214
Positives/b47.png 1 135 02 130 232
Positives/b42.png 1 108 06 107 204
Positives/b18.png 1 133 03 138 221
Positives/b14.png 1 138 04 116 221
Positives/b33.png 1 55 07 114 209
Positives/b8.png 1 135 06 112 207
Positives/b50.png 1 141 37 92 172
Positives/b36.png 1 181 25 103 194
Positives/b20.png 1 117 03 123 216
Positives/b28.png 1 120 11 108 207
Positives/b9.png 1 103 05 112 202
Positives/b7.png 1 138 17 103 183
Positives/b23.png 1 80 35 101 171
Positives/b4.png 1 120 10 108 197
Positives/b17.png 1 115 20 118 204
Positives/b39.png 1 126 35 86 148
Positives/b34.png 1 157 05 101 200
Positives/b43.png 1 118 07 127 227
Positives/b27.png 1 113 13 93 173
Positives/b1.png 1 112 11 118 227
Positives/b32.png 1 79 04 117 219
Positives/b29.png 1 117 05 122 223
Positives/b21.png 1 137 04 118 214
Positives/b24.png 1 108 13 94 182
Positives/b19.png 1 134 07 119 216
Positives/b45.png 1 123 04 114 219
Positives/b3.png 1 111 12 117 192
Positives/b35.png 1 165 42 86 184
Positives/b26.png 1 124 10 96 180
Positives/b25.png 1 106 15 103 74

From these 50 images, i have created 10 from each image , totalling 500 images.

Through the comments i have read, vasily mun has suggested i put 1:2 proportion of positive and negative images. So I have now 1000 negative images.

Then I did, was merge my all the vec files, also i have seen through option “opencv-createsamples -vec samples.vec -show” that the merged samples.vec file has 500 images.

Now I have used command,
opencv-haartraining -data haarcascade -vec samples.vec -bg negatives.dat -nstages 20 -nsplits 2 -minhitrate 0.999 -maxfalsealarm 0.5 -npos 500 -nneg 1000 -w 20 -h 20 -nonsym -mem 512 -mode ALL

Its processing, i’ll tell you when it successfully finishes.

Hi, Andrey Soldatov,

It finished after 8th node , and it generated an xml. When I tested that xml , it was not detecting… Test 5 failed.

For Test 6, I have taken images from different volunteers i found from my university in different backgrounds , i am going to make 10 images out of each totalling 1000 image samples, and 2000 negative samples. Lets hope it works …

by the way , -nstages 20 -nsplits 2 what is these ??? should i change them or these parameters are okay…

Hello

I am trying to train a haar classifier for logo detection . I have collected 150 positive samples and 300 negetive sample images . I have marked the positive samples carefully . Now when I am running haartraining any stage(including the first stage) is not completing the value of N is going up (say 25000 ) but the false alarm is not achiving , I have given the -maxfalsealarm 0.5 . Please help me , what I should do .

Thanks

Could you please give me output of your program like:
D:\BEHOLDER\PROJECTS\pringles>createsamples.exe -info positive.txt -vec 1.vec -w 20 -h 20
Info file name: positive.txt
Img file name: (NULL)
Vec file name: 1.vec
BG file name: (NULL)
Num: 1000
BG color: 0
BG threshold: 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
Width: 20
Height: 20
Create training samples from images collection…

Hello Vasiliy,

I am running that on my machine and currently I have no access to that as I am out of town. i will let you know asap.

Regards,
Prathik

C:\Tools\temp\haartraining.exe -data data/cascade -vec data/vector.vec -bg negative/infofile.txt -npos 5000 -npos 4500 -nstages 25 -mem 1000 -mode ALL -w 24 -h 24 – nonsym
Data dir name: data/cascade
Vec file name: data/vector.vec
BG file name: negative/infofile.txt
Num pos: 5000
Num neg: 4500
Num stages: 25
Num splits: 1 : misclass
Max number of splits in tree cascade: 0
Min number of positve samples per cluster: 500
Required leaf false alarm rate: 2.98023e-008
Tree classifier stage
+—+
| 0|
+—+

Number of features used : 261600

parent node: NULL

*** 1 cluster ***
POS: 5000 5000 1.000000
NEG: 4499 1
BACKGROUND PROCESSING TIME: 0.14
Precalculation time 114.91

I guess this is what you asked… I created the vec file from the positive samples I had… If you want that scree I will send you… The current training is in 23rd stage and after seeing those results I am planning to run one more classifier… I want your help in running that……

Prathik,
It’s better to put -maxfalsealarm rate = 0.5 and hit rate = 0.999, not false alarm is very small and training may be not possible.

The default max. false alarm rate is 0.5 which i got… And in the positive images I took there is a constant red background so now this time I want to put some noise… I introduced noise using photoshop is it good or do you advice me to introduce some other noise?

it’s better to put some noise.

“it’s better to put some noise”
Do you mean to put noise such as some background images???

I am copying the picasa link of 2 photos
1. the first one is sample of what I used for the first time
2. The second one is what I am planning to do for the next time.

Please comment on those so that i can start trainning

http://picasaweb.google.com/pratheekgadde/Haartraining?feat=directlink

The second one is what I meant.

I finally got the xml file of the first trail. The output is really good. It is detecting hands no only in red background but also in different back grounds. The only issue I had is it is not detecting hand after some distance(if you move hand far from camera). Is there any way i can improve that?

It is known issue. And can be fixed in haardetector, not in haartraining.

Thank you for your support in my haartrainning… Do you have any idea to fix that problem in haardetector

You need to rework scalling method in cvhaar.cpp. As quick fix, change scale_factor = 1.05 and size = 20×20 ( -w -h which you put in haartraining. )
Also please note, that objects smaller than -w -h, put in haartraining will not be detected at all.

I gave 24*24 for width and height in haar training so i can get haar detector for that width and height ? I will do that changes so that I can effectively build the haar detector….

the haar classisifier, which I trained is not detecting hand in some postures… It is very accurate but misses some gestures… should i use images with such gestures in the positive samples…

which algorithm is best for trainning this classifier??

It’s normal, because your hand classifier was trained on defined posture.

1. Try to add different gestures to positive images, but quality can be worse.
2. There are another classifier like NBC or SVM.

Prathik,

I guess this task is an original one and not resolved yet by anybody. So, we will be glad to work with you, we could develop a solution for your business case. You could contact to our marketing team, see “about” page for details.

Aleksey

Hello Aleksey,

What do you refer when you say contact our marketing team? Can you please be specific on this…

Hi Prathik Gadde,

>>What do you refer when you say contact our marketing team? Can you please be specific on this…

It was reply to

” Prathik said on 27-09-2009

the haar classisifier, which I trained is not detecting hand in some postures… It is very accurate but misses some gestures… should i use images with such gestures in the positive samples…

which algorithm is best for trainning this classifier??”

anusha,
There is tool convert_cascade.exe in C:\Program Files\OpenCV\samples\c, use it

Hi Vijay,

Thank you for your questions. I have forwarded your request to our marketing team (see “about” page for details).

Aleksey

Hi Alejandro,
Use first variant – createsample.exe in this case will cut Rectangle(7 20 64 128) from your image and will resize it to parameters you put in -w -h for createsample.exe
It’s very simple =)

Hello Vasiliy Mun,

I am training a hand detection classifier. I am using 4500 negative images and 5000 positive images for the training. The 5000 positive images are in different lightening backgrounds and they are distributed to 25 stage based on the complexities with max false alarm rate of 0.5. I faced a problem when running those. The program terminated after 13 stages and I generated a classifier for those 13 stages which is not effective. It is detecting almost everything is a hand. I have few concerns regarding this.

1. I used a constant red background in the images. Is there any problem by doing so (I will be usinig this classifier to detect in a steady background may be white)

2. Do I need to increase the negative images?

3. I used faces also in the negative images as I am afraid that the classifier detects the faces too. Do I need to remove those face images?

4. Is it that the classifier won’t work properly if it terminates in between?

This is the first time I am doing this training so I had these many questions.

Thank you for your patience.

Regards,
Prathik gadde.

Hello Prathik,

1. Don’t use constant background, because your classifier will be learned only for this background. it’s better to use some noise in background.
2. Use 4000 negative and 2000 positive
3. In negative you can use all objects apart from hands.
4. If training terminates due to false alarm rate achieved – it’s bad.

Thank you. I will train the classifier with the images with noise. For number of splits I gave 0 is that ok or do i need to mention it 1

it is ok to use 0. it’s default value for -nsplits, so you may not use -nsplits at all.

Thank you for your immediate reply. I didn’t mention anything. I will let you know if I have any problems.

To Nishant:
It means, that too much false positives were found e.g. on negative images, program finds your object( hand ).
Don’t use -nsplits. Nsplits is needed to build tree based xml cascade. Without this key, stump based xml cascade – it’s better with small nubmer of pos and neg.

Your positive images maybe not good. Negative images are “far from hands”?

Ok! Thanks for the info.

I’ll try again with new images. Can the negative images contain faces, torso, etc without hands and still work? Or should i avoid all those types of pictures and take only images containing backgrounds?

As for the positive images, most of the hands in the current set were upright, at around 90 degrees and without much rotation and tilt. And they all had a constant background – a wall. So should the new set of positive images contain hands in any position and a mixture of backgrounds? Or should i stick to what i did before?

Sorry for pestering you with these questions.

Again, thanks a bunch.

Hi Nishant,
1. Negative images should not contain hands and similar objects
2. First use one position of hand. For exampl up right. Of course it will detect hands only in such position.
3. Don’t use constant background, fill background with noise, so that feature were on object and not on constant background.

Alejandro,
proportion should be the same.

You can use global variable – it’s question of programming, not of computer-vision =)

Hello Vasiliy,

Sorry for the late reply… What do you mean by global variable… what are you referring to?

Hello Prathik Gadde,
You wanted to take get stage_sum when detect objects.

Hey,

I managed to get stage_sum from cvRunHaarClassifierCascade using structure similar to cvAvgComp.

I think, it is more easier than global variable : )

Thank you Vasiliy for all of your inputs… : )

Hello Vasiliy,

How can I run haartraining in unix… is there any resources you can suggest…

You are welcome =)

Hello Prathik Gadde,
we made parallel version of haartraining for linux cluster, you can try to compile opencv for linux and run it.

Should I complile the haartraining.cpp on linux and then do the training

Hi, yea compile it for linux

Hi Prathik,

Is it possible for you to share your haar cascade xml file with me. I’m at my wits end trying to get training done (i’ve tried it 6 times already with no hint of success).

So, if you wouldn’t mind, it would be really helpful.

Thanks,
Nishant

Hi nikkey,

Detection time depends on scale_factor, and min w, h you used during training.
Also it depends on what type of cascade you are using, stump or tree based (cluster), the second one is faster.
Min_neigbours also affect detection speed( the more neigbours you want, the slower detection is )

One minute is very much for 450×300 image. On PC Intel 4 2.7 GHZ it should take < 10 sec.

1-finnaly i have to know that, to detect human in real time what is the best way?
2-Can I use haar features to detect human accurately (more than 95% accuracy) in outdoor?

Well, I could say nothing without investigation. As I know there are some published arcticled by Viola and Jones about human detection. They use special additional features, which are not implemented in OpenCV

Hi Rappie, if nsplits > maxtreesplit, tree will not be build. In code there is such cond:

{
building nodes of tree
} while( falsealarm > maxfalsealarm && (!maxsplits || (num_splits < maxsplits) ) );

Jedota,

Well, what classifier you want?

1. If you want classifier which finds only woman faces, you should use woman faces only as positive and not-woman-faces( even not faces ) as negative. use proportion 1:2 = pos: neg
2. If you want classifier to say on photo of face if it’s woman or man, get for example N 24×24 woman faces as positive and about 100*N man 24×24 faces as negative, if you have N woman faces and 2N man faces, I could not say if your classifier will work or not…

Jedota,

This question is too popular in this post. If the distance between two classes is big, then it is easy to make hyperplane even with most popular AdaBoost and SVM classifiers or with Viola-Jones (Haar Training in OpenCV). The problem is that woman face and man face classes are too similar than face and “no face” classes are too different. And the distance between woman face and man face is too small. I tried to use AdaBoost for gender recognition with Haar features (even without HaarTraining), it required 4000 features and more and still had poor quality. But such amount of Haar features are enough for other tasks (like face detection in Viola-Jones) .

Aleksey

Hi
faces are assumed to have already been identified, this si the first part, now the second part I need to classify this faces in man and woman

regards

what can I do?

I read that LBP has good results. the train_cascade function of opencv 2.0 have this implemented. you know to use it (parameters)

regards

Hi jedota,

We had bad results with gender recognition using Adaboost. So we write our own gender recognition classifier using template matching, not Adaboost.
But we could not publish all details and technology.

Hi
I am working on Opencv haartraining for hand shape identification and I can not even identify object in positive images used for training.

I have followed the following steps:

1) I Created a folder “temp” under c: and then two other folders namely positives and negatives under temp folder
i.e, the path of temp is c:\temp
the path of positives is c:\temp\positives
the path of negatives is c:\temp\negatives
2) Placed 4 of my positive images in a folder called rawdata and placed that folder inside the folder positives .
i.e, the path of rawdata is c:\temp\positives\rawdata

3) Placed 7 negative images in the negatives folder

4) created a batch file “create_list.bat” in the negatives folder which contains the following line:

dir /b *.bmp > infofile.txt

5) Double clicked on the bat file.
infofile.txt is created and contains lines like the following lines:

image2619.BMP
image2620.BMP

6) Copied performance.exe, createsamples.exe and haartraining.exe from the bin folder of Opencv folder

copied all .dll files from the bin folder of Opencv and pasted them in
(i) temp folder
(ii) in temp\positives folder

(7) pasted objectmarker.exe in positives folder and also pasted the .dll files associated with objectmarker.exe in the positives folder

(8) Double clicked on objectmarker.exe and marked objects of positive images one by one.

The following keys were used:
save added rectangles and show next image
exit program
add rectangle to current image
any other key clears rectangle drawing only

info.txt file is created with following content

rawdata/1.bmp 1 39 68 94 123
rawdata/2.bmp 1 70 55 74 112
rawdata/3.bmp 1 27 47 71 114
rawdata/4.bmp 1 39 59 59 86

(9) in command line the following commands were given

c:\> cd temp
c:\temp> createsamples.exe -info positives/info.txt -vec data/positives.vec -num 1 -w 24 -h 24

positives.vec file got created in data folder

(10) in command line the following command is given

haartraining.exe -data data/cascade -vec data/positives.vec -bg negatives / infofile.txt -npos 4 -nneg 7 -nstages 20 -mem 1000 -mode ALL -w 24 -h 24 -nonsym

The last few lines of output looks like…………….

Precalculation time: 0.03
+—-+—-+-+———+———+———+———+
| N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
+—-+—-+-+———+———+———+———+
| 1|100%|-| 1.000000| 1.000000| 0.000000| 0.000000|
+—-+—-+-+———+———+———+———+
Stage training time: 0.00
Number of used features: 1

Parent node: 7
Chosen number of splits: 0

Total number of splits: 0

Tree Classifier
Stage
+—+—+—+—+—+—+—+—+—+
| 0| 1| 2| 3| 4| 5| 6| 7| 8|
+—+—+—+—+—+—+—+—+—+

0—1—2—3—4—5—6—7—8

Parent node: 8

*** 1 cluster ***
POS: 1 1 1.000000

(11) folder 0,1,..,8 are created in side the data/cascade folder and each folder contains a file

AdaBoostCARTHaarClassifier.txt

(12) copied haarconv.exe file and pasted them in temp file

(13) in command line the following command is given

c:\temp>haarconv.exe data/cascade output.xml 24 24

output.xml file gets created..

But when I am trying to use this xml file to detect object it is not working at all..

Thats why I felt that I must have done something wrong while following the above steps

I shall be really grateful to u if U kindly go through my text and let me know where I have gone wrong…

One more thing that I want to know is about the sample size….what does it actually mean??

Write a comment