asked 2012-08-28 10:04:42 -0500
This post is a wiki. Anyone with karma >50 is welcome to improve it.
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"....
answered 2012-08-28 10:38:12 -0500
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);
}
answered 2012-08-30 03:48:19 -0500
This post is a wiki. Anyone with karma >50 is welcome to improve it.
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'
Asked: 2012-08-28 10:04:42 -0500
Seen: 439 times
Last updated: Aug 30 '12
Camera with auto-focus and 3D reconstruction
Laser scanner and the math behind
The homography tutorial in java
How to pass points to minAreaRect using Java Bindings
findHomography is giving wrong results
How to efficiently filter out points geometrically close to each other?