3

How do I access the vector value

std :: vector <cv :: Point2f> pto

into a separate vector x and y

std :: vector <float> x;

already tried several ways:

x (i) = pto.at <cv :: float> (i) .pt.x

but did not work

Micka
  • 19,585
  • 4
  • 56
  • 74
Marcos Basso
  • 31
  • 1
  • 2
  • Please edit your post to give us more context about the problem. Most people wouldn't have known this was about OpenCV unless they looked at the tags. – eigenchris Mar 06 '15 at 04:25

2 Answers2

1

When I needed to extract X and Y values separately from an array like your own, I did it like this:

std::vector<cv::Point2f> corners;
//stuff

cornersSize = corners.size();
for(int k=0; k<cornersSize; k++){          //goes through all cv::Point2f in the vector
                float x = corners[k].x;   //first value
                float y = corners[k].y;   //second value
                //stuff
}

The docs had everything - http://docs.opencv.org/modules/core/doc/basic_structures.html

Petersaber
  • 851
  • 1
  • 12
  • 29
0

You access the values in an std::vector with either at or operator[]:

std :: vector <float> x (n); // Initializes `x` to hold `n` values.
x.at (i) = pto.at (i) .x;

This will assign the x component of the Point2f at index i in pto to index i in the x vector.

Emil Laine
  • 41,598
  • 9
  • 101
  • 157