Engine
Engine

Reputation: 5422

Multiplying a a vector of cv::Points2f with a cv::Matx33f

I have a function that works fine :

cv::Point2f classA::DoStuff(cv::Point2f pTmp){
    cv::Matx33f newMatrix = oldMatrix ; // oldMatrix  is already defined 
    cv::Point3f  newPoint = newMatrix *pTmp;
    cv::Point2f result(newPoint.x, newPoint.y);
    return result;
}

well now I want to run this function on a set of points a vector I know I can do this with a for loop, but from this answer , multiplying a vector with a scalar :

std::transform(myv1.begin(), myv1.end(), myv1.begin(),
               std::bind1st(std::multiplies<T>(),3));

Multiply vector elements by a scalar value using STL

I guess it is possible to do it in one line any idea how to do this with my function like :

std::vector<cv::Point2f> classA::Dostuff(std::vector<cv::Point2f> inputVector){
    cv::Matx33f newMatrix = oldMatrix ; // oldMatrix  is already defined 

..!!! 

thanks in advance ?

}

Upvotes: 0

Views: 270

Answers (1)

juanchopanza
juanchopanza

Reputation: 227418

Assuming you want to run this from inside an instance of classA, it would be something like this:

using namespace std::placeholders;
std::transform(vec.begin(), 
               vec.end(), 
               vec.begin(), 
               std::bind(&classA::DoStuff, this, _1));

where vec is an std::vector<std::vector<cv::Point2f>>. Note you might be making unnecessary and potentially costly copies of the input vector. Unless you need a copy in the function, you may be better off passing a const reference:

std::vector<cv::Point2f> classA::Dostuff(const std::vector<cv::Point2f>& inputVector);

Upvotes: 2

Related Questions