From:http://www.computer-vision-software.com/blog/2009/11/faq-opencv-haartraining/
Hi All, before posting your question, please look at this FAQ carefully! Also you can readOpenCV haartraining article.
Because a positive image contains the target object which you want machine to detect. Unlike them, a negative image doesn’t contain such target objects.
During haartraining positive samples should have the same width and height as you define in command “-w -h size”.
Yes, use Google, there are free tools, written by OpenCV’s community.
There is tool in C:\Program Files\OpenCV\apps\HaarTraining\src createsamples.cpp.
createsamples -info positive_description.txt -vec samples.vec -w 20 -h 20
The matter is that, on each positive image, there can be several objects. They have bounding rectangles: x,y, width, height.
positive_image_name
Text file, which contains such info about positive images is called description file. So during vec file generation,
Yes, with createsamples you need description file.
Yes, it’s very important. On each positive image, beside object, there is background. Try to fill this background with random noise, avoid constant background.
If you have much background pixels on your positive images in comparison with object’s pixels – it’s bad since the haartraining could remember the background as feature of positive image.
If you don’t have background pixels at all – it’s also bad. There should be small background frame on positive image
[For training we supply number of positive images, cropped to remove extra background down to boundaries of object. Cropped positive pictures are marked by surrounding rectangle (position and size of this rectangle is saved in positive images list). When you make this markup, you have to retain aspect ratio. Haartraining application will scale your positive images to size of (w,h) and this process must not disturb proportions of object.]
You can put any value to -w and -h depend on aspect ratio of the target object which you want to detect.
【
info.txt file:
pos/10003_frame.png 1 0 0 500 300
pos/10010_frame.png 1 0 0 500 300
pos/10021_frame.png 1 0 0 500 300
and the command line:
createsamples -info info.txt -vec pos.vec -w 25 -h 15
】
-First check you description file: positive_image_name should be absolute path name without spaces like “C:\content\image.jpg” not “C:\con tent\image.jpg” or relative path name.
-Avoid empty lines in description file
-Resolution of original positive image file should be not less, then -w -h parameters you put.
-Check that positive images are available in your file systems and not corrupted.
-There can be unsupported formats. Jpeg, Bmp, PPM are supported!
Let’s working directory be C:\haartraining. In it there is createsamples.exe. There is folder
C:\haartraining\positives. So create description file positive_desc.txt.
positives\image1.jpg 1 10 10 20 20
positives\image2.jpg 2 30 30 50 50 60 60 70 70
or
C:\haartraining\positives\image1.jpg 1 10 10 20 20
C:\haartraining\positives\image2.jpg 2 30 30 50 50 60 60 70 70
You should avoid empty lines and empty space in image’s path
createsamples -info positive_desc.txt -vec samples.vec -w 20 -h 20
You can use any image of OpenCV supported formats, which does not contain target objects (which are present on positive images). But they should be various – it’s important! Good enough database is here
No. But the size should not be less than -w -h, which were put during vec file generation.
It’s just text file, often called negative.dat, which contains full path to negative images like:
image_name1.jpg
image_name2.jpg
Avoid empty lines in it.
It depends on your task.
Good enough proportion is
Working directory is C:\haartraining with haartraining.exe tool and samples.vec file.
Let’s negative images are in C:\haartraining\negative, in this case negative.dat should be like this:
negative\neg1.jpg
negative\neg2.jpg
…
So in C:\haartraining launch this:
You should read theory of adaboost about strong classifier. Stage is strong classifier. In short:
Yes, there is dependency. You could not put minhitrate = 1.0 and maxfalsealarm = 0.0. .
Firstly, the system builds classifier with desired hitrate, then it will calculate it’s falsealarm, if the false alarm is higher than maxfalsealarm, the system will reject such classifier and will build the next one. During haartraining you may see such:
N |%SMP|F| ST.THR | HR | FA | EXP. ERR|
+—-+—-+-+———+———+———+———+
| 0 |25%|-|-1423.312590| 1.000000| 1.000000| 0.876272|
HR – hitrate
FA – falsealarm
Cascade is linked list (or three) of stages. That’s why:
Really all these parameters are related to Adaboost, read theory. In short:
These parameters are related to clustering. In Adaboost different week classifier may be used:stump-based or tree-based.
There is OpenCV/samples/c/convert_cascade.c. Use like:
convert_cascade –size=”20×20″ haarcascade haarcascade.xml
performance -data haarcascade -w 20 -h 20 -info positive_description.txt -ni
performance -data haarcascade.xml -info positive_description.txt -ni
It depends on task and your machine.
“The OpenMP (Open Multi-Processing) is an application programming interface (API) that supports multi-platform shared memory multiprocessing programming in C, C++ and Fortran on many architectures, including Unix and Microsoft Windows platforms“. If you have MT processor, you can use it.
Yes, one of possible ways is to use parallel programming. We have realized OpenCV haartraining using MPI for linux cluster. You can read it here
Yes. It is impossible to generate cascade, which can detect face in all orientations. But you can generate cascade for each orientation separately. For this you need positive content of rotated faces. You can try to generate cascade with OpenCV , add -mode ALL, with it tilted haar feature will be used. But it’s badly implemented, at least in OpenCV 1.1. If you want you can add your own feature to opencv haartraining – it’s not too hard.
Another approach is to write head pose estimator. Then rotate your pictures, so that you have frontal face and detect it with OpenCV default face cascade
We tried, but could not do it with OpenCV haartraining. That’s why for such classification, we used our own gender and attention classificators. Of course you can use Adaboost for this task, which is implemented in haartraining, but we did not get good results.
Yes.
1. How to add new features?
Is adding another cvHaarFeature() in icvCreateIntHaarFeatures
2.Endless loop,without termination.The reason?
endless loop happens if haartraining cannot extract enough negative samples (small images) from your negative images. Try to replace negative images with others of bigger size or more multifarious. You can stop training, change images and restart training. It will continue from the last successful stage.[更换样本后,程序是可以接着执行的,不用从头开始]
3.负样本大小?
The algorithm requires big negative images, the bigger the better (for example 1280×1024 for positive samples 20×20), don’t use images of size –w –h – it will not work. Haartraining will automatically extract millions of small negative samples from your negative images, so it need images with millions of subregions.
4.怎样确定 -w -h 的值?
Hi,
I am having trouble understanding how to determine the values for -w and -h :
example:
createsamples -info positive_description.txt -vec samples.vec -w 20 -h 20
How are the values “-w 20″ and -h 20″ determined?
Here is my situation:
example positive Image details
name: pos0001.bmp
width: 320 pixels
height: 240 pixels
In my description file for my positive images, the line for the above image look like this:
C:\BMPpositve\pos0001.bmp 1 17 81 232 64
This means that the bounding box that surronds the object of interest is of the following size:
width: 232
height: 64
232 divided by 64 = 3.625
Above it is stated that -w and -h are just aspect ratios? What will be the appropriate values in my case?
Here are other lines from my description file:First of all choose -w and -h parameters. See next paragraph how to choose it. In the second place make all bounding boxes in your description file of the same ratio as ratio of -w and -h. It may mean that you need to crop some of your current boxes and expand the others. Don’t use bounding boxes of different aspect ratios as they will be scaled and proportions will be distorted hence algorithm will never see in nature object it was learned.
As for value of -w and -h, all your images from description file will be cropped by bounding box and rescaled to -w -h. If you choose small size, it can be impossible to recognize object by small picture. But if you choose big size, it can be impossible for the algorithm to distinguish meaningful features of object and random noise. So quality of recognition depends on these size significantly. You should choose it by trial and error method. For face recognition sizes of 20×20 or 24×24 are commonly used. Start from something like this. Make sure that you can (by your eyes) recognize the object downscaled to chosen size. Don’t use size bigger than necessary.