C++学习笔记之——map set 与 opencv中的数据结构 如 point 等不兼容

今天写程序的时候需要去掉重复的坐标点 所以很自然的想到用 set 容器
但是一直编译的时候报错 所以写了如下的小程序来 测试 map 和 set 和opencv数据结构的兼容性

#include "stdafx.h"
#include <opencv2/core/core.hpp>  
#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/imgproc/imgproc.hpp>  
#include <opencv2/opencv.hpp>
#include <vector>
#include <set>
#include <iostream>

using namespace std;
using namespace cv;

int _tmain(int argc, _TCHAR* argv[])
{
    Point2i n;
    n.x=1;
    n.y=1;
    set<Point2i> m;
    map<Point2i,int> m_2;
    m.insert(n);
    //m_2.insert(make_pair(n,1));
    return 0;
}

首先是使用set容器的结果

1>------ 已启动生成: 项目: set point 兼容性测试, 配置: Debug Win32 ------
1>  set point 兼容性测试.cpp
1>f:\新建文件夹\vc\include\xstddef(180): error C2678: 二进制“<”: 没有找到接受“const cv::Point2i”类型的左操作数的运算符(或没有可接受的转换)
1>          d:\opencv 2.4.9\opencv\build\include\opencv2\core\operations.hpp(3190): 可能是“bool cv::operator <(const cv::FileNodeIterator &,const cv::FileNodeIterator &)”[通过使用参数相关的查找找到]
1>          d:\opencv 2.4.9\opencv\build\include\opencv2\core\mat.hpp(1300): 或       “cv::MatExpr cv::operator <(const cv::Mat &,const cv::Mat &)”[使用参数相关的查找找到]
1>          d:\opencv 2.4.9\opencv\build\include\opencv2\core\mat.hpp(1301): 或       “cv::MatExpr cv::operator <(const cv::Mat &,double)”[使用参数相关的查找找到]
1>          d:\opencv 2.4.9\opencv\build\include\opencv2\core\mat.hpp(1302): 或       “cv::MatExpr cv::operator <(double,const cv::Mat &)”[使用参数相关的查找找到]
1>          d:\opencv 2.4.9\opencv\build\include\opencv2\core\mat.hpp(1981): 或       “bool cv::operator <(const cv::MatConstIterator &,const cv::MatConstIterator &)”[使用参数相关的查找找到]
1>          尝试匹配参数列表“(const cv::Point2i, const cv::Point2i)”时
1>          f:\新建文件夹\vc\include\xstddef(179): 编译类 模板 成员函数“bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const”时
1>          with
1>          [
1>              _Ty=cv::Point2i
1>          ]
1>          f:\新建文件夹\vc\include\xutility(559): 参见对正在编译的函数 模板 实例化“bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const”的引用
1>          with
1>          [
1>              _Ty=cv::Point2i
1>          ]
1>          f:\新建文件夹\vc\include\type_traits(743): 参见对正在编译的类 模板 实例化“std::less<_Ty>”的引用
1>          with
1>          [
1>              _Ty=cv::Point2i
1>          ]
1>          f:\新建文件夹\vc\include\xtree(1028): 参见对正在编译的类 模板 实例化“std::is_empty<_Ty>”的引用
1>          with
1>          [
1>              _Ty=std::less<cv::Point2i>
1>          ]
1>          f:\新建文件夹\vc\include\set(44): 参见对正在编译的类 模板 实例化“std::_Tree<_Traits>”的引用
1>          with
1>          [
1>              _Traits=std::_Tset_traits<cv::Point2i,std::less<cv::Point2i>,std::allocator<cv::Point>,false>
1>          ]
1>          f:\visual studio 2012\projects\set point 兼容性测试\set point 兼容性测试\set point 兼容性测试.cpp(21): 参见对正在编译的类 模板 实例化“std::set<_Kty>”的引用
1>          with
1>          [
1>              _Kty=cv::Point2i
1>          ]
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

其次是使用map容器的结果

1>------ 已启动生成: 项目: set point 兼容性测试, 配置: Debug Win32 ------
1>  set point 兼容性测试.cpp
1>f:\新建文件夹\vc\include\xstddef(180): error C2678: 二进制“<”: 没有找到接受“const cv::Point2i”类型的左操作数的运算符(或没有可接受的转换)
1>          d:\opencv 2.4.9\opencv\build\include\opencv2\core\operations.hpp(3190): 可能是“bool cv::operator <(const cv::FileNodeIterator &,const cv::FileNodeIterator &)”[通过使用参数相关的查找找到]
1>          d:\opencv 2.4.9\opencv\build\include\opencv2\core\mat.hpp(1300): 或       “cv::MatExpr cv::operator <(const cv::Mat &,const cv::Mat &)”[使用参数相关的查找找到]
1>          d:\opencv 2.4.9\opencv\build\include\opencv2\core\mat.hpp(1301): 或       “cv::MatExpr cv::operator <(const cv::Mat &,double)”[使用参数相关的查找找到]
1>          d:\opencv 2.4.9\opencv\build\include\opencv2\core\mat.hpp(1302): 或       “cv::MatExpr cv::operator <(double,const cv::Mat &)”[使用参数相关的查找找到]
1>          d:\opencv 2.4.9\opencv\build\include\opencv2\core\mat.hpp(1981): 或       “bool cv::operator <(const cv::MatConstIterator &,const cv::MatConstIterator &)”[使用参数相关的查找找到]
1>          尝试匹配参数列表“(const cv::Point2i, const cv::Point2i)”时
1>          f:\新建文件夹\vc\include\xstddef(179): 编译类 模板 成员函数“bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const”时
1>          with
1>          [
1>              _Ty=cv::Point2i
1>          ]
1>          f:\新建文件夹\vc\include\xutility(559): 参见对正在编译的函数 模板 实例化“bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const”的引用
1>          with
1>          [
1>              _Ty=cv::Point2i
1>          ]
1>          f:\新建文件夹\vc\include\type_traits(743): 参见对正在编译的类 模板 实例化“std::less<_Ty>”的引用
1>          with
1>          [
1>              _Ty=cv::Point2i
1>          ]
1>          f:\新建文件夹\vc\include\xtree(1028): 参见对正在编译的类 模板 实例化“std::is_empty<_Ty>”的引用
1>          with
1>          [
1>              _Ty=std::less<cv::Point2i>
1>          ]
1>          f:\新建文件夹\vc\include\set(44): 参见对正在编译的类 模板 实例化“std::_Tree<_Traits>”的引用
1>          with
1>          [
1>              _Traits=std::_Tset_traits<cv::Point2i,std::less<cv::Point2i>,std::allocator<cv::Point>,false>
1>          ]
1>          f:\visual studio 2012\projects\set point 兼容性测试\set point 兼容性测试\set point 兼容性测试.cpp(21): 参见对正在编译的类 模板 实例化“std::set<_Kty>”的引用
1>          with
1>          [
1>              _Kty=cv::Point2i
1>          ]
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

都是编译错误,所以目测这个数据结构应该是不可行的,欢迎遇到相同问题的小伙伴在评论区交流
博主最近在做深度学习方向 所以更新较慢 不过不能放松自己对学习语言的要求

猜你喜欢

转载自blog.csdn.net/laoma023012/article/details/52294085