Rahul K Singh Rahul K Singh - 1 month ago 12
C++ Question

how to use vector<Point2f> in c++

I want to use this code(source) to find fundamental matrix in opencv.

int point_count = 100;
vector<Point2f> points1(point_count);
vector<Point2f> points2(point_count);

// initialize the points here ... */
for( int i = 0; i < point_count; i++ )
{
points1[i] = ...;
points2[i] = ...;
}

Mat fundamental_matrix =
findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99);


but I don't know how to initialise points1, points2 in for loop.
I have tried using:

points1[i] = 10.0;
points1[i] = (10.0, 20.0);
points1[i] = {10.0, 20.0};


but getting error like this

no match for ‘operator=’ (operand types are ‘cv::Point_<float>’ and ‘double’)


in all of them.

Answer

They should be initialized like the following:

points[i] = Point2f(0.3f, 0.f);

Check OpenCV documentation.