diff --git a/openbr/plugins/classification/boostedforest.cpp b/openbr/plugins/classification/boostedforest.cpp index 3cf941e..4d97f35 100644 --- a/openbr/plugins/classification/boostedforest.cpp +++ b/openbr/plugins/classification/boostedforest.cpp @@ -149,10 +149,8 @@ private: } } - float classify(const Template &src, bool process, float *confidence) const + float classifyPreprocessed(const Template &t, float *confidence) const { - Template t = process ? preprocess(src) : src; - float sum = 0; for (int i = 0; i < classifiers.size(); i++) { Node *node = classifiers[i]; @@ -175,6 +173,12 @@ private: return sum < threshold - THRESHOLD_EPS ? 0.0f : 1.0f; } + float classify(const Template &src, bool process, float *confidence) const + { + // This code is written in a way to avoid an unnecessary copy construction and destruction of `src` when `process` is false. + return process ? classifyPreprocessed(preprocess(src), confidence) : classifyPreprocessed(src, confidence); + } + int numFeatures() const { return representation->numFeatures();