# WarpAffine for 3D

**URL:** <https://forum.opencv.org/t/warpaffine-for-3d/2603>\
**Category:** C++\
**Created:** [April 5, 2021, 7:32am UTC](https://forum.opencv.org/t/warpaffine-for-3d/2603 "2021-04-05T07:32:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gorakh22](https://avatars.discourse-cdn.com/v4/letter/g/ecb155/32.png) [@Gorakh22](https://forum.opencv.org/u/Gorakh22)\
**Post date:** [April 5, 2021, 7:32am UTC](https://forum.opencv.org/t/warpaffine-for-3d/2603/1 "2021-04-05T07:32:16Z")

</div>

Hello All,

1. I am looking for “getRotationMatrix3D” function in cpp implementation to utilize it for 3D rotation although 2D is available but 3D is not visible.
2. Kindly confirm if WarpAffine for 3D rotation is available or not in cpp.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [April 5, 2021, 7:43am UTC](https://forum.opencv.org/t/warpaffine-for-3d/2603/2 "2021-04-05T07:43:07Z")

</div>

no, none of it is builtin.

what are you trying to do, exactly ?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [April 5, 2021, 8:44am UTC](https://forum.opencv.org/t/warpaffine-for-3d/2603/3 "2021-04-05T08:44:31Z")

</div>

use Rodrigues to convert between a “rotation vector” (length encodes angle) and a 3x3 rotation matrix.

a 3D affine transformation is a 4x4 matrix that has no projective component (4th row is exactly [0,0,0,1]). you can build such matrices yourself.

`warpAffine` is an operation on raster images. the 3D equivalent would have to work on **voxel** data.

if you just want to apply a transformation to 3D points, there’s [OpenCV: Operations on arrays](https://docs.opencv.org/master/d2/de8/group __core__ array.html#ga393164aa54bb9169ce0a8cc44e08ff22) docs aren’t clear on whether it is expected to support 4x4 transformation matrices. my bet it that it does.

---

<div class="post-metadata">

**Author:** ![Gorakh22](https://avatars.discourse-cdn.com/v4/letter/g/ecb155/32.png) [@Gorakh22](https://forum.opencv.org/u/Gorakh22)\
**Post date:** [April 5, 2021, 3:59pm UTC](https://forum.opencv.org/t/warpaffine-for-3d/2603/4 "2021-04-05T15:59:18Z")

</div>

Thanks Crackwitz,

I will explore more on your suggestion. Can you help me with remaining elements of the matrix for 3D rotation?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Silvestri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/alejandro_silvestri/32/357_2.png) [@Alejandro\_Silvestri](https://forum.opencv.org/u/Alejandro_Silvestri)\
**Post date:** [April 5, 2021, 7:37pm UTC](https://forum.opencv.org/t/warpaffine-for-3d/2603/5 "2021-04-05T19:37:37Z")

</div>

Hi @Gorakh22

There is a getRotationMatrix2D because images are 2D. By going into 3D world from images, you rising the complexity of the problem, so there is no getRotationMatrix3D, there are many non trivial geometric ways to get it instead, and they depend on context.

It will help us to help you help everyone if you provide some images of what you are trying to achieve.

For example, in the particular case of a rotated plane with texture, you can use **homography** , aka perspective transformation, [like in this tutorial](https://docs.opencv.org/master/dc/d2c/tutorial_real_time_pose.html) (on this link fist go to the bottom and see the videos).
