I am using opencv library with C++, and I am trying to compute sum of points which are contained in vector<Point2f> difference
Point class has x property which is float.
float pointSumX(Point2f pt1,Point2f pt2)
{
return (pt1.x + pt2.x);
}
I defined function as above, and call it from accumulate shown below. But it throws error.
float avgMotionX = accumulate(difference.begin(),difference.end(),0,pointSumX);
Error is:
error: could not convert ‘__init’ from ‘int’ to ‘cv::Point_’ __init = __binary_op(__init, *__first);
Note: I am using C++11
float pointSumX(Point2f pt1, Point2f pt2)
should be
float pointSumX(float lhs, const Point2f& rhs)
{
return lhs + rhs.x;
}
as lhs is the accumulator.
Note also that you should call it
std::accumulate(difference.begin(), difference.end(), 0.f, pointSumX); // 0.f instead of 0
to return float and not int.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With