计算 cv::P oints2f 向量中的重复项
Counting duplicates in a vector of cv::Points2f
Im 试图在向量中查找和计数重复的 cv::P oints2f。为此,我尝试使用以下函数。但是当我尝试使用取消引用的值时出现错误rv[*val]++
.
std::map<cv::Point2f, unsigned int> counter(const std::vector<Point2f>& vals)
{
std::map<Point2f, unsigned int> rv;
for (auto val = vals.begin(); val != vals.end(); ++val) {
rv[*val]++;
}
return rv;
}
最后,我想使用一个包含键列表(没有重复键(的容器,以及在原始向量中发现每个键的次数。
例如,对于以下向量
vector<Point2f> v{Point2f(2,2),Point2f(3,3),Point2f(1,2),Point2f(2,2),Point2f(3,3)};
我想获取一个包含此信息的容器: (1,2) 1; (2,2) 2; (3,3( 2
编辑:
只是为了澄清,我得到了不同的注释和错误,如:
/usr/include/c++/5/bits/stl_function.h:387:20: error: no match for ‘operator<’ (operand types are ‘const cv::Point_<float>’ and ‘const cv::Point_<float>’)
{ return __x < __y; }
/usr/local/include/opencv2/core/cvstd.hpp:1031:20: note: no known conversion for argument 1 from ‘const cv::Point_<float>’ to ‘const cv::String&’
提前非常感谢!
显然,您缺少 Point 类的比较运算符,因此您需要提供它,例如:
bool operator <(const cv::Point2f &a, const cv::Point2f &b)
{
if (a.x < b.x) return true;
if (a.x > b.x) return false;
return a.y < b.y;
}
第二个注意事项是说有一个运算符
如果你想在std::map
的情况下使用特定类型作为键(在这种情况下Point2f
(,那么你必须为你的类型定义operator<
,因为地图使用operator<
对它的元素进行排序,否则它怎么知道哪个元素比另一个小?
相关文章:
- 将CHW格式的浮点向量转换为cv::Mat
- 计算 cv::P oints2f 向量中的重复项
- 如何在打开的 cv 中使用向量将一些浮点值存储在 for 循环中
- 将std ::向量复制到CV :: Mat_的行操作相同
- 一般情况下,在 cv::Mat 或 cv::Mat 的向量上进行 omp 还原
- 如何有效地传递 std::vector<cv::P oint3f> 的子向量作为参数(不拥有函数)
- C++ cv::Mat 返回向量的<rectangle>线程异步
- 将CV :: MAT的向量写入C 的二进制文件
- 为什么CV :: MAT的向量总是返回第一个图像
- 将 cv::Mat 向量复制到浮点数向量的最佳方法是什么?
- 如何在opencv中创建cv::matrix的向量,并将图像数据的子矩阵分配给向量的所有索引上的矩阵
- 为什么将 cv::Mat 的列复制到向量中会失败
- 将两个 std::vector<cv::P oint> 向量和安全公共点与第三个 std::vector<cv::P oint 进行比较>
- 是否有任何函数可以对 std::vector< cv::P oint2f> 向量进行排序
- 将cv::Points2f的向量与cv::Matx33f相乘
- std::vector不会为多个向量条目创建cv::Mat的新引用——初始化矩阵时,数据会被覆盖
- 如何在向量中找到相同的cv::Mat<简历::Mat>
- 复制图像数据到向量cv::mat
- 我如何添加cv::指向数组或向量在c++ / OpenCV
- OpenCV 向量<point> - 没有用于初始化'cv::Point_<int>'的匹配承包商