如何在C ++ OpenCv中使用向量点?

时间:2013-04-12 07:38:30

标签: c++ opencv

你们能帮我提供好的笔记或链接吗?

对于Ex:我需要创建一个向量并将这些x,y值转储到Vector ..

Data { X , Y } = {1,1} , {1,2} , {1,3}, {2,1},{2,2},{2,3},{3,1},{3,2},{3,3}

2 个答案:

答案 0 :(得分:10)

OpenCV中的点向量只是包含C++ STL个对象的标准OpenCV Point向量:

std::vector<Point> data;
data.push_back(Point(1,1));
data.push_back(Point(1,2));
data.push_back(Point(1,3));
data.push_back(Point(2,1));
...

或者,如果您使用C++11或更高版本,则可以使用列表初始化:

std::vector<Point> data = {Point(1,1), Point(1,2), Point(1,3), Point(2,1)};

查看C++ reference for STL Vector

答案 1 :(得分:3)

所以......你想用一个向量来存储数据......其中每个元素都是一对int个?好吧,如果您不想创建自己的类型,请使用元组或对:

#include <vector>
#include <utility>

// ...

std::vector<std::pair<int, int> v;
// ...
v.push_back(std::make_pair(1, 1));
// ...
auto p = c[offset];
int x = p.first;
int y = p.second;