Ask Your Question
2

homography for cordinates of poins

asked 2012-08-28 10:04:42 -0600

this post is marked as community wiki

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

1 answer

Sort by ยป oldest newest most voted
7

answered 2012-08-28 10:38:12 -0600

this post is marked as community wiki

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()
{
    // 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);
}
edit flag offensive delete link more

Comments

i already try

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'

andrea gravatar imageandrea ( 2012-08-30 03:48:19 -0600 )edit
1

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

yes123 gravatar imageyes123 ( 2012-08-30 11:10:55 -0600 )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)?

Xeverus gravatar imageXeverus ( 2014-01-02 09:15:01 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2012-08-28 10:04:42 -0600

Seen: 6,100 times

Last updated: Sep 26 '15