简体   繁体   English

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

[英]How To Use Vector Points in C++ OpenCv?

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 .. 对于Ex:我需要创建一个向量并在Vector中转储这些x,y值。

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

A vector of point in OpenCV is just a standard C++ STL vector containing OpenCV Point objects : 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++11 or 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 ++参考

So... you want to use a vector to store data... wherein each element is a pair of int s? 所以......你想用一个向量来存储数据......其中每个元素都是一对int Well, if you don't want to create your own type, use a tuple or pair: 好吧,如果您不想创建自己的类型,请使用元组或对:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM