1

We would like to implement this kind of transformation: Screenshot-73.png

Screenshot-73

This image is taken from Gimp, using the Unified Transform Tool. You simply drag the corners and the rectangle is transformed freely. I believe this is called a projective transformation.

Does anyone have the formulas to create the transformation matrix for such a projective transformation given the locations of the corners?

Spektre
  • 49,595
  • 11
  • 110
  • 380
Gazihan Alankus
  • 11,256
  • 7
  • 46
  • 57
  • hmm they might do it differently leave camera and projection matrix as is and just changing object matrix rotating it by predefined axis (chosen by selected point and movement) by an angle computed by `atan2` of projected triangle of the moved and original point position in the screen plane ... Anyway if you want to compute full matrix from points then I think you need some more info like focal length and FOV of the camera then construct system of linear equation `moved_point = matrix * original_point` and solve the system for all the points getting all the elements of the matrix. – Spektre Jul 09 '19 at 07:35
  • Also this problem can be solved in very different way (if you have some prior knowledge about image or features) see [Transformation of 3D objects related to vanishing points and horizon line](https://stackoverflow.com/a/53303948/2521214) Also there is a possibility your image is not projection from 3D but just textured 2D polygon instead ... – Spektre Jul 09 '19 at 07:43
  • My problem here is I would like to have a matrix so that I can transform points in and out of this region, it will be a part of a larger transformation pipeline. Are you sure we need more info other than the four corners to get a matrix? – Gazihan Alankus Jul 10 '19 at 06:20
  • No I am not sure ... 4x4 perspective matrix I use needs: `fovy,aspect,zNear,zFar` where aspect is known from image resolution and `znear,zfar` can be hard-coded. So that is just 1 unknown. The coordinate syustem needs 3 basis vectors and 1 position which sum up into `1+4*3 = 13` unknowns. each point creates 3 equation in the system so `ceil(13/3) = 5` so we need 1 info and 4 points or 5 points. Yes you got more than 4 points but there is problem if they are linearly dependent (wrong points selected) the system will not have solution ... – Spektre Jul 10 '19 at 08:17

1 Answers1

0

We have used the following library to obtain the transformation matrix from the source and destination corner points:

https://github.com/jlouthan/perspective-transform

Gazihan Alankus
  • 11,256
  • 7
  • 46
  • 57
Can
  • 1,646
  • 9
  • 13