1
votes

I am writing some image processing program using OpenCV.

I need to transform the image using several perspective transformations. Perspective transformation is defined by the matrix. I know, that we can get complex affine transform by multiplication of the simple transform matriсes (rotation, translation, etc.). But when I tried to multiply two perspective transformation matrices, I didn't get the transformation matrix, that corresponds to the consequently used first and second matrix.

So, how can I get the matrix of several consequent perspective transformations?

1
I am not sure, that it is a question for stackoverflow. It's more computer vision question. - Alex

1 Answers

1
votes

Let you have two perspective matrices C:(x,y)->(u,v) and D:(u,v)->(r,g):

And you try to get M:(x,y)->(r,g)

You should substitute ui and vi from (1),(2) to the equations (3),(4).

 ui = (c00*xi + c01*yi + c02) / (c20*xi + c21*yi + c22) (1)

 vi = (c10*xi + c11*yi + c12) / (c20*xi + c21*yi + c22) (2)

 ri = (d00*ui + d01*vi + d02) / (d20*ui + d21*vi + d22) (3)

 gi = (d10*ui + d11*vi + d12) / (d20*ui + d21*vi + d22) (4)

After that you can see that M = D*C