Calculating new positions of keypoints


can somebody help me, how we can calculate the new positions of keypoints in the transformed image,the keypoints were detected in original image. I am using opencv homography matrix and warpPerspective to make the transformed image.

Here is a code..

... std::vector< Point2f > points1,points2; for( int i = 0; i < matches1.size(); i++ ) { points1.push_back( keypoints_input1[matches1[i].queryIdx ].pt ); points2.push_back( keypoints_input2[matches1[i].trainIdx ].pt ); } /* Find the Homography Matrix for current and next frame*/ Mat H1 = findHomography( points2, points1, CV_RANSAC ); /* Use the Homography Matrix to warp the images*/ cv::Mat result1; warpPerspective(input2, result1, H1, Size(input2.cols+150, input2.rows+150), INTER_CUBIC); ... }

Now I want to calculate the new positions of points2 in the result1 image.

For example in the below transformed image<img alt="" class="b-lazy" data-src="https://i.stack.imgur.com/l0z95.png" data-original="https://i.stack.imgur.com/l0z95.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /> , we know the corner points. Now I want to calculate the new position of the keypoints say before transformation {(x1,y1),(x2,y2),(x3,y3)...}, How we can calculate it?

Update: opencv 'perspectiveTransform' does what I trying to do.


Let's call I' the image obtained by warping image I using homography H.

If you extracted keypoints <strong>m<sub>i</sub></strong> = (x<sub>i</sub>, y<sub>i</sub>, 1) in original image I, you can get the keypoints <strong>m'<sub>i</sub></strong> in the warped image I' using the homography transform: S * <strong>m'<sub>i</sub></strong> = H * <strong>m<sub>i</sub></strong>. Notice the scale factor S, if you want the keypoints coordinates in pixels, you <em>have</em> to scale <strong>m'<sub>i</sub></strong> so that the third element is 1.

If you want to understand where the scale factor comes from, have a look at <a href="https://en.wikipedia.org/wiki/Homogeneous_coordinates" rel="nofollow">Homogeneous Coordinates</a>.

Also, there is an OpenCV function to apply this transformation to an array of points: perspectiveTransform(<a href="http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#perspectivetransform" rel="nofollow">documentation</a>).


  • OpenCV Android extract match Mat after feature detection
  • Link two pictures pixels using Homography
  • Estimation of euler angels (camera pose) using images from camera and opencv library
  • why is the sort() not working?
  • Why can't the compiler deduce template parameter from return type?
  • 3D Math: Calculate Bank (Roll) angle from Look and Up orthogonal vectors
  • Pointer vs Reference difference when passing Eigen objects as arguments
  • How to save dynamically created textboxes and their values
  • Formatting a text in a table cell with PHPWord e.g. bold, font, size e.t.c
  • Accessing another variable in the same class with a click event
  • Result showing lining on image
  • Galaxy S4 Android Custom Camera Issue
  • Not able to display correct data in table -AngularJS
  • F#: In which memory area is the continuation stored: stack or heap?
  • Deleting empty Series out of Graph (with VBA)
  • runtime-check whether an instance (Base*) override a parent function (Base::f())
  • Does CSS support inheritance [duplicate]
  • Xaml, wpf image position and crop issue
  • Inversing an interpolation of rotation
  • C# - Most efficient way to iterate through multiple arrays/list
  • HttpClient: disabling chunked encoding
  • Display validation errors inside
  • quiver not drawing arrows just lots of blue, matlab
  • Floated image with variable width and heading with background image
  • Extract zip entries to another Zip file
  • Using a canvas object in a thread to do simple animations - Java
  • GridView breaks while scrolling
  • How to change the font size of a single index for UISegmentedControl?
  • Time complexity of a program which involves multiple variables
  • Atlas images wrong size on iPad iOS 9
  • Change multiple background-images with jQuery
  • Android screen density dpi vs ppi
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Change an a tag attribute in JavaScript based on screen width
  • How do I use the BLAS library provided by MATLAB?
  • Acquiring multiple attributes from .xml file in c#
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • How can i traverse a binary tree from right to left in java?