# Hough probability maths (hough.cpp)

**URL:** <https://forum.opencv.org/t/hough-probability-maths-hough-cpp/8541>\
**Category:** C++\
**Tags:** houghlines, imgproc\
**Created:** [April 25, 2022, 2:00pm UTC](https://forum.opencv.org/t/hough-probability-maths-hough-cpp/8541 "2022-04-25T14:00:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Logan5015](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Logan5015](https://forum.opencv.org/u/Logan5015)\
**Post date:** [April 25, 2022, 2:00pm UTC](https://forum.opencv.org/t/hough-probability-maths-hough-cpp/8541/1 "2022-04-25T14:00:51Z")

</div>

Hi all, while looking at the code for probabilistic hough for uni, I came across a section of the code that doesnt make sense with no explanation.

Within hough.cpp (found through github: [opencv/hough.cpp at master · opencv/opencv · GitHub](https://github.com/opencv/opencv/blob/master/modules/imgproc/src/hough.cpp)) , on line 567, after calculating rho using the polar coordinate formula, the code then adds “(numrho - 1) / 2” to the already calculated rho

surely this is adding extra value to the pre-calculated distance value and shouldnt be needed within this process. can anyone explain why this calculation happens?

any help would be greatly appreciated

---

<div class="post-metadata">

**Author:** ![Tarlan](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@Tarlan](https://forum.opencv.org/u/Tarlan)\
**Post date:** [August 5, 2022, 10:09pm UTC](https://forum.opencv.org/t/hough-probability-maths-hough-cpp/8541/2 "2022-08-05T22:09:14Z")

</div>

r += (numrho - 1) / 2; it prevents negative value of r.
