# Slope in downhills

**URL:** <https://community.stereolabs.com/t/slope-in-downhills/6372>\
**Category:** Python\
**Tags:** python, depth\
**Created:** [June 21, 2024, 10:21am UTC](https://community.stereolabs.com/t/slope-in-downhills/6372 "2024-06-21T10:21:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CristianViSa](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/c/85e7bf/32.png) [@CristianViSa](https://community.stereolabs.com/u/CristianViSa)\
**Post date:** [June 21, 2024, 10:21am UTC](https://community.stereolabs.com/t/slope-in-downhills/6372/1 "2024-06-21T10:21:40Z")

</div>

Hi,

I am using a ZED 2i to calculate slopes of some floors. I have they real slope measured with a level.

I have noticed that, always that the slope is positive, the calculation is fine, however, if i rotate the surface to make the slope go down, the calculation is wrong.

This happens almost always, is this a limitation of the camera?

---

<div class="post-metadata">

**Author:** ![Myzhar](https://community.stereolabs.com/user_avatar/community.stereolabs.com/myzhar/32/11_2.png) [@Myzhar](https://community.stereolabs.com/u/Myzhar)\
**Post date:** [June 21, 2024, 4:04pm UTC](https://community.stereolabs.com/t/slope-in-downhills/6372/2 "2024-06-21T16:04:01Z")

</div>

Hi @CristianViSa  
can you please record an SVO with ZED Explorer and share your code so we can test and debug it in the same conditions?

You can send the material to [support@stereolabs.com](mailto:support@stereolabs.com) if you do not want to share it publicly.

---

<div class="post-metadata">

**Author:** ![CristianViSa](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/c/85e7bf/32.png) [@CristianViSa](https://community.stereolabs.com/u/CristianViSa)\
**Post date:** [June 25, 2024, 6:01am UTC](https://community.stereolabs.com/t/slope-in-downhills/6372/3 "2024-06-25T06:01:56Z")

</div>

Hi, sorry for the late response, i was on vacations.

Here you can see my svo2 on a WeTransfer link. [WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free](https://we.tl/t-joOzGDqPCG)

In the frames where the slope is Upwards, the slope is perfect, howerver, when it goes Downwards is wrong.

With a level, the slope is 7.5º.

My code is simple, i just simply read the cloud points, rotate them using YZX convention and then i use a cloud point viewer (potree) to calculate the slope.

My guess is i am doing something wrong with the rotation, maybe the angles? maybe the order?

Here is my .py  
[slope.py](https://community.stereolabs.com/uploads/short-url/nfJETEx00YceRxr7WOATphg7QUB.py) (4.9 KB)

---

<div class="post-metadata">

**Author:** ![mattrouss](https://community.stereolabs.com/user_avatar/community.stereolabs.com/mattrouss/32/2452_2.png) [@mattrouss](https://community.stereolabs.com/u/mattrouss)\
**Post date:** [July 1, 2024, 4:56pm UTC](https://community.stereolabs.com/t/slope-in-downhills/6372/4 "2024-07-01T16:56:47Z")

</div>

Request #54242 “Slope calculation using ZED 2i i…” was closed and merged into this request. Last comment in request #54242:

Hi, I recently wrote a post on your forum asking for help about calculating slopes in downhills. I was asked to upload an svo so you could test it on same conditions but I had no response, so I send this email.

I am using this camera to measure the slope of terrains. I attach my .py file so you can use it if you need. The script act as follows:

- 

Read SVO  
\*  
Obtain XYZ Angles of rotation  
\*  
Rotate the cloud point this angels to make it “straight” in YZX order  
\*  
Export Rotated PC to LAZ format

Then i use a cloud point viewer (potreehttps://github.com/potree/potree) to see the cloud point and obtain the points for slope calculation (distance in height / distance in horizontal) \* 100.

The thing is, when the slope goes upwards, it matches perfectly with reality. In the SVO I attach via drive link, the slope that can be seen from frames 1080 to 1500 is 7.5º measured with a level.

However, when it goes downwards, the slope DOES NOT MATCH REALITY, I obtain 3º of slope.

Is this a limitation of the camera? or am I doing something wrong? Maybe the rotation angles, i use the orientation angles of the camera to straight the cloud point, is this de correct angle process?

Thanks in advance

SVO2 Video:[https://drive.google.com/file/d/1VdMA1NKcC7dEWgIJyqzNCrY1FTmAkQJP/view?usp=sharing](https://drive.google.com/file/d/1VdMA1NKcC7dEWgIJyqzNCrY1FTmAkQJP/view?usp=sharing)

Un saludo,

[cid:0f19f013-fcea-4999-b2a8-e02c5b534559][https://app.businesscards.eco/e/dd10pe/full](https://app.businesscards.eco/e/dd10pe/full)  
Outlook-c4hvcvl1.png  
Slope\_Calc.zip

---

<div class="post-metadata">

**Author:** ![mattrouss](https://community.stereolabs.com/user_avatar/community.stereolabs.com/mattrouss/32/2452_2.png) [@mattrouss](https://community.stereolabs.com/u/mattrouss)\
**Post date:** [July 2, 2024, 3:23pm UTC](https://community.stereolabs.com/t/slope-in-downhills/6372/5 "2024-07-02T15:23:17Z")

</div>

Hi Cristian,

I sincerely apologize for the late reply.

The ZED SDK has a parameter in its API that allows to directly transform the 3D data (e.g. point cloud, object detection boxes, etc) in the WORLD reference frame, which is what you are trying to do by rotating the point cloud using the positional tracking.  
Can you export the point cloud with this parameter RuntimeParameters.measure3d\_reference\_frame set to REFERENCE\_FRAME.WORLD, and remove your point cloud rotations? This way we can make sure that the correct rotations are applied.  
(You may require to set the translation to identity)

Best,  
Matthew Rousseau

[Stereolabs](https://www.stereolabs.com/) Support

---

<div class="post-metadata">

**Author:** ![CristianViSa](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/c/85e7bf/32.png) [@CristianViSa](https://community.stereolabs.com/u/CristianViSa)\
**Post date:** [July 3, 2024, 7:14am UTC](https://community.stereolabs.com/t/slope-in-downhills/6372/6 "2024-07-03T07:14:25Z")

</div>

Hi,

No worries. I have tried to set it as said, but with this parameter i obtain wrong values for both cases.

When going upwards i obtain slope values around 0.5º to 1.5º (Reality is 7º)  
When going downards i obtain slope values around 2.5º and 3º

Here is the code, i just update the reference frame in the RuntimeParameters and remove rotations.

[slope\_world.py](https://community.stereolabs.com/uploads/short-url/bWpNzmSnzAGKfeDwXnGZ9BXL6dJ.py) (5.3 KB)

---

<div class="post-metadata">

**Author:** ![mattrouss](https://community.stereolabs.com/user_avatar/community.stereolabs.com/mattrouss/32/2452_2.png) [@mattrouss](https://community.stereolabs.com/u/mattrouss)\
**Post date:** [July 5, 2024, 4:53pm UTC](https://community.stereolabs.com/t/slope-in-downhills/6372/7 "2024-07-05T16:53:14Z")

</div>

Hi @CristianViSa,

I see that you set the set\_gravity\_as\_origin to false in your sample, have you tried with it set to true?

As the floor plane estimation may change for each camera startup, having the gravity as origin may return a more robust world rotation and give you a better slope angle.

---

<div class="post-metadata">

**Author:** ![CristianViSa](https://community.stereolabs.com/letter_avatar_proxy/v4/letter/c/85e7bf/32.png) [@CristianViSa](https://community.stereolabs.com/u/CristianViSa)\
**Post date:** [July 16, 2024, 9:06am UTC](https://community.stereolabs.com/t/slope-in-downhills/6372/8 "2024-07-16T09:06:58Z")

</div>

Hi,

I keep struggling with this, i have tried every combination possible, using the REFERENCE.WORLD, the set\_gravity to True, every rotation order and i keep obtaining bad results ONLY IN DOWNHILLS.

I dont know, maybe is a limitation of the camera, you may know more than i do.
