我想计算成对向量中相同点的出现次数。
这是我的代码:
vector<Point2f> points_1, points_2;
points_1.push_back(Point2f(1.0, 2.0));
points_1.push_back(Point2f(2.0, 2.0));
points_1.push_back(Point2f(3.0, 2.0));
points_1.push_back(Point2f(1.0, 2.0));
points_1.push_back(Point2f(2.0, 2.0));
points_1.push_back(Point2f(3.0, 2.0));
points_1.push_back(Point2f(1.0, 2.0));
points_2.push_back(Point2f(1.0, 1.0));
points_2.push_back(Point2f(1.0, 1.0));
points_2.push_back(Point2f(1.0, 2.0));
points_2.push_back(Point2f(1.0, 1.0));
points_2.push_back(Point2f(1.0, 1.0));
points_2.push_back(Point2f(1.0, 1.0));
points_2.push_back(Point2f(1.0, 1.0));
vector<pair<Point2f, Point2f>> point_pairs;
for (size_t i = 0; i < points_1.size(); i++) {
cout << points_1[i] << " " << points_2[i] << endl;
point_pairs.push_back(make_pair(points_1[i], points_2[i]));
}
结果应该是:
[1, 2] [1, 1] - 3 Occurrences
[2, 2] [1, 1] - 2 Occurrences
[3, 2] [1, 2] - 1 Occurrence
[3, 2] [1, 1] - 1 Occurrence
我知道你可以使用带有关键点(如直方图)的地图来跟踪事件,我尝试了以下方法:
map<pair<Point2f, Point2f>, int> pairToCount;