# Does triangulatePoints() undistort and rectify given points?

**URL:** <https://forum.opencv.org/t/does-triangulatepoints-undistort-and-rectify-given-points/3722>\
**Category:** Uncategorized\
**Tags:** calib3d, stereo\
**Created:** [June 6, 2021, 3:16pm UTC](https://forum.opencv.org/t/does-triangulatepoints-undistort-and-rectify-given-points/3722 "2021-06-06T15:16:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Wolff](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/paul_wolff/32/689_2.png) [@Paul\_Wolff](https://forum.opencv.org/u/Paul_Wolff)\
**Post date:** [June 6, 2021, 3:16pm UTC](https://forum.opencv.org/t/does-triangulatepoints-undistort-and-rectify-given-points/3722/1 "2021-06-06T15:16:14Z")

</div>

Dear community,  
I am trying to recover 3d Pose from 2 corresponding observations of a stereo camera setup. I did a stereo camera calibration initially so I have my P1, P2, R1 and R2 as well as my 2 points at hand.

To obtain 3D Points I first undistort my initial corresponding pixel coordinates with undistortPoints() and triangulate them using triangulatePoints()

However I am confused about how triangulatePoints() preprocesses its arguments because I am getting nonsense result which does not correspond to ground truth at all. So I am starting to debug.

Therefore my question is: Does triangulatePoints do undistortion too or do I have to cakk it myself?

And in which case do I need to pass R1/R2 and/or P1/P2 into undistortPoints()

Thank you in advance for your help!

---

<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:** [June 6, 2021, 3:49pm UTC](https://forum.opencv.org/t/does-triangulatepoints-undistort-and-rectify-given-points/3722/2 "2021-06-06T15:49:55Z")

</div>

> [@Paul\_Wolff](#):
>
> Does triangulatePoints do undistortion too

it can’t. it doesn’t take any arguments required for that operation.

I can’t comment on the other question.

---

<div class="post-metadata">

**Author:** ![JeremyWright](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/jeremywright/32/5482_2.png) [@JeremyWright](https://forum.opencv.org/u/JeremyWright)\
**Post date:** [June 15, 2022, 1:18am UTC](https://forum.opencv.org/t/does-triangulatepoints-undistort-and-rectify-given-points/3722/3 "2022-06-15T01:18:28Z")

</div>

TriangulatePoints() returns “OutputArray points4D”.  
But OutputArray doesn’t directly mean XYZ data.  
You need to recalculate the OutputArray to reconstruct the 3D data.

---

<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:** [June 15, 2022, 7:50am UTC](https://forum.opencv.org/t/does-triangulatepoints-undistort-and-rectify-given-points/3722/4 "2022-06-15T07:50:57Z")

</div>

@JeremyWright your statement contradicts documentation: [OpenCV: Triangulation](https://docs.opencv.org/4.x/d0/dbd/group__triangulation.html)

---

<div class="post-metadata">

**Author:** ![JeremyWright](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/jeremywright/32/5482_2.png) [@JeremyWright](https://forum.opencv.org/u/JeremyWright)\
**Post date:** [June 15, 2022, 9:25am UTC](https://forum.opencv.org/t/does-triangulatepoints-undistort-and-rectify-given-points/3722/5 "2022-06-15T09:25:56Z")

</div>

Your link mentioned cv::sfm::triangulatePoints.  
I mentioned the cv::triangulatePoints.  
[https://docs.opencv.org/4.x/d9/d0c/group\_\_calib3d.html#gad3fc9a0c82b08df034234979960b778c](https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#gad3fc9a0c82b08df034234979960b778c)

---

<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:** [June 15, 2022, 10:52am UTC](https://forum.opencv.org/t/does-triangulatepoints-undistort-and-rectify-given-points/3722/6 "2022-06-15T10:52:05Z")

</div>

good catch.

so the results need to be converted to 3D, by dividing by the fourth component of each vector.

there is `convertPointsFromHomogeneous` to do that.

[https://docs.opencv.org/4.x/d9/d0c/group\_\_calib3d.html#gac42edda3a3a0f717979589fcd6ac0035](https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#gac42edda3a3a0f717979589fcd6ac0035)
