void Fern::train(const cv::Mat &frame, const cv::Rect &patchRect, const bool isPositive) { int leaf = getLeafIndex(frame, patchRect); if (isPositive == true) { leafs[leaf].increment(); } else { leafs[leaf].decrement(); } }
void Fern::train(IntegralImage *image, int patchX, int patchY, int patchW, int patchH, int patchClass) { // Apply all tests to find the leaf index this patch falls into int leaf = getLeafIndex(image, patchX, patchY, patchW, patchH); // Increment the number of positive or negative patches that fell into // this leaf if (patchClass == 0) { n[leaf]++; } else { p[leaf]++; } // Compute the posterior likelihood of a positive class for this leaf if (p[leaf] > 0) { posteriors[leaf] = (float)p[leaf] / (float)(p[leaf] + n[leaf]); } }
// Classify a given patch double Fern::classify( cv::Mat const & image, cv::Point & patchPt, cv::Point & patchDims) { return m_posteriors[getLeafIndex(image,patchPt,patchDims)]; }
double Fern::classify(const cv::Mat &frame, const cv::Rect &patchRect) const { return leafs.at(getLeafIndex(frame, patchRect)).load(); }
float Fern::classify(IntegralImage *image, int patchX, int patchY, int patchW, int patchH) { // Return the precomputed posterior likelihood of a positive class for // this leaf return posteriors[getLeafIndex(image, patchX, patchY, patchW, patchH)]; }