Ask Your Question
1

homography for cordinates of poins

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

this post is marked as community wiki

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

updated 2012-08-28 10:04:42 -0500

andrea gravatar image andrea
101 1 4 7

sorry probably it's a stupid question :) it's 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"....

delete close flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
5

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

this post is marked as community wiki

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

updated 2012-08-30 05:30:28 -0500

Ben gravatar image Ben
1132 6 20

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

Comments

1

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

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

answered 2014-01-02 09:15:01 -0500

Xeverus gravatar image Xeverus
19 3

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)?

link delete flag offensive edit
0

answered 2012-08-30 03:48:19 -0500

this post is marked as community wiki

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

updated 2012-08-30 03:48:19 -0500

andrea gravatar image andrea
101 1 4 7

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'

link delete flag offensive edit

Comments

1

@andrea: please don't add an answer to your question for further questions. Edit your question instead or add comments to my answer to stick to the forum rules :) I edited my answer, it should help you with your problem.

Ben ( 2012-08-30 05:32:27 -0500 )edit

Login/Signup to Answer

Question tools

Follow

subscribe to rss feed

Stats

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

Seen: 1,052 times

Last updated: Jan 02