Pixel
Pixel

Reputation: 439

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}

Upvotes: 5

Views: 37221

Answers (2)

zakinster
zakinster

Reputation: 10688

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

Upvotes: 16

Ed Swangren
Ed Swangren

Reputation: 124632

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:

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

Upvotes: 4

Related Questions