如何在 C++ OpenCv 中使用向量点?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15965674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How To Use Vector Points in C++ OpenCv?
提问by Pixel
Could you guys Please help me in providing good notes or links ?
你们能帮我提供好的笔记或链接吗?
For Ex : I need to create a vector and dump these x,y values in Vector ..
例如:我需要创建一个向量并将这些 x,y 值转储到 Vector ..
Data { X , Y } = {1,1} , {1,2} , {1,3}, {2,1},{2,2},{2,3},{3,1},{3,2},{3,3}
回答by zakinster
A vector of point in OpenCV is just a standard C++ STLvector containing OpenCV Pointobjects :
OpenCV 中的点向量只是包含OpenCV Point对象的标准C++ STL向量:
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));
...
Alternatively, if you're using C++11or later you can use a list initialization:
或者,如果您使用C++11或更高版本,则可以使用列表初始化:
std::vector<Point> data = {Point(1,1), Point(1,2), Point(1,3), Point(2,1)};
Take a look at the C++ reference for STL Vector
看一看STL Vector的C++ 参考
回答by Ed S.
So... you want to use a vector to store data... wherein each element is a pair of int
s? Well, if you don't want to create your own type, use a tuple or pair:
所以......你想使用一个向量来存储数据......其中每个元素都是一对int
s?好吧,如果您不想创建自己的类型,请使用元组或对:
#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;