I'm using 3D coordinates to take account
- translation by vector
[u v]
- 2D linear transformation made by matrixabcd
The overall transformation matrix will have the form
[ a b u]
M = [ c d v]
[ 0 0 1]
- Take 3 points
A=[x1 y1 1]
andB=[x2 y2 1]
andC=[x3 y3 1]
from the triangle - Compare them with their position after transformation
A' = [x1' y1' 1]
andB'=[x2' y2' 1]
andC'=[x3' y3' 1]
. Id est: Do your math to get the transformation matrixM
so thatA' = M A
andB' = M B
andC' = M C
- Apply
x -> M x
to every input points
Edit: Incorporate the translation in the matrix M
using Translation in transformation matrix
Edit: It seems "do your math" is not clear for you.
You'll realize that the 3 equations can be written as:
[x1' x2' x3'] [x1 x2 x3]
[y1' y2' y3'] = M [y1 y2 y3]
[1 1 1 ] [1 1 1 ]
or
X' = M X
Or
M = X . X'^-1
and yes, OpenCV has a function inv()
on matrices.