Skip to content
Snippets Groups Projects
Commit 5e861a2d authored by Jordi Inglada's avatar Jordi Inglada
Browse files

ENH: tidy up CvRTreesWrapper and add comments

parent 5f7e2735
Branches
Tags
No related merge requests found
......@@ -20,13 +20,29 @@
#include "otbOpenCVUtils.h"
#include <vector>
#include <algorithm>
namespace otb
{
/** \class CvRTreesWrapper
* \brief Wrapper for OpenCV Random Trees
*
* \ingroup OTBSupervised
*/
class CV_EXPORTS_W CvRTreesWrapper : public CvRTrees
{
public:
CvRTreesWrapper(){};
virtual ~CvRTreesWrapper(){};
/** Predict the confidence of the classifcation by computing the
difference in votes between the first and second most voted classes.
This measure is preferred to the proportion of votes of the majority
class, since it provides information about the conflict between the
most likely classes.
*/
float predict_confidence(const cv::Mat& sample,
const cv::Mat& missing =
cv::Mat()) const
......@@ -39,16 +55,15 @@ public:
CV_Assert( 0 <= class_idx && class_idx < nclasses );
++classVotes[class_idx];
}
// We only sort the 2 greatest elements
std::nth_element(classVotes.begin(), classVotes.begin()+1,
classVotes.end(), std::greater<>());
unsigned int maxVotes = classVotes[0];
unsigned int secondVotes = classVotes[1];
float confidence = static_cast<float>(maxVotes-secondVotes)/ntrees;
float confidence = static_cast<float>(classVotes[0]-classVotes[1])/ntrees;
return confidence;
};
};
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment