cv::Mat OpenCvDetector::calculateFeatureMatrix(const Segments& segments) { cv::Mat featureMatrix(segments.size(), m_featureDimensions.size(), CV_32FC1); for(size_t i = 0; i < segments.size(); i++) { const Segment& segment = segments[i]; std::map<FeatureDimension, float> featureValueLookup; // one entry per dimension per feature for(size_t j = 0; j < m_features.size(); j++) { Feature::Ptr feature = m_features[j]; Eigen::VectorXd values; feature->evaluate(segment, values); // Each feature can have multiple dimensions, store these in a map so we can look up // the requested dimensions in the next step for(size_t dim = 0; dim < feature->getNDimensions(); dim++) { featureValueLookup[ feature->getDescription(dim) ] = values(dim); } } // Look up the requested dimensions for(size_t k = 0; k < m_featureDimensions.size(); k++) { const FeatureDimension& featureDescription = m_featureDimensions[k]; featureMatrix.at<float>(i, k) = featureValueLookup[featureDescription]; } } return featureMatrix; }
void OpenCvDetector::detect(const Segments& segments, Labels& labels, Confidences& confidences) { cv::Mat featureMatrix = calculateFeatureMatrix(segments); for(size_t i = 0; i < segments.size(); i++) { // Implemented by the derived class. classifyFeatureVector(featureMatrix.row(i), labels[i], confidences[i]); } }