我正在尝试用C++实现P. Viola和M. Jones的检测框架(一开始只是序列分类器-非级联版本)。我认为我设计了所有必需的类和模块(例如积分图像、Haar特征),除了一个最重要的算法:AdaBoost核心算法。
我读过P. Viola和M. Jones的原始论文以及许多其他出版物。不幸的是,我仍然不明白如何找到一个弱分类器的最佳阈值?我只找到了有关“加权中位数”和“高斯分布”算法的小参考和许多数学公式...
我尝试使用OpenCV Train Cascade模块源代码作为模板,但它非常全面,反向工程代码非常耗时。我还编写了自己简单的代码来理解自适应增强的思想。
问题是:您能否向我解释计算一个弱分类器的最佳阈值的最佳方法是什么?
下面我呈现了从Google找到的样本中重新编写的AdaBoost伪代码,但我并不确定这是否是正确的方法。计算一个弱分类器非常慢(几个小时),我对计算最佳阈值的方法有疑虑。
(1) AdaBoost::FindNewWeakClassifier
(2) AdaBoost::CalculateFeatures
(3) AdaBoost::FindBestThreshold
(4) AdaBoost::FindFeatureError
(5) AdaBoost::NormalizeWeights
(6) AdaBoost::FindLowestError
(7) AdaBoost::ClassifyExamples
(8) AdaBoost::UpdateWeights
DESCRIPTION (1)
-Generates all possible arrangement of features in detection window and put to the vector
DO IN LOOP
-Runs main calculating function (2)
END
DESCRIPTION(2)
-Normalizes weights (5)
DO FOR EACH HAAR FEATURE
-Puts sequentially next feature from list on all integral images
-Finds the best threshold for each feature (3)
-Finds the error for each the best feature in current iteration (4)
-Saves errors for each the best feature in current iteration in array
-Saves threshold for each the best feature in current iteration in array
-Saves the threshold sign for each the best feature in current iteration in array
END LOOP
-Finds for classifier index with the lowest error selected by above loop (6)
-Gets the value of error from the best feature
-Calculates the value of the best feature in the all integral images (7)
-Updates weights (8)
-Adds new, weak classifier to vector
DESCRIPTION (3)
-Calculates an error for each feature threshold on positives integral images - seperate for "+" and "-" sign (4)
-Returns threshold and sign of the feature with the lowest error
DESCRIPTION(4)
- Returns feature error for all samples, by calculating inequality f(x) * sign < sign * threshold
DESCRIPTION (5)
-Ensures that samples weights are probability distribution
DESCRIPTION (6)
-Finds the classifier with the lowest error
DESCRIPTION (7)
-Calculates a value of the best features at all integral images
-Counts false positives number and false negatives number
DESCRIPTION (8)
-Corrects weights, depending on classification results
感谢任何帮助。