1、FQAopencvhaartrainingFAQ: OpenCV HaartrainingPosted on : 10-11-2009 | By : rhondasw | In : OpenCV Hi All, before posting your question, please look at this FAQ carefully! Also you can read OpenCV haartraining article. If you are sure, there is no answer to your question, feel free to post comment. A
2、lso please, put comments about improvement of this post. This post will be updated, if needed.Positive imagesWhy positive images are named so?Because a positive image contains the target object which you want machine to detect. Unlike them, a negative image doesnt contain such target objects.Whats v
3、ec file in OpenCV haartraining?During haartraining positive samples should have the same width and height as you define in command “-w -h size”. So original positive images are resized and packed as thumbs to vec file. Vec file has header: number of positive samples, width, height and contain positi
4、ve thumbs in body.Is it possible to merge vec files?Yes, use Google, there are free tools, written by OpenCVs community.I have positive images, how create vec file of positive samples?There is tool in C:Program FilesOpenCVappsHaarTrainingsrc createsamples.cpp. Usage:createsamples -info positive_desc
5、ription.txt -vec samples.vec -w 20 -h 20Whats positive description file?The matter is that, on each positive image, there can be several objects. They have bounding rectangles: x,y, width, height. So you can write such description info of image:positive_image_name num_of_objects x y width height x y
6、 width height Text file, which contains such info about positive images is called description file. So during vec file generation, really objects are packed, but not whole image. Essentially vec file is needed to speed up machine learning.Do I always need description file, even if I have only one ob
7、ject on a image?Yes, with createsamples you need description file. If you have only one object, its bounding rectangle may be bounding rectangle of whole image. If you want, write your own tool for vec file generation =)Should lightning conditions and background be various on positive images?Yes, it
8、s very important. On each positive image, beside object, there is background. Try to fill this background with random noise, avoid constant background.How much background should be on positive image?If you have much background pixels on your positive images in comparison with objects pixels its bad
9、since the haartraining could remember the background as feature of positive image.If you dont have background pixels at all its also bad. There should be small background frame on positive imageShould all original positive images have the same size?No, original images can have any size. But its impo
10、rtant that width, height of this rectangle have the same aspect ratio as -w -h.What s -w and -h should I put in createsamples? Should it be always square? You can put any value to -w and -h depend on aspect ratio of the target object which you want to detect. But objects of smaller size will not be
11、detected! For faces, commonly used values are 2424, 2020. But you may use 2420, 2024, etc.Errors during vec file generation: Incorrect size of input array, 0 kb vec file,-First check you description file: positive_image_name should be absolute path name without spaces like “C:contentimage.jpg” not “
12、C:con tentimage.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
13、, PPM are supported!Example of vec file generation!Lets working directory be C:haartraining. In it there is createsamples.exe. There is folderC:haartrainingpositives. So create description file positive_desc.txt.positivesimage1.jpg 1 10 10 20 20positivesimage2.jpg 2 30 30 50 50 60 60 70 70orC:haartr
14、ainingpositivesimage1.jpg 1 10 10 20 20C:haartrainingpositivesimage2.jpg 2 30 30 50 50 60 60 70 70You should avoid empty lines and empty space in images pathcreatesamples -info positive_desc.txt -vec samples.vec -w 20 -h 20Negative imagesWhat negative images should I take?You can use any image of Op
15、enCV supported formats, which does not contain target objects (which are present on positive images). But they should be various its important! Good enough database is hereShould negative images have the same size?No. But the size should not be less than -w -h, which were put during vec file generat
16、ion.Whats description file for negative image? Its just text file, often called negative.dat, which contains full path to negative images like:image_name1.jpgimage_name2.jpgAvoid empty lines in it.How many negative/positive image should I take?It depends on your task. For real cascades there should
17、be about 1000 positive images and 2000 negative images e.g.Good enough proportion is positive:negative = 1:2, but its not hard rule! I would recommend first to use small number of samples, generate cascade, test it, then enlarge number of samples.Launch haartraining.exe (OpenCVappsHaarTrainingsrc)Ex
18、ample of launchingWorking directory is C:haartraining with haartraining.exe tool and samples.vec file.Lets negative images are in C:haartrainingnegative, in this case negative.dat should be like this:negativeneg1.jpgnegativeneg2.jpgSo in C:haartraining launch this: haartraining -data haarcascade -ve
19、c samples.vec -bg negatives.dat -nstages 20 -minhitrate 0.999 -maxfalsealarm 0.5 -npos 1000 -nneg 2000 -w 20 -h 20 -nonsym -mem 1024 w h is the same, you put during vec file generation npos nneg number of positive samples and negative samples mem RAM memory, that program may use maxfalsealarm maximu
20、m false alarm, that stage may have. If big false alarm it could be bad detection system minhitrate minimal hit rate, that should stage have at least nstage number of stages in cascade What s falsealarm and hitrate of stage?You should read theory of adaboost about strong classifier. Stage is strong c
21、lassifier. In short: For example you have 1000 positive samples. You want your system to detect 900 of them. So desired hitrate = 900/1000 = 0.9. Commonly, put minhitrate = 0.999 For example you have 1000 negative samples. Because its negative, you dont want your system to detect them. But your syst
22、em, because it has error, will detect some of them. Let error be about 490 samples, so false alarm = 490/1000 = 0.49. Commonly,put false alarm = 0.5 Are falsealarm and hitrate depend on each other?Yes, there is dependency. You could not put minhitrate = 1.0 and maxfalsealarm = 0.0. .Firstly, the sys
23、tem builds classifier with desired hitrate, then it will calculate its 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.
24、312590| 1.000000| 1.000000| 0.876272|HR hitrateFA falsealarmWhats falsealarm and hitrate of whole cascade?Cascade is linked list (or three) of stages. Thats why: False alarm of cascade = false alarm of stage 1* false alarm of stage 2* Hit rate = hitrate of stage 1 * hitrate of stage 2* How many stag
25、es should be used? If you set big number of stages, then you will achieve better false alarm, but it will take more time for generating cascade. If you set big number of stages, then the detection time could be slower If you set big number of stages, then the worse hitrate will be (0.99*0.99* etc).
26、Commonly 14-25 stages are enough Its useless to set many stage, if you have small number of positive, negative samples Whats weighttrimming, eqw, bt, nonsym options?Really all these parameters are related to Adaboost, read theory. In short: nonsym If you positive samples are not X or Y symmetric, pu
27、t -nonsym, -sym is default! eqw if you have different number of pos and neg images, its better to put no eqw weighttrimming for calculation optimization. It can reduce calculation time a little, but quality may be worse bt what Adaboost algorithm to use: Real AB, Gentle AB, etc. Whats minpos, nsplit
28、s, maxtreesplits options?These parameters are related to clustering. In Adaboost different week classifier may be used: stump-based or tree-based. If you choose nsplits 0, tree-based will be used and you should set up minpos and maxtreesplits. nsplits minimun number of nodes in tree maxtreesplits ma
29、ximum number of nodes in tree. If maxtreesplits nsplits, tree will not be built minpos number of positive images, that can be used by one node during training. All positive images are splitted between nodes. Generally minpos should be not less than npos/nsplits. Errors and stranges during haartraini
30、ng! Error (valid only for Discrete and Real AdaBoost): misclass its warning, but no error. Some options are specific to D and R Adaboost. So your haartraining is ok. Screen is filled with such | 1000 |25%|-|-1423.312590| 1.000000| 1.000000| 0.876272| your training is cycled, restart it. First column
31、 should have value 100 cvAlloc fails. Our of memory you give too much negative images or sample.vec is too big. All these pictures are loaded to RAM. Pay attention you put the same -w and -h, as during vec file generation Pay attention, that number of positive samples and negative samples, you put in -npos -nneg are really available Avoid empty line in negative.dat file Required leaf false alarm rate achieved. Branch training terminated its impossible to build classifier with good false alarm on this negative images. Check your negative images are reall
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1