double cv_emd_distance(const std::vector<double>& h1, const std::vector<double>& h2, int histogram_cycle) { int n = h1.size(); #if 0 ntk_dbg_print(h1.size(), 1); ntk_dbg_print(h2.size(), 1); double norm1 = std::accumulate(stl_bounds(h1), 0.0); double norm2 = std::accumulate(stl_bounds(h2), 0.0); ntk_dbg_print(norm1, 1); ntk_dbg_print(norm2, 1); #endif CvMat* sig1 = cvCreateMat(n, 3, CV_32FC1); CvMat* sig2 = cvCreateMat(n, 3, CV_32FC1); foreach_idx(i, h1) { int row = i/histogram_cycle; int col = i%histogram_cycle; cvSet2D(sig1, i, 0, cvScalar(h1[i])); cvSet2D(sig1, i, 1, cvScalar(row)); cvSet2D(sig1, i, 2, cvScalar(col)); cvSet2D(sig2, i, 0, cvScalar(h2[i])); cvSet2D(sig2, i, 1, cvScalar(row)); cvSet2D(sig2, i, 2, cvScalar(col)); }
std::vector<cv::Point2f> make_unimodal_distribution(const std::vector<cv::Point2f>& points) { double max_value = -FLT_MAX; foreach_idx(i, points) if (points[i].y > max_value) max_value = points[i].y; std::vector<cv::Point2f> control_points; double current_max = -FLT_MAX; int i = points.size()-1; for (i = points.size()-1; i > 0 && points[i].y < max_value; --i) { if (points[i].y > current_max) { current_max = points[i].y; control_points.insert(control_points.begin(), points[i]); } } int last_index = i; control_points.insert(control_points.begin(), points[i]); std::vector<cv::Point2f> control_points_fwd; current_max = -FLT_MAX; for (i = 0; i < last_index; ++i) { if (points[i].y > current_max) { current_max = points[i].y; control_points_fwd.push_back(points[i]); } } control_points_fwd.insert(control_points_fwd.end(), stl_bounds(control_points)); return control_points_fwd; }
std::vector<double> distrib_to_bimodal_linear(const std::vector<double>& factors) { double max_value = -FLT_MAX; foreach_idx(i, factors) if (factors[i] > max_value) max_value = factors[i]; std::vector<cv::Point2f> control_points; double current_max = -FLT_MAX; int i = factors.size()-1; for (i = factors.size()-1; i > 0 && factors[i] < max_value; --i) { if (factors[i] > current_max) { current_max = factors[i]; control_points.insert(control_points.begin(), cv::Point2f(i, factors[i])); } } int last_index = i; control_points.insert(control_points.begin(), cv::Point2f(i, factors[i])); std::vector<cv::Point2f> control_points_fwd; current_max = -FLT_MAX; for (i = 0; i < last_index; ++i) { if (factors[i] > current_max) { current_max = factors[i]; control_points_fwd.push_back(cv::Point2f(i, factors[i])); } } control_points_fwd.insert(control_points_fwd.end(), stl_bounds(control_points)); return fill_linear_values_from_control_points(control_points_fwd); }
void SiftObjectDetector :: initializeFindObjects() { super::initializeFindObjects(); m_point_matches.clear(); m_image_sift_points.clear(); std::list<LocatedFeature*> points; ntk::TimeCount tc_init("initialize", 1); compute_feature_points(points, m_data.image, siftDatabase().featureType()); tc_init.elapsedMsecs(" compute feature points: "); std::copy(stl_bounds(points), std::back_inserter(m_image_sift_points)); ntk_dbg_print(m_image_sift_points.size(), 1); tc_init.stop(); }