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