如何在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:56:05  来源:igfitidea点击:

How To Use Vector Points in C++ OpenCv?

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 VectorC++ 参考

回答by Ed S.

So... you want to use a vector to store data... wherein each element is a pair of ints? Well, if you don't want to create your own type, use a tuple or pair:

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

#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;