Ask Your Question

multiply two points and matrix

asked 2012-07-30 09:08:40 -0600

basarkir gravatar image

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 flag offensive close merge delete


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

sammy gravatar imagesammy ( 2012-07-30 09:15:43 -0600 )edit

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'.

basarkir gravatar imagebasarkir ( 2012-07-30 09:17:55 -0600 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2012-07-30 09:30:42 -0600

sammy gravatar image

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[0];

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)

edit flag offensive delete link more


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

basarkir gravatar imagebasarkir ( 2012-07-31 05:46:04 -0600 )edit

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

sammy gravatar imagesammy ( 2012-07-31 06:47:45 -0600 )edit

answered 2012-07-30 09:27:53 -0600

gfuhr gravatar image


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...

edit flag offensive delete link more

Question Tools


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

Seen: 4,908 times

Last updated: Jul 30 '12