我正在尝试在 C++ 中实现 P. Viola 和 M. Jones 检测框架(一开始,只是序列分类器 - 不是级联版本)。我想我已经设计了所有必需的类和模块(例如积分图像、Haar 特征),尽管有一个——最重要的是:AdaBoost 核心算法。
我已经阅读了 P. Viola 和 M. Jones 的原始论文以及许多其他出版物。不幸的是,我仍然不明白如何为一个弱分类器找到最佳阈值?我只发现了对“加权中位数”和“高斯分布”算法以及许多数学公式的少量参考......
我曾尝试使用 OpenCV Train Cascade 模块源作为模板,但它是如此全面,以至于对代码进行逆向工程非常耗时。我还编写了自己的简单代码来理解 Adaptive Boosting 的概念。
问题是:你能解释一下计算一个弱分类器的最佳阈值的最佳方法吗?
下面我将展示 AdaBoost 伪代码,它是根据 Google 中的示例重写的,但我不相信它是否正确。一个弱分类器的计算非常慢(几个小时),我特别怀疑计算最佳阈值的方法。
(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
感谢您的任何帮助