Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I guess you're looking for

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

where his your (inverted) homography matrix.

I guess you're looking for

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

where h is your (inverted) homography matrix.

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()
{
    // source quadrangle
    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));

    // transformed quadrangle
    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);
}