Thursday, August 18, 2011

Creating a haar cascade classifier aka haar training

In the previous posts, I used haar cascade xml files for the detection of face, eyes etc.., In this post, I am going to show you, how to create your own haar cascade classifier xml files. It took me a total of 16 hours to do it. Hope you can do it even sooner, following this post

Note : The below is only for linux opencv users. If you are a windows user, use this link

For most of the dough, that is going to come, you will need these executable linux files. Here's the link for it.

Before I start, remember two important definetions

Positive images : These images contain the object to be detected
Negative images : Absolutely except that image, anything can be present

It's better to explain, with an example. So I will tell you, a step by step procedure, to make a classifier that detects a pen. You can use the same for any object, you are going to experiment.

First of all, I took the photographs of three of my pens, along with some background, the pics looked like the one below


I took a total of 7 photographs (I didn't care to count, for which pen, I took more photographs, out of three) with my 2MP camera phone and loaded them into my computer. Now I cropped, each one of them using Image Clipper excluding the background and storing only the pen's image. Image clipper can be downloaded from the link below

http://code.google.com/p/imageclipper/

The one thing that I hated about this imageclipper is that even though it made me work fast, it requires me to install a lot of other libraries. It would have been much simpler, if I just used GIMP, to crop, since there were only 7 images and cropping would have been easier. It is upto you, to follow the way you find easier.The cropped image looks like the one below


From here on the procedure is simple. As I told you at the starting of post, after downloading the necessary linux executables, keep them in a seperate folder named "Haar_Training", where you need to carry on your experimentations. Now inside that folder, create three folders and fill them with the necessary data, as explained below

1. Positive_Images : In this folder, I kept all my seven cropped images
2. Negative_Images : In this folder, I kept some other images (99 in total), which can be any image that you have, except, they should be of like genre and should not contain any where the cropped part i.e., pen
3. Samples : Keep it empty

Now, your Haar_Training folder looks like this


Now, navigate into that Haar_training folder through terminal. In the folder named "Positive_Images", the images are in png format and in "Negative_Images", they are in ppm format. So accordingly, I collected the information about those files in two text files named postives.dat and negatives.dat repectively using the below two commands


find ./Negative_Images -name '*.ppm' >negatives.dat
find ./Positive_Images -name '*.png' >positives.dat

In the next step, I used the samples folder, to store the training samples, by issuing it as arguement, along with positives.dat and negatives.dat using the below command

perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples  -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 160 -h 20"

The important arguements in the above command, to be discussed are
positives.dat - Contains the list of positive image paths
negatives.dat - Contains the list of negative image paths
samples - The folder that is used to store the data of training samples
250 - No. of training samples
-w 160 -h 20 - These two signify the width and height ratio of the pen. Originally it's -w 20 -h 20 for face. But, since I am using a pen here which is long and thin unlike face I made it 160 and 20


The next two commands use the data in samples folder to create a unified training data, that is used for haar training

find samples/ -name '*.vec' > samples.dat
./mergevec samples.dat samples.vec

Finally, run this command


opencv_haartraining -data haarcascade -vec samples.vec -bg negatives.dat -nstages 20 -nsplits 2 -minhitrate 0.999 -maxfalsealarm 0.5 -npos 250 -nneg 99 -w 160 -h 20 -nonsym -mem 2048 -mode ALL

This creates the haarcascade xml file desired by us in the same Haar_training folder, keeping all the meta data, that is forms in the meanwhile in the haarcascade folder, which is created automatically. The arguements to be noted in the above command are

haarcascade : The folder in which meta data can be kept
samples.vec : The unified training data, that we created just a while ago, before this command
negatives.dat : The list of negative image paths
20 - Stages, the more, the better, but great time consumer
99 - No. of negative images
2048 - The RAM memory that can be used

It took me five hours for this process to complete and generate my final pen detector. If you are a bit skeptic about the final outcome, instead of waiting for five hours, at any time, when the above command is running, you can issue the below command, to generate a intermediate haar cascade xml file, from the data available.

./convert_cascade --size="160x20" haarcascade haarcascade-inter.xml
Now finally after five hours, I got the haar cascade xml file. As I have shown you, in the previous posts, the way to use haar cascade xml files. I experimented on some pens of my own. Below is the youtube video for it.







Update (16 March, 2012): On the request of people I am sharing the haar classifier file for Pen detection. Below it the link for it.

Pen detector

Please note that I used very less sample images, less than a 100 to create it, while in reality we use at-least 5000-10000 images to create a robust classifier. So, it may give false positives in some cases

Update (25 March,2012): The link to the executable Linux files that I gave earlier is slowly loading or sometimes not working at all. So here's the new link for it

Linux Executables

Update (16 Nov,2012): Some of the commands, go out of page. For them select the first few words of the command; press shift+end; and then copy

81 comments:

marwa hmida said...

Hi,
Can you send me please your haar classifier?
Thanks in advance

Dileep Kumar said...

Hello Marwa,

I have updated this post(in the bottom) to include the link to the haar classifier. I have deleted your comment with your mail ID since it may introduce spam to you.

marwa hmida said...

Thank you very much

marwa hmida said...

Hi Dileep,
I can't download the executable linux files.
Can you send me your Haar_Training folder (with positive and negative images...).
Thanks in advance

Dileep Kumar said...

Updated the post; now you can download Linux executables, easily from the link given at the bottom of the post.

marwa hmida said...

And what about positive and negative images?

Dileep Kumar said...

That will be a very big database to share or send. Creating those databases shouldn't be a problem for you. For positive images, I just took photographs of my pen and cropped them, so that only the pen is visible. For negative images, take any kind of images - any image you want as long as the image doesn't have pen in it.

marwa hmida said...

Hi Dileep,
Is there any problem if i use negative images in png format?wahat is the software that you used to save images in ppm format?
thanks a lot

RINSON said...

do you have any other xml files for object detection.pls send it if you have.thnx in advance

Dileep Kumar said...

Marwa,
It's not a problem, but since the negative images I had were in ppm format and so inorder to find them all at a time I used '*.ppm'.

Rinson,
Sorry, I have the collection related to human biometrics like face, eyes, left eye, right eye etc.,

But it's very intuitive. Just let me know if you face any problem in following the above said process

tjv said...

hi dileep, i followed your steps for creating an xml for mobile phone detection. does the size of positive image affects the speed of training? i used 50*75 but the training seems to be stuck at stage 4. i tried it several times but the process get stuck either at stage3 or at stage 4
pls help..

Dileep Kumar said...

tjv,
Good that you tried to create one by yourself. Did you try to create an intermediate classifier at that stage using the last of the commands that I mentioned ? If yes, howz the performance using it?

Size of positive samples shouldn't be a problem. I used 157*1096 sized ones. And the timing speed solely depends on the number of training samples. How many are you using ? 250 ?

tjv said...

hi dileep,
first of all thanks for your reply,
i used 250 samples for the process
and this is where iam getting stuck,
Tree Classifier
Stage
+---+---+---+---+
| 0| 1| 2| 3|
+---+---+---+---+

0---1---2---3

Number of features used : 11017037

Parent node: 3

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

from here onwards the process wont proceed further i tried for more than 6 hrs also icant insert the create intermediate cascade command here.
can you suggest a solution?

tjv said...

hi dileep,
i created an intermediate xml file at stage 4,
but it showed lots of false results, its a 5kb file.

Dileep Kumar said...

tjv,

Did you change the -w and -h? These attributes tell d width and height in the above said commands. Since a pen's width is very high compared to it's length, I took '-w 160 -h 20'. This is the least sized object that I could find in a given scene. If it's size is greater than this, I could find, but if it's less, I fail. So as per the mobile phone size, change the dimensions to be the minimum level, but make sure you don't keep them so minimum that you lose robustness.

My final classifier is around 25Kb.

Also, try changing the various parameters in 'opencv_haartraining' command, like reducing the number of stages, increasing splits etc.,

Mario said...

Hi Dileep, can you share your pen detection code?

Dileep Kumar said...

Hello Mario,
It is exactly similar to the face detection code
http://opencvuser.blogspot.in/2011/06/face-detector.html
except when you refer the haarcascade xml file ( char filename[]="haarcascade_frontalface_alt.xml";), you refer to the haar cascade file that I mentioned in this post.

Mario said...

Really nice tutorial, thank you for the link's and code

nicolas said...

When I try the command. / Createtestsample me it generates no files ".vec" you have a solution?

ps: I tried on mac and linux same result...

Adil Soomro said...

Same here, it doesn't generate any ".VEC" file, I'm trying on mac.
below is the result, which is echoed during the process:

...
Info file name: samples//03BC7FCB287F4A2E.png/info.dat
Img file name: ./Positive_Images//03BC7FCB287F4A2E.png
Vec file name: (NULL)
BG file name: tmp
...

Any solution?

Dileep Kumar said...

When you run the command "perl createtrainsamples.pl positives.dat negatives.dat samples 250 ......" as stated in the above post, it should generate ".vec" files in the samples folder. Or is there some problem with perl in mac ? .

I tried in my Ubuntu and it's working fine

Adil Soomro said...

I figured that out. however now I'm stuck on
"mergevec samples.dat samples.vec"

I got yours mergevec.exec, but it gives error

"cannot execute binary file. "

Any Idea?

Dileep Kumar said...

what exactly is the problem you are getting when the command "mergevec samples.dat samples.vec" gets executed ?

Try using "./opencv_createsamples -info samples.dat -vec samples.vec -w 160 -h 20" instead of dat command and try again, replacing the correct width and height at -w and -h

Adil Soomro said...

Now the problem I'm facing is, I can't merge vec files using mergevec.exec, whenever I run this command
mergevec samples.dat samples.vec

it says:
bash mergevec: cannot execute binary file

Dileep Kumar said...

So the problem is with mergevec executable. Try changing it's permissions using chmod or running it in a shell other than bash.

Try to replace that command with the command in my previous comment and complete haar training

Adil Soomro said...

Thanks Dileep..!!

I copied all of my material to an Ubuntu system and perform mergevec there successfully and then came back to mac :p

Thanks again.

koji said...

I have a createtrainsamples.pl in my working directory but entering the command does not quite seem to output anything to my samples folder. im using windows and using cygwin terminal for all the linux commands. i've been reading your tutorial and http://note.sonots.com/SciSoftware/haartraining.html#tbc650a5 tutorial. hope you could help me with this.

Jad Chmaytilli said...

Dileep, I would like to thank you for posting this. It is exactly what I need for my project.

However, I am having issues concerning the "perl createtrainsamples.pl positives.dat ..." (it is createtestsamples.pl right ? just to make sure):

The command works and it is generating the samples with the distortions and all, but the problem is that it does not generate the .vec files. --> Vec file name: (NULL). Here is the output of one of the files:

opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 24 -h 20 -img ./Positive_Images/5.png -bg tmp -info samples/5.png/info.dat -num 31
Info file name: samples/5.png/info.dat
Img file name: ./Positive_Images/5.png
Vec file name: (NULL)
BG file name: tmp
Num: 31
BG color: 0
BG threshold: 0
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: 24
Height: 20
Create test samples from single image applying distortions...
Done

I hope you reply as soon as possible, and I hope that I am not taking a lot of your time.

Thanks in advance Dileep.

Dileep Kumar said...

@toall

I am busy till 26th of this month. Have to travel a lot.

Try the links given in the blog of sandarenu regarding haar cascade classifier. They were ample to solve majority of the problems.

But in between if i got time, i will look into your problems

Alex Wu said...

Thanks for the post Dileep, but I have an odd error. When trying to execute the mergevec, it says error while loading shared libraries: libml.so.2.1:cannot open shared object file: No such file or directory. I already chmodded mergevec with 777, is there anything else I should do?

hiposai said...

I cannot run the "./convert_cascade" command. The import files are missing.

Alex Wu said...

Additionally, nothing is created in the samples folder after executing the Perl program.

Moiz Adamjee said...

Hi Dileep .. Can u tell me the working of OCR i have to implement it using opencv libraries but dont know from where to start ..
tell me how can find a letter from an image and how can i make segments of every letter .. ??

thanks in advance..

Dileep Kumar said...

@Koji
I too followed that notes. Try with the createtrainsamples.pl in the link I have provided.

@Jad
Thanks for pointing it out. Actually it's what I have given, createtrainsamples only. But I forgot to keep that executable in the link. Now everything is set right. Try again with the createtrainsamples.pl provided in the link to executables to get .vec

@Alex Try chmodding the whole directory, where you are doing the haar training. Please try again for the samples folder (perl program), with the executable from the updated link of executables, now. I have updated it.

@Hiposai
Can you elaborate and paste the error here ?

@Moiz Optical Character Recognition or OCR is a very interesting field. I haven't worked on it, but one of my friends did research on extracting and recognizing the numbers from a number plate. You can read his thesis here http://ethesis.nitrkl.ac.in/3352/.

He worked with openCV in windows and he may be the one to help you better. Best of luck for your project.

thejoker said...

Hi Dileep,
I'm using OpenCV for a face detection application. I have a performance issue with face detection, and I want to train my own haar classifier to see if I can bring down the execution time. Do you have any idea as to what the minimum number of positive samples should be for decent accuracy? Also, do you have any approximation about time taken for training haar classifier vs. time taken for training lbp classifier?
P.S - I'm an alumni of NIT Rkl. :P

Dileep Kumar said...

For decent, atleast 5000 positive samples would do. But it's simply waste of time to make your own classifier, when there is already one. Don't try to reinvent the wheel. In the opencv installation folder, if you search, there is a folder exclusively for haar classifiers. In that there are around 3-4, exclusively for face. Try with them. I donno about lbp, but to train a decent haar classifier, it would take 15-20 days, if you leave your computer as is

Nour said...

Dileep, I would like to thank you for your great efforts
But please...I already downloaded the code in ur given link
http://opencvuser.blogspot.in/2011/06/face-detector.html
when i try it it build successfully but it gives me the error message
Assertion failed:cascade && Membuffer && capture line 46
I'm working on Win XP and VS 2010
Please Help me as I'm beginner in AR field

Quingshan Zhang said...

Hi Dileep, thanks very much for this article and it's really helpful. Just one small question, is there any width and height ratio requirments in the cropped images? I mean, do they have to be with the same width and height ratio when be cropped?

mesteruh mesteruh said...

opencv_haartraining -data haarcascade -vec samples.vec -bg negatives.dat -nstages 20 -nsplits 2 -minhitrate 0.999 -maxfalsealarm 0.5 -npos 250 -nneg 99 -w 160 -h 20 -nonsym -mem 2048 -mode ALL
Data dir name: haarcascade
Vec file name: samples.vec
BG file name: negatives.dat, is a vecfile: no
Num pos: 250
Num neg: 99
Num stages: 20
Num splits: 2 (tree as weak classifier)
Mem: 2048 MB
Symmetric: FALSE
Min hit rate: 0.999000
Max false alarm rate: 0.500000
Weight trimming: 0.950000
Equal weights: FALSE
Mode: ALL
Width: 160
Height: 20
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-07

Tree Classifier
Stage
+---+
| 0|
+---+


Number of features used : 6858870

Parent node: NULL

*** 1 cluster ***
POS: 0 0 -nan
OpenCV Error: Unspecified error (Unable to obtain positive samples) in cvCreateTreeCascadeClassifier, file /build/buildd/opencv-2.3.1/modules/haartraining/cvhaartraining.cpp, line 2467
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.3.1/modules/haartraining/cvhaartraining.cpp:2467: error: (-2) Unable to obtain positive samples in function cvCreateTreeCascadeClassifier

Decio Schmitt said...

Hello Dileep Kumar,

I'm trying to create my own classifier, firstly I would like to thank his otimo tutorial.

I am facing a problem and I'm very grateful if you could help me.
The mergevc compiled which you provided not worked on my 64-bit ubuntu.
I downloaded the source and tried to compile it into the source of the opencv haartraining however got an error:

erro fatal: cvhaartraining.h: file not found

Any idea how to solve?

Or by chance you do not have a mergevc compiled for 64-bit version to send me?

Thank you in advance.

Dileep Kumar said...

Sorry, that I don't have one for a 64-bit ubuntu version for the same. The problem you are facing is clear that the header file cvhaartraining.h is missing. Google for that header file and keep it in the same folder where you are doing the training and try again

Ronald said...

Hi, I got this error "./opencv_createsamples: ./opencv_createsamples: cannot execute binary file" when running "pecl ..." and "zsh: exec format error: ./opencv_createsamples" when running "opencv_createsamples ...".

Did you have any ideas about that??

Thanks in advance.

nguyễn sỹ huy said...

i have a problem . I run this command "perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 160 -h 20", but "createtrainsamples" is empty and no .vec file can be found. And i have a question about format of negative and positive images, can i use jpg format?

ABHI said...

hi Dileep i run all commands mention by you postive.dat,negative.dat ,sample.dat file is also made but when i run this command:
find samples/ -name '*.vec' > samples.dat
./mergevec samples.dat samples.vec
on terminal i got error bash: ./mergevec: Permission denied
please help on it
Thanks in Advance

Dileep Kumar said...

Hi Abhi,
Make "chmod 777 *" in the folder where you are running the tests. Let me know if the issue gets resolved.

Hi huy,
you cannot use jpg format; I haven't tested it, but even if it works, you know the fact the jpg uses compressioin techniques that take the originality of bits present per pixel away. So, better to stick with .bmp or .png

Are you referring to createtrainsamples.pl as being empty?

Ronald,
Please try in a 32-bit Ubuntu, that has proper perl and opencv 2.1 installation. Many people have reported problems with other variants..

ABHI said...

hi Dileep,
i still got same error as i new to linux ios so not much know about its commands .i paste here the command line o/p's please help me on this
root@nitin:/media/New Volume/Haar_Training# find samples/ -name '*.vec' > samples.dat
find: `samples/': No such file or directory
root@nitin:/media/New Volume/Haar_Training# ./mergevec samples.dat samples.vec
bash: ./mergevec: Permission denied

Dileep Kumar said...

Abhi,

It's pretty clear that there is no "samples" folder at all in the directory.

In the first step, where I suggested to create three folders, did you create "samples" - as one of the three. And then when you use "createtrainsamples..." command, the samples folder gets populated. Make sure, these both are done, before moving onto your next step

ABHI said...

Hi Dileep,
i created the sample folder when i run command to create sample.dat sample.dat file created inside samples folder & 1 outside inside Haar_Training but both contain no data (0 byte) after that i run command find samples/ -name '*.vec' > samples.dat
./mergevec samples.dat samples.vec
but it showing error O/p
root@nitin:/media/New Volume/Haar_Training# find samples/ -name '*.vec' > samples.dat
root@nitin:/media/New Volume/Haar_Training# ./mergevec samples.dat samples.vec
bash: ./mergevec: Permission denied

please help me on this im using AMD processor sysyem having Ubuntu OS .
thanks in Advance


ABHI said...

thanks alot dileep i use the link in which method to create haar xml for window system its works & i got xml

Vrushali Akant said...

Hi Dileep,
i m trying to create unified training data. i executed
find samples/ -name '*.vec' > samples.dat
./mergevec samples.dat samples.vec
these 2 command.
but i m getting the following error
./mergevec: error while loading shared libraries: libml.so.2.1: cannot open shared object file: No such file or directory
.
and libml.so.2.1 is not is usr/local/lib. i also tried to set the path in bashrc file.
any solution?


Dileep Kumar said...

This may be due to the problem with your openCV installation. Please see my previous post on openCV installation on how to confirm, whether openCV is properly installed or not

Vrushali Akant said...

Ok.. thank you. :)

Vrushali Akant said...

Hey Dileep,
I have installed OpenCV 2.4.1 from the following link.
http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/
All the samples are running fine.
So i guess the problem is not with installation.
Because I am getting the same error.

dgd said...

hi Dileep

when I run the last command, stay in this screen:

http://dl.dropbox.com/u/40163724/tela.png

it's normal before generating the haar cascade?

vikas60vasani said...

i am creating xml file for detecting a cell phone.
i have used 2000 positive images with size 320*240 and m creating samples with following command:
"perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 24 -h 24".

my question is that is it necessary to convert positive images to 24*24 size first or they are converted automatically?

i have doubt for -w(width) and -h(height) parameter in above command whether this parameters are size of object(cell phone) or they are size of positive image?

pls help...

Dileep Kumar said...

Hii dgd,
The pic is not opening due to some authentication issues, since I use my company laptop. Can you upload it in Picasa..

Hii Vikas60vasani,
They are converted automatically. They are the size of positive images, that are going to be generated by running that command

vikas60vasani said...

Hi dillep!!!
I m still confused with -w and -h parameters in createsamples.pl command.

Actually i have 320*240 sized images and i am creating samples with this command "perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 24 -h 24".

will it work?

Or i have ti use "perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 320 -h 240".

and if i keep my positive images size to 24*24 than it becomes very small and i m unable to mark the object from it in objectmarker tool. so i have kept the positive images size to 320*240. Pls tell me what should be my -w and -h values.(i m detecting cell phone in positive images)

pls help.

Dileep Kumar said...

Hii,

There is no 24*24 in the command I have mentioned. It's 160*20. That is the minimum size of the pen, that I want in an given large image to be detected. One more thing to note here is, that it is the size of pen, not the whole positive image(sorry that I have told it's positive image size in my previous comment).


Now let's go to your cell phone, which is 320*240 is width and height. If it is the cell phones width and height and it is the minimum size you want to detect, you can keep it as "perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 320 -h 240"". But if the whole image in which the cell phone is present is some 300*200 photo, then it's not possible to detect cell phone. Now the whole image, in which you are detecting cell phone should be greater than 320*240 in size.

vikas60vasani said...

In the following command:
perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 160 -h 20"

what means to 250..? it is no. of positive sample? or negative or Positive + negetive samples?

Dileep Kumar said...

First of all you have to understand the difference between both images. Positive images are images of pen and negative images are images of scenes with out pen. So putting the positive on negative images, will give us a scene with a pen inside it.

Those 250 are thus the scenes that contain pen, are being generated. These were needed to train our classifier

Manoharan H said...

Hi dear Friend's,
I'm doing my project in FPGA based Face recognition using Haar Classifier Algorithm. i want to know how to set the threshold value's in cascade(PIPELINE scheme) method.

After getting the two or three Haar-Like Feature, to add that feature value's. that result is Final haar feature classifier resultant value, then that resultant value compare with the Feature Threshold vale.

And also the accumulator value also compare with the Stage threshold value.

I have some doubt setting the threshold value's.

what is meant by feature threshold value, then how to set that feature threshold value? And

What is meant by Stage threshold value? How to set that stage threshold value's ?

I want detail about that threshold value's ???

by, Mano.H(TN)

HASHEM said...

^_^ thank u that's really helpful

Alok Kashyap said...

Thank you very much.
Its a good and nice tutorial.
Worked in windows.Had problem in the perl command in linux.

Hassan Murat said...

Hi Kumar.
I have a problem. If I want to merge samples.dat and samples.vec i am getting always an error:
Error while loading shared libraries: libcvaux file is too short

Please help
Thanks

Dileep Kumar said...

Hi Hassan,

'libcvaux' is a file related to opencv. So, I guess the problem is with opencv installation or may be due to compatibility issues. Can you try in open cv 2.1 and Ubuntu; If you don't have, can you try in one of your friends and check the result.

One thing I can suggest is to have a look at one of my previous posts of openCV installation, where I have given some checks to know whether it is properly installed or not

Hassan Murat said...

Hello Kumar,
After installing Ubuntu 10.04 with OpenCV 2.1 i am able to generate a xml-file.

Thanks for help

Hassan Murat said...

Hi
I have another problem now. I want to generate the xml file with 170 positive images and 100 negative images. After typing "opencv_haartraining -data haarcascade -vec samples.vec...." in the console there is always written "killed". Can you help please?
Thanks

Dileep Kumar said...

This is the first time I am hearing such problem. Can you paste the logs. I believe the error may be due to permissions to access the files. Can you give "chmod 777 *" and try again

Hassan Murat said...

Hello Kumar,
I can not give you more information because in the console there i can see only:
"Tree Classifier
Stage
0

Killed"

Info what i am doing:
1)I have 179 positive images. The positive images contains only the object of interest(size 200 x 150).
2)100 negative images.

My Commands:
1)find ./Negative_Images -name '*.jpg' >negatives.dat
2)find ./Positive_Images -name '*.png' >positives.dat
3)perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples - bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 200 -h 150"

4)opencv_haartraining -data haarcascade -vec samples.vec -bg negatives.dat -nstages 20 -nsplits 2 -minhitrate 0.999 -maxfalsealarm 0.5 -npos 179 -nneg 100 -w 200 -h 150 -nonsym -mem 2048 -mode ALL

Another thing:
In my samples folder there are only 179 *.vec files. Is it right?

Thanks for help

Dileep Kumar said...

After -npos, give "250" in the 4th command you have mentioned, instead of 179 and try.


If the above doesn't work
===========================
Also, in your samples folder, there should be 250 *.vec files. I guess while running the 3rd command, you gave 179 in place of 250.

Marcus Vinicius Rangel Renno said...

Just to say thank you, man!!!

Pulak Bhushan said...

hi dileep sorry to disturb you my . vec file is not created after

perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 160 -h 20"

please help me if possible

Dileep Kumar said...

Are you sure, that positive.dat and negatives.dat exist. Also, any error messages appeared?

The .vec files were created inside "samples" folder. Did you check inside that?

Rachel Aron said...

Hi Dileep, this is a fantastic tutorial! Trying to get this to recognize flowers (specifically, daffodils)
However, I'm having the same problem that some others were having earlier in the comments. I'm using a Mac, and I'm having trouble with this step:

./mergevec samples.dat samples.vec
It returns "cannot execute binary file".

I was able to make the samples.dat file, but not the samples.vec, and I don't have access to linux as the other person did to solve their same problem. I'm very new at using terminal, and I"m not sure how to change the shell out of bash as you suggested. I've got the positives.dat and negatives.dat files. though.

Hassan Murat said...

Hello Kumar,

i solved my problems with this link:
http://nayakamitarup.blogspot.co.at/2011/07/how-to-make-your-own-haar-trained-xml.html

Thanks for your effort and time
Baris

Dileep Kumar said...

Cool man. If you have only windows that's the best solution.

Robert Svec said...

Thanks for the tutorial. Do you have any plans on releasing an updated tutorial for the current Ubuntu/64-bit/OpenCV versions?

Dileep Kumar said...

Hi Robert,
no man. Right now I am working full time and preparing for some exams.

Radiation Proctector said...

hello Dileep Kumar,

i'm using this command it didn't generate any file is it any mistake?? my picture is w=189 h=232(because more than one picture so the picture size will slightly different a bit)
perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples  -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 160 -h 20"

Dileep Kumar said...

Is it throwing any error. Can you paste it? The size of your picture is not an issue

aziza cheikhna said...

Thanks a lot for posting this tutorial;

i have a problem When I try the command. / Createtestsample on ubuntu it works without any errors but it doesn't generates any ".vec" files
can you help me plz ?


PS:

i used the same command i only edited the params:
perl createtrainsamples.pl positives.dat negatives.dat samples 250 "./opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 1183 -h 228"

Post a Comment