31
$\begingroup$

I have a camera looking at a computer monitor from varying angles. Since the camera is a grid of pixels, I can define the bounds of the monitor in the camera image as: alt text

I hope that makes sense. What I want to do is come up with an algorithm to translate points within this shape to this: alt text

I have points within the same domain as ABCD, as determined from the camera, but I need to draw these points in the domain of the monitor's resolution.

Does that makes sense? Any ideas?

  • 0
    You're asking for an *affine* transformation?2010-12-07
  • 0
    Yes, that's quite close to what I'm looking for. I'm looking to map a 4 sided shape with corners ABCD to A'B'C'D'. Is there a way to do this in general, or do i need to figure out the individual transform, rotate, shear, etc. differences between the two shapes?2010-12-07
  • 0
    I have a hard time understanding what you are asking. It seems you have an arbitrary quadrilateral and you want to map it to a rectangle? The most straight-forward way would be to average the opposite sides and take these to be your widths and heights. Is there something you want to be preserved by this transformation, e.g. area?2010-12-07
  • 0
    Not all rectangles are achievable by pointing a camera at a rectangle. So ignore one of the corner-points and then do a linear transform (along with a translation to match up the origin) to match up the remaining triangle. The fourth point will magically end up where it should be. I would make this an answer, but I can't be bothered to actually work out which matrix I need.2010-12-07
  • 1
    A 2D->2D affine transformation will not work, as they map parallelograms to parallelograms. You can do 3D->2D taking advantage of the depth to account for the non-parallelism (the two sides will be parallel in 3 space). If you know the depth, you can just follow the Wikipedia article and solve for the matrix elements of the transform.2010-12-07
  • 0
    I've searched far and wide for an answer to this. Patapom's answer is a bit confusing for me. Finally found this Codeproject article and it has a detailed explanation **with working example!** https://www.codeproject.com/Articles/674433/Perspective-Projection-of-a-Rectangle-Homography2018-07-09

9 Answers 9