Ask Your Question

# multiply two points and matrix

I want to multiply two points and matrix.I have trainPoints which is trained before the program.And I have testPoints which is occured while program is processing.And also I have homography which is Mat object (calculated with findHomography method).I want to check is it true?I want to calculate homography error.How can i multiply two points and homography?

edit retag close merge delete

## Comments

Your question is not clear enough. You should reformulate it. Can you write it in using mathematical conventions?

I have two points.Train points are (x,y) and test points are (x',y').I want to muliply xhomography and yhomography.For a result ,I want to get x' and y'.

## 2 answers

Sort by » oldest newest most voted

There are multiple functions to do it. If you have a list of points, perspectiveTransform()) is what you're looking for.

std::vector<cv::Point> inPts, outPts;
inpPts.push_back(cv::Point(3, 5));
perspectiveTransform(inPts, outPts, homography);

// now, you have the x', y' stored in outPts;


You may also want to convert an entire picture from one space to another - if you want to match pairs of points in two pictures, this is a common task.

So, given the currentPicture, and pictureReference, both declared as cv::Mat, you can

warpPerspective(currentPicture, pictureReference, homography);


Here you can find docs for warpPerspective)

more

## Comments

I use "perspectiveTransform(inPts, outPts, homography);" and it works well.Thank you.

Hey, please note that you can accept only one answer. You can use the upvote ^ button to show an answer is good. Clicking multiple times on the accept button on different answers triggers a nasty bug in the site Hi,

I am not sure if I understood your question but it seems that you are asking how two multiply several points by an homography (3x3 matrix) at the same time, right? For this, you only need to concatenate the points as column vectors in a Mat and then you can do something like that:

cv::Mat_<double> imp;
imp   = H*im_point;

for (int i = 0; i < im_point.cols; i++) {
// normalize the point
imp(0,i) = imp(0,i)/imp(2,i);
imp(1,i) = imp(1,i)/imp(2,i);
}

cv::Mat res;
res = imp(cv::Range(0,2), cv::Range::all());
return res;


Notice that the points im_point must be in homogeneous coordinates. I hope that this helps, if not, please be more specific in your question...

more

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2012-07-30 09:08:40 -0500

Seen: 3,848 times

Last updated: Jul 30 '12