ImageEn, unit ievision

TIEVisionCascadeClassifierTrainer.trainCascade

TIEVisionCascadeClassifierTrainer.trainCascade


Declaration

procedure trainCascade(cascadeDirName: PAnsiChar; vecName: PAnsiChar; bgImagesDir: PAnsiChar; numPos: int32_t = 1000; sampleWidth: int32_t = 24; sampleHeight: int32_t = 24; numStages: int32_t = 20; featureType: TIEVisionFeatureType = ievHAAR; continueTraining: bool32 = false; msgCallBack: TIEVisionTrainCascadeMsgCallBack = nil; precalcValBufSize: int32_t = 256; precalcIdxBufSize: int32_t = 256; baseFormatSave: bool32 = false; acceptanceRatioBreakValue: double = -1.0; boostType: TIEVisionHaarBoostType = ievGENTLE_ADABOOST; minHitRate: double = 0.995; maxFalseAlarmRate: double = 0.45; weightTrimRate: double = 0.95; maxDepth: int32_t = 1; maxWeakCount: int32_t = 120; haarFeatureSet: TIEVisionHaarMode = ievBASIC); safecall;


Description

Trains a cascade classifier given a positive samples file and a set of background (negative) images.
You can use classifier files to find content within images.



Parameter Description
cascadeDirName Path to a directory containing training temporary files and final result file 'cascade.xml'
vecName Input positive samples file
bgImagesDir Path to a directory containing background (negative) samples
numPos Number of positive samples. This should be up to 85% of positives contained in "vecName" file
sampleWidth Positive sample width (should have the same value of samples contained in "vecName")
sampleHeight Positive sample height (should have the same value of samples contained in "vecName")
numStages Number of cascade stages to be trained. If you set the same value of already trained stages (existing in cascadeDirName directory) and continueTraining is True then only the final "cascade.xml" file is generated
featureType Type of features: ievHAAR for Haar-like features, ievLBP for local binary patterns
continueTraining If False the content of cascadeDirName is removed, otherwise training continues using the already trained stages
msgCallBack Specifies a function to monitor training. This callback can be used also to stop a training, among stages
precalcValBufSize Size of buffer for precalculated feature values (in MB)
precalcIdxBufSize Size of buffer for precalculated feature indices (in MB)
acceptanceRatioBreakValue This argument is used to determine how precise your model should keep learning and when to stop. By default this value is set to -1 to disable this feature
boostType Type of boosted classifiers: ievDISCRETE_ADABOOST for Discrete AdaBoost, ievREAL_ADABOOST for Real AdaBoost, ievLOGITBOOST for LogitBoost, ievGENTLE_ADABOOST for Gentle AdaBoost (default)
minHitRate Minimal desired hit rate for each stage of the classifier (0.995)
maxFalseAlarmRate Maximal desired false alarm rate for each stage of the classifier (0.45)
weightTrimRate Specifies whether trimming should be used and its weight (0.95)
maxDepth Maximal depth of a weak tree (1)
maxWeakCount Maximal count of weak trees for every cascade stage (120)
haarFeatureSet Selects the type of Haar features set used in training. ievBASIC use only upright features, while ievALL uses the full set of upright and 45 degree rotated feature set


Demo

Demo  Demos\IEVision\TrainCascadeClassifier\TrainCascadeClassifier.dpr


Example

// create training samples file "samples.vec" from real positive samples stored in 'positive_images"
imagesCount = cascadeTrainer.createSamplesFromImageSet('positive_images', 'samples.vec', 40, 40);
// trainCascade images count must be less than 85% of the images in "vec" file
imagesCount := trunc(imagesCount * 0.85);
// train the cascade classifier with 10 stages using LBP. The output will be "trainingresult\cascade.xml", the you should use in TIEVisionObjectsFinder to find objects.
cascadeTrainer.trainCascade('trainingresult', 'samples.vec', 'negative_images', imagesCount, 40, 40, 10, ievLBP);