创建“从点设置”时出错
error in creation of Set from Points
我想要一组图像的所有像素坐标。不幸的是,我收到以下错误消息:
"错误 C2678:二进制'<':未找到采用类型为'const cv::P oint'的左操作数的运算符(或没有可接受的转换)"
Mat img;
img = imread( "[...]\picture.jpg", 1 );
set<Point> pointset;
for( int x = 0 ; x < img.cols ; x++)
{
for (int y = 0 ; y < img.rows ; y++)
{
pointset.insert(Point(x,y));
}
}
我怀疑进入集合的每个类型都必须提供用于比较的函数,而 cv::P oint 无法做到这一点。不幸的是,我是C++和OpenCV的新手,不知道如何检查我的怀疑是否属实。
长话短说:如果你想使用一组点,你需要为点提供一个比较操作:
struct comparePoints {
bool operator()(const Point & a, const Point & b) {
return ( a.x<b.x && a.y<b.y );
}
};
int main()
{
Mat img = imread( "clusters.png", 1 );
set<Point,comparePoints> pointset;
for( int x = 0 ; x < img.cols ; x++)
{
for (int y = 0 ; y < img.rows ; y++)
{
pointset.insert(Point(x,y));
}
}
return 0;
}
在 otther 手上,您只需要一组,如果有重复的点需要避免。 这里不是这样。
因此,使用向量可能更容易:
int main()
{
Mat img = imread( "clusters.png", 1 );
vector<Point> points;
for( int x = 0 ; x < img.cols ; x++)
{
for (int y = 0 ; y < img.rows ; y++)
{
points.push_back(Point(x,y));
}
}
return 0;
}
相关文章:
- 从 Swift 设置C++指针
- 从 QFontDatabase 设置 QFont 将所有标签设置为等宽字体?Qt C++
- 难以从 CImageList 设置菜单项位图
- 编译时出错 - 从 DWORD 到 LPCVOID 的转换
- 请求从"点*"转换为非标量类型"点"
- C++如何将字符串数组中的一个点设置为枚举变量
- 如何使用CMake在Windows上将应用程序入口点设置为main()C++?
- 无法从JNI设置Java Int数组字段
- QWidget - 从C++代码设置边框
- qlineedit DoubleValidator从点开始
- 如何从 QString 设置Q_ENUM
- 有没有办法从点云和深度数据构建和存储3D地图
- 从编译器设置中关闭 RTTI 有什么好处?
- 线性代数转换矩阵 - 通过乘以矩阵从点到不同点
- 创建“从点设置”时出错
- 如何从点赞列表中创建一个复制构造函数
- 从点云中的质心绘制一个矢量
- 从点云中检测一组平面
- C++从点识别形状
- 从点云库运行hdl_sample_viewer.cpp的可执行文件