Calculate mean for vector of points

后端 未结 4 2132
甜味超标
甜味超标 2021-02-09 00:16

I have a vector of a 2-dimensional points in OpenCV

std::vector points;

I would like to calculate the mean values for x and

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-09 00:37

    You can use stl's std::accumulate as follows:

    cv::Point2f sum = std::accumulate(
        points.begin(), points.end(), // Run from begin to end
        cv::Point2f(0.0f,0.0f),       // Initialize with a zero point
        std::plus()      // Use addition for each point (default)
    );
    cv::Point2f mean = sum / points.size(); // Divide by count to get mean
    

提交回复
热议问题