简体   繁体   中英

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 ..

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 :

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:

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

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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