<p>I'll start with the coordinate system I'm trying to use:  If I were standing on the ground, facing north, the x axis is a line moving from the west to the east (positive X is east).  Positive y is north.  Positive Z is the line from my feet up toward my head.</p>
<p>I have an image that represents a flat plane, upon which I might be standing - the Z coordinate is 0 for the whole image; it extends along the XY plane.  My image is x by y pixels (we'll say 10000 by 5000) and that represents some real world unit - I don't care that much about the scale.  The center of the image is located at the origin, so the top-left corner of the image (0, 0 pixel) is at (-5000, 2500).</p>
<p>I have a camera in this hypothetical, and I know its intrinsic matrix - we can just stick to the pinhole model for now, I can worry about distortion later.  I also know the extrinsic matrix of this camera, because I know exactly where I want to position it in world space.</p>
<p>Given this information, I want to warp the image of the plane into how my hypothetical camera would see it.</p>
<p>With this goal in mind, I have a few questions:</p>
<ol>
<li><p>I am assuming that an initial rotation matrix of I_(3x3) would be equivalent to the camera looking straight down.  Is this correct?  If not, what does the identity rotation matrix correspond to?</p>
</li>
<li><p>I am currently calculating a homography to use with cv2.warpPerspective.  To calculate this homography, I am doing:</p>
</li>
</ol>
<pre><code>translationVector = np.matrix([[xTranslation], [yTranslation], [zTranslation]])
extrinsic = np.block([R_3x3,-R_3x3]@translationVector])
intrinsic = np.matrix([[f, 0, outputWidth/2],
                       [0, f, outputHeight/2],
                       [0, 0,   1]])
composite = extrinsic[:, [0, 1, 3]]
homography = intrinsic[:, :3] @ composite
</code></pre>
<p>When I use this homography matrix (using x and y translation to bring the camera to the center of the image), however, I get a weird... duplication of the source image, where it appears on the top and the bottom of the image.  I've provided an example of what I mean - in this example, there is a positive Z offset, so only the portion of the image on the bottom should exist.  (Note: in this case my 3x3 rotation matrix has rotation of +90.0001 degrees in X - more on this in question 3).</p>
<p><a href="https://i.sstatic.net/Hsl3l.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Hsl3l.png" alt="duplication" /></a></p>
<p>2A) Why does that &quot;duplicate&quot; appear, and how do I get rid of it?</p>
<p>2B) It seems like my image is rotated oddly.  If I add 180 degrees rotation in Z it looks how I expect: is this expected or have I done something wrong?  Is this, perhaps, because in the pinhole model the image gets inverted in x and y?</p>
<ol start="3">
<li><p>If I input a rotation angle of exactly 90 degrees in X, a flickering white line appears horizontally along the center of the image with some z translation values and not with others.  I assume this is some mathematic instability - is there any way to get rid of this, or is using &quot;90.00001&quot; degrees the best I can manage?</p>
</li>
<li><p>Is there a better/faster/more direct way to warp the image - which always represents a flat XY plane - into the perspective of a camera with known intrinsics/extrinsics?</p>
</li>
</ol>
<p>Thank you!</p>

CC BY-SA 4.0
2022-11-25T10:14:55.040Z
Welcome to CG. I know that it sometimes seems to make sense to ask several questions regarding one topic but we prefer one question per thread here. This way your question(s) are easier to find and understand for others in the future who might have similar ones.
wychmaster
CC BY-SA 4.0
2022-11-26T05:11:44.030Z
@wychmaster That makes sense - I think we can consider basically all of this supporting information to the question of "is my approach reasonable, and if so, why do I have this weird double in the provided picture?"  If you'd like me to edit it relative to that, I can do so.
Helpful
<3d><transformations><perspective><camera-matrix><opencv>
Camera Perspective of 2D X/Y Plane
Helpful
# Camera Perspective of 2D X/Y Plane

(Asked by: username_0 on 2022-11-25)

I'll start with the coordinate system I'm trying to use: If I were standing on the ground, facing north, the x axis is a line moving from the west to the east (positive X is east). Positive y is north. Positive Z is the line from my feet up toward my head.

I have an image that represents a flat plane, upon which I might be standing - the Z coordinate is 0 for the whole image; it extends along the XY plane. My image is x by y pixels (we'll say 10000 by 5000) and that represents some real world unit - I don't care that much about the scale. The center of the image is located at the origin, so the top-left corner of the image (0, 0 pixel) is at (-5000, 2500).

I have a camera in this hypothetical, and I know its intrinsic matrix - we can just stick to the pinhole model for now, I can worry about distortion later. I also know the extrinsic matrix of this camera, because I know exactly where I want to position it in world space.

Given this information, I want to warp the image of the plane into how my hypothetical camera would see it.

With this goal in mind, I have a few questions:

1. I am assuming that an initial rotation matrix of I\_(3x3) would be equivalent to the camera looking straight down. Is this correct? If not, what does the identity rotation matrix correspond to?
2. I am currently calculating a homography to use with cv2.warpPerspective. To calculate this homography, I am doing:

```
translationVector = np.matrix([[xTranslation], [yTranslation], [zTranslation]])
extrinsic = np.block([R_3x3,-R_3x3]@translationVector])
intrinsic = np.matrix([[f, 0, outputWidth/2],
                       [0, f, outputHeight/2],
                       [0, 0,   1]])
composite = extrinsic[:, [0, 1, 3]]
homography = intrinsic[:, :3] @ composite

```

When I use this homography matrix (using x and y translation to bring the camera to the center of the image), however, I get a weird... duplication of the source image, where it appears on the top and the bottom of the image. I've provided an example of what I mean - in this example, there is a positive Z offset, so only the portion of the image on the bottom should exist. (Note: in this case my 3x3 rotation matrix has rotation of +90.0001 degrees in X - more on this in question 3).

[![duplication](https://i.sstatic.net/Hsl3l.png)](https://i.sstatic.net/Hsl3l.png)

2A) Why does that "duplicate" appear, and how do I get rid of it?

2B) It seems like my image is rotated oddly. If I add 180 degrees rotation in Z it looks how I expect: is this expected or have I done something wrong? Is this, perhaps, because in the pinhole model the image gets inverted in x and y?

3. If I input a rotation angle of exactly 90 degrees in X, a flickering white line appears horizontally along the center of the image with some z translation values and not with others. I assume this is some mathematic instability - is there any way to get rid of this, or is using "90.00001" degrees the best I can manage?
4. Is there a better/faster/more direct way to warp the image - which always represents a flat XY plane - into the perspective of a camera with known intrinsics/extrinsics?

Thank you!

**Tags:** 3d, transformations, perspective, camera-matrix, opencv

> **Comments:**
> **username_1**: Welcome to CG. I know that it sometimes seems to make sense to ask several questions regarding one topic but we prefer one question per thread here. This way your question(s) are easier to find and understand for others in the future who might have similar ones.  
> **username_0**: @username_1 That makes sense - I think we can consider basically all of this supporting information to the question of "is my approach reasonable, and if so, why do I have this weird double in the provided picture?"  If you'd like me to edit it relative to that, I can do so.  

---

## 0 answers

