# Get camera intrinsics for undistorted images

**URL:** <https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075>\
**Category:** Pipeline & Plugins\
**Tags:** question, realityscan\
**Created:** [January 16, 2024, 1:59pm UTC](https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075 "2024-01-16T13:59:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![s1ddok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@s1ddok](https://forums.unrealengine.com/u/s1ddok)\
**Post date:** [January 16, 2024, 1:59pm UTC](https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075/1 "2024-01-16T13:59:32Z")

</div>

Hello! Very thankful for 1.3 release providing essential fixes for undistorted images and removing the black bars.

However currently those images are somewhat useless because there is no way to export camera intrinsics suitable for undistorted images. I tried to manually calculate those matrices using OpenCV’s undistort but they don’t match with the provided images. Am I missing something or this is not implemented in any form right now?

---

<div class="post-metadata">

**Author:** ![OndrejTrhan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ondrejtrhan/32/906565_2.png) [@OndrejTrhan](https://forums.unrealengine.com/u/OndrejTrhan)\
**Post date:** [January 16, 2024, 2:22pm UTC](https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075/2 "2024-01-16T14:22:49Z")

</div>

Hi [s1ddok](https://dev.epicgames.com/community/api/user_profiles/tab-redirect/about?discourse_username=s1ddok),  
the black lines removing was suppose just for Inner region settings.  
I think the option for camera intrinsics wasn’t possible even before. But I could be wrong about it…

---

<div class="post-metadata">

**Author:** ![s1ddok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@s1ddok](https://forums.unrealengine.com/u/s1ddok)\
**Post date:** [January 17, 2024, 2:26pm UTC](https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075/3 "2024-01-17T14:26:13Z")

</div>

yup, I just wanted to confirm I’m not missing something. Now I wonder how can I use undistorted images if none of intrinsics is available for it. Can you share some math to calculate fx, fy for undistorted images given that I have xmps for distorted ones? I’m using inner region as well and I’m not sure how to calculate intrinsics for those images given that some arbitrary cropping is happening under the hood

---

<div class="post-metadata">

**Author:** ![s1ddok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@s1ddok](https://forums.unrealengine.com/u/s1ddok)\
**Post date:** [January 17, 2024, 3:00pm UTC](https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075/4 "2024-01-17T15:00:17Z")

</div>

Another weird thing is that with Inner region + Resolution: Fit settings sometimes the result undistorted images become larger on one axis than the original one. Is it expected?

---

<div class="post-metadata">

**Author:** ![OndrejTrhan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ondrejtrhan/32/906565_2.png) [@OndrejTrhan](https://forums.unrealengine.com/u/OndrejTrhan)\
**Post date:** [January 17, 2024, 3:10pm UTC](https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075/5 "2024-01-17T15:10:20Z")

</div>

Hi, regarding to the first issue this could be helpful: [RealityCapture XMP Camera Math](https://forums.unrealengine.com/t/realitycapture-xmp-camera-math/682564). Or you can try align undistorted images inside RealityCapture and then export wanted parameters.

Regarding your second question, that is expected, as Fit will provide new image according to a best fit. To have the image in same size as original, you need to use Resolution: Preserve.

- Fit - keeps the resolution of the image created in the previous step.
- Preserve - The resolution of the undistorted image is the same as the resolution of the original image.

---

<div class="post-metadata">

**Author:** ![s1ddok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@s1ddok](https://forums.unrealengine.com/u/s1ddok)\
**Post date:** [January 17, 2024, 3:46pm UTC](https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075/6 "2024-01-17T15:46:43Z")

</div>

I don’t think using Preserve is correct because inner region can potentially change aspect ratio of the image.

I’m able to parse XMP math using camorph but I’m not sure how to calculate undistorted intrinsics using it because your undistortion algorithm is not exposed publicly and I tried to use OpenCV2 and I checked that it doesn’t match your algorithm.

Is it possible to somehow obtain intrinsics without repaying credits for re-alignment? Since I also fix cx,cy to be in the center, I only need to recalculate fx, fy for undistorted images, but I’m not sure what would be the correct formula.

---

<div class="post-metadata">

**Author:** ![OndrejTrhan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ondrejtrhan/32/906565_2.png) [@OndrejTrhan](https://forums.unrealengine.com/u/OndrejTrhan)\
**Post date:** [January 17, 2024, 4:12pm UTC](https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075/7 "2024-01-17T16:12:32Z")

</div>

It depends on the usage of the undistorted images and what you want to use them for.

I think these equations could be used to find wanted parameters:  
`m = K*DivisionModel^-1( x )`  
as you can have undistorted and distorted coordinates of some points.

As K matrix is

```auto
[ focal skew ppU
   0 aspect*focal ppV
   0 0 1 ]

```

I suppose it should be possible to make the equations to find focal.

As the undistorted images are new images and the intrinsics are some kind of export you need to license those images.

---

<div class="post-metadata">

**Author:** ![s1ddok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@s1ddok](https://forums.unrealengine.com/u/s1ddok)\
**Post date:** [January 18, 2024, 8:02am UTC](https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075/8 "2024-01-18T08:02:45Z")

</div>

Solving equation is a bit on a harder side for me. I came up with an alternative idea: what if I export with “keep intrinsics” + resolution “preserve”, but instead of finding new f, I’ll just calculate new crop that will align with “Inner region”.

Can you share a math behind calculating “Inner region” crop?

---

<div class="post-metadata">

**Author:** ![OndrejTrhan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ondrejtrhan/32/906565_2.png) [@OndrejTrhan](https://forums.unrealengine.com/u/OndrejTrhan)\
**Post date:** [January 18, 2024, 9:09am UTC](https://forums.unrealengine.com/t/get-camera-intrinsics-for-undistorted-images/1619075/9 "2024-01-18T09:09:31Z")

</div>

Hi, I am sorry, but we can’t share that math.  
You can try this workflow to find out the focal length: [https://www.youtube.com/watch?v=yq0XjvBlsiU&t=427s](https://www.youtube.com/watch?v=yq0XjvBlsiU&t=427s)
