Search code examples
c++arraysopencvvectorpoint

How can I add cv::Point to array or vector in C++ / OpenCV?


I'm trying to add a cv::Point to an array or vector every iteration so I can use fitEllipse on the total data. I feel like there is a simple solution to this that I'm missing? I've tried declaring a double array but obviously I cannot convert from cv::Point to double. I'm new to using vectors and points so any help would be greatly appreciated. Thanks!


Solution

  • Try this out:

    cv::vector<cv::Point> pointList;
    

    Adding new point is easy:

    pointList.push_back(newPoint); // newPoint is your cv::Point object
    

    You can access to member elements in your list like this:

    for (int n = 0; n < pointList.size(); n++)
    {
        cv::Point myPoint = pointList[n];
    }