# homography for cordinates of poins

This post is a wiki. Anyone with karma >50 is welcome to improve it.

is it possible to apply a homography to the coordinates of a point?

for example in his code:

double X;
double Y;
std::vector<KeyPoint> key_filtered;
for( int i=0; i<(int)keypoints.size(); i++)
{
double x = keypoints[i].pt.x, y = keypoints[i].pt.y;

if((X >= corner[0].x && X <= corner[1].x) && (Y >= corner[0].y && Y <= corner[2].y)){
key_filtered[j]=keypoints[i];
j++;
}
}


i want apply the homography "inv" to "x" and "y"....

edit retag close merge delete

Sort by ยป oldest newest most voted

This post is a wiki. Anyone with karma >50 is welcome to improve it.

I guess you're looking for

void perspectiveTransform(vector<Point> origPoints, vector<Point> transformedPoints, Mat h)


where h is your (inverted) homography matrix.

Here's a little code example on how to use it:

void perspectiveTransformTest()
{
vector<Point2f> src;
src.push_back(Point(0,0));
src.push_back(Point(2,0));
src.push_back(Point(2,2));
src.push_back(Point(0,2));

vector<Point2f> dst;
dst.push_back(Point(1,0));
dst.push_back(Point(2,1));
dst.push_back(Point(1,2));
dst.push_back(Point(0,1));

// compute transformation matrix
Mat H = getPerspectiveTransform(src, dst);

// apply transformation matrix to source quadrangle
vector<Point2f> dst2;
perspectiveTransform(src, dst2, H);

// display results
for (int i=0; i<4; ++i)
{
cout << "dst: p" << i << "(" << dst[i].x << "," << dst[i].y << ")\t dst2: p" << i << "(" << dst2[i].x << "," << dst2[i].y << ")" << endl;
}
}


and that's the output:

dst: p0(1,0)     dst2: p0(1,3.33067e-016)
dst: p1(2,1)     dst2: p1(2,1)
dst: p2(1,2)     dst2: p2(1,2)
dst: p3(0,1)     dst2: p3(1.11022e-016,1)


Note: perspectiveTransform() doesn't accept KeyPoints. Use The Points stored in KeyPoint instead:

vector<KeyPoint> keypoints;
// ....
vector<Point2f> points;
for(vector<KeyPoint>::iterator it=keypoints.begin(); it!=keypoints.end(); ++it)
{
points.push_back(it->pt);
}

more

i write: perspectiveTransform(keypoints[i],temp,inv)

but he give me an error : invalid initialization of reference of type 'const cv::_InputArray&' from expression of type 'cv::KeyPoint'

( 2012-08-30 03:48:19 -0500 )edit
1

also you can use Keypoint::convert for your last piece of code

( 2012-08-30 11:10:55 -0500 )edit

I have similar question but for Affine matrix retrieved from estimateRigidTransform. How can i transform one std::vector<cv::Point2f> to another? I mean the same action but for smaller dim matrix (affine)?

( 2014-01-02 09:15:01 -0500 )edit

Official site

GitHub

Wiki

Documentation