# Convert/Normalize 3x3 Homography Matrix to 4x4 3D Matrix

Hello!

I have been stuck on this problem from months and I hope someone can help me. My problems seems like something everyone has gone through already. If I am doing this wrong or is overly complicated, please let me know of a better solution!

So I have a 3D environment written in Direct3D (please don't hate me for picking Direct3D over OpenGL, there were other factors involved) and would like to utilize the OpenCV library in my environment.

Anyway, my problem is that findHomography returns a 3x3 2D matrix. I would like to convert/normalize this matrix into a 4x4 3D matrix with the Z coordinates essentially set to 0. I figure there's two major steps required in this process.

1. Normalize the 3x3 matrix coordinates.
2. Convert the 3x3 matrix to a 4x4 matrix.

## Normalize the 3x3 matrix elements

To normalize the matrix elements, I'm assuming we need to divide each matrix element with the maximum value of each matrix element. However, what are the maximum value for each matrix element?

## Convert the 3x3 matrix to a 4x4 matrix.

I know OpenCV and Direct3D coordinate systems are different. Here is what I am assuming.

• OpenCV is row major with the origin at the upper left corner.
• Direct3D is column major with the origin at the lower left corner.

Here is how I am mapping my matrix conversion.

OpenCV Homography Matrix

m00  m01  m02
m10  m11  m12
m20  m21  m22


Direct3D Homography Matrix

m00  m10  0  m20
m01  m11  0  m21
0    0    1  0
m02  m12  0  m22


So this has been my approach to convert OpenCV 3x3 matrix to Direct3D 4x4 matrix. What should be my values for normalization in step 1? Am I mapping the matrix correctly in Step 2?

Thanks in advance! You have no idea how much I've been struggling with this issue.

edit retag close merge delete