gpt4 book ai didi

c++ - opencv以Point为键创建 map

转载 作者:行者123 更新时间:2023-12-02 10:04:16 26 4
gpt4 key购买 nike

我正在尝试插入键为cv::Point,值为bool的 map 中。我这样做如下:

Mat& pts = ...
std::map<cv::Point, bool>& myMap;
myMap.insert({pts.at<Point>(5), true});

但是越来越 invalid operands to binary expression ('const cv::Point_<int>' and 'const cv::Point_<int>'){return __x < __y;}

请注意,我已定义以下内容进行比较:
 bool operator<(cv::Point const& a, cv::Point const& b)
{
return (a.x < b.x) || (a.x == b.x && a.y < b.y);
}

我不确定自己在做什么错。即使我注释掉 myMap.insert({pts.at<Point>(5), true});我有问题。

最佳答案

像这样声明您的比较器,而不是operator<函数:

struct ComparePoints
{
bool operator () (const cv::Point& a, const cv::Point& b) const
{
return (a.x < b.x) || (a.x == b.x && a.y < b.y);
}
};

和你的 map 是这样的:
std::map <cv::Point, bool, ComparePoints> myMap;

然后一切正常。

关于c++ - opencv以Point为键创建 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61002679/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com