【发布时间】:2016-01-11 14:07:07
【问题描述】:
我正在寻找 std::set_intersection 函数的替代版本,但要用于 std::vector<cv::Point> 向量。
我尝试比较两个不同大小的std::vector<cv::Point> 向量。这两个包含坐标列表。类似交叉点的方法的主要任务现在应该是检测公共对并通过push_back() 将它们安全到第三个std::vector<cv::Point>
我搜索了类似std::set_intersection(v1.begin(),v1.end(),v2.begin(),v2.end(),back_inserter(v3));的函数
有什么办法解决这个问题吗?
【问题讨论】:
-
std::set_intersection正是这样做的,有什么问题?v1和v2必须排序。 -
我之前对向量进行了排序,但出现错误 C2893: failed to specialize function template 'unknown-type std::less
::operator()(_Ty1 &&,Ty2 && const' .(来自文件算法)。我使用的向量包含 x 和 y 坐标。 std::sort(v1.begin(), v1.end()); std::sort(v2.begin(), v2.end()); std::set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(v3)); -
@Flippy 对
std::sort使用自定义比较,即std::sort(v1.begin(), v2.end(), [](cv::Point lhs, cv::Point rhs){ return (lhs.x < rhs.x || (lhs.x == rhs.x && lhs.y <= rhs.y));} -
然后是
std::set_intersection的相同自定义比较器。