# Finding the angle between horizontal and vertical lines

**URL:** <https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668>\
**Category:** OpenMV Boards\
**Created:** [November 9, 2022, 8:35am UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668 "2022-11-09T08:35:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [November 9, 2022, 8:35am UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/1 "2022-11-09T08:35:06Z")

</div>

Hi there,  
i am trying to find a way to calculate the angle of vertical lines against horizontal lines on a cloth.  
this is the best image i think without any filter:

 ![test2](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/b/bc836b85bca965e17fea2e3eedb6101ccf6da83c.jpeg)

and this the final image with some mean adaptive threshold:

 ![test](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/9/93d957c0b9957f9fc2ca7b1063da7729e1d63c7e.jpeg)

and then calculate the angle:

 ![test3](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/2/27f63ac42fb0c6e764520f1927cbf626dff7b2af.jpeg)

do you have any idea where to start?

best regards..

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [November 9, 2022, 9:32am UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/2 "2022-11-09T09:32:23Z")

</div>

and here is the best with different setup of lighting:  
 ![dome2](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/b/bce109e0711b843cc27f94a3d2637ab4a7a61fa1.jpeg)

and then some filtering:  
 ![dome](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/a/abedc77cca52cd25d1b9d8c19935768bb723bf81.jpeg)

to calculate the angle…:

![dome3](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/a/a2ba343c47e4126632bce379586d5d353c4cd06f.jpeg)

which is the best ?

---

<div class="post-metadata">

**Author:** ![Inter\_fan](https://avatars.discourse-cdn.com/v4/letter/i/90ced4/32.png) [@Inter\_fan](https://forums.openmv.io/u/Inter_fan)\
**Post date:** [November 9, 2022, 2:21pm UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/3 "2022-11-09T14:21:22Z")

</div>

We did something similar, create a vector from a known point. Then it is quite simple to calculate the angle using the .math features.  
The difficulty is trying to find the crossing point, because if you have that you would be able to create 2 vectors with the find lines? Or something similar?

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [November 9, 2022, 2:39pm UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/4 "2022-11-09T14:39:43Z")

</div>

in fact i want to measure the angle of vertical lines only . horizontal lines will be 0 degrees all the time.  
The job is to find the vertical lines with find lines tool and measure that angle regarding the y axis. Completely vertical line will be 0 degrees . so must get negative and positive values if lines are slightly left or right of the y -axis.  
Thinking that i dont have good lines to make this work properly thought.  
And unfortunately cant take better pictures.  
Do you think that is this possible with these images?  
 ![dome4](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/f/fb7fb6cce80341db9b1010817f0d6d3b9005f9bc.jpeg)  
think that the second setup is better for this…

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [November 10, 2022, 8:59am UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/5 "2022-11-10T08:59:17Z")

</div>

think getting closer regarding the image.  
But still cannot measure the tilt of the vertical lines…  
i drawn a cross with lines so to be able to see better the tilt too…  
 ![domenew](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/6/67bde312b94dc41e12ed7fefc885f2418254f3db.jpeg)  
and the below image is from diferent cloth with almost 0degrees tilt on the vertical lines  
 ![domenewred](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/e/eb5247f0d75f2401b4d123b08e173caeba24e2f9.jpeg)

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [November 12, 2022, 1:00pm UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/6 "2022-11-12T13:00:19Z")

</div>

cant resolve the issue i have with the find lines tool.  
it keeps finding unnecessary lines.  
In picture below i have set the tool to a region in the center only.  
 ![domepreview](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/e/e76deb3f0d63f47b6c56d412affb8943384779b9.jpeg)

the only way i can keep the lines i want is too filter out lines depending on the angle.do you think that is possible to find the correct lines and then meausure its angle?  
the image below shows what i want to do but in this image i filtered out the lines that aren’t the right angle…

 ![2022-11-12_145834](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/e/e828547acafeedd3b923ffa478af3527f412ed33.jpeg)

then i want to get the mean angle of the found lines. Is there any possibility for this to work?  
the colors in the image is a colorize filter so to see the found lines better. i use global shutter module for this project…

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [November 12, 2022, 4:24pm UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/7 "2022-11-12T16:24:34Z")

</div>

Use find line segments.

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [November 14, 2022, 3:25pm UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/8 "2022-11-14T15:25:46Z")

</div>

it seems that cant find lines at all with segments tool.  
If i try find\_line\_segments to original image can find lines but almost everywhere.  
But if i try to use it in the filtered image not even a single line…  
Do i miss something?  
The tool has only 2 parameters of filtering…  
do i have tro think a different approach of inspection?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [November 15, 2022, 2:49pm UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/9 "2022-11-15T14:49:35Z")

</div>

I guess find\_lines() is then the best for this.

Turn off all the joining features and you should get the results you want.

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [November 15, 2022, 3:26pm UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/10 "2022-11-15T15:26:59Z")

</div>

cant figured this out unfortunately.  
is there any feature of pattern matching so to teach a pattern and then get its rotation?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [November 15, 2022, 8:06pm UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/11 "2022-11-15T20:06:28Z")

</div>

So, for find\_lines… have you printed out the magnitude for the lines and tried displaying only the highest magnitude ones?

I think you almost have the solution with find\_lines(). You just need to filter by their strength.

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [November 17, 2022, 11:40am UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/12 "2022-11-17T11:40:46Z")

</div>

yeap,

thought that this will be an easy one but get find a way to make it work proper.  
i used a clear image to get this working but still nothing…

i am trying to do some filtering with all the find lines output …

![domepreview2](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/d/d3d4a4f511a21c58a3310ebc15327c8f60f274f4.jpeg)

```auto
min_degree = 0
max_degree = 180

min_length = 50
max_length = 5000

min_magnitude = 100
max_magnitude = 50000

```

```auto
line_list = img.find_lines(x_stride=1,y_stride=2,threshold = 500, theta_margin = 25, rho_margin = 25)
    for l in line_list:
        if (min_degree <= l.theta()) and (l.theta() <= max_degree):
            if (min_length <= l.length()) and (l.length() <= max_length):
                if (min_magnitude <= l.magnitude()) and (l.length() <= max_magnitude):

                   img.draw_line(l.line(), color = 100)

```

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [November 17, 2022, 11:46am UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/13 "2022-11-17T11:46:57Z")

</div>

today i have better results now with segments:  
 ![domepreview3](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/1/15ed16070944a0f0ed51d03ed84b480dd35e3e1b.jpeg)

```auto
min_degree = 0
max_degree = 180

min_length = 10
max_length = 5000

min_magnitude = 10
max_magnitude = 50000

```

```auto
line_list = img.find_line_segments(roi=(roi1),merge_distance = 2, max_theta_diff = 2)
    for l in line_list:
        if (min_degree <= l.theta()) and (l.theta() <= max_degree):
            if (min_length <= l.length()) and (l.length() <= max_length):
                if (min_magnitude <= l.magnitude()) and (l.length() <= max_magnitude):

                   img.draw_line(l.line(), color = 50)

```

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [November 18, 2022, 12:05pm UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/14 "2022-11-18T12:05:41Z")

</div>

how to store all the found lines and get the mean angle?  
the list contains all the lines that have export the tool.  
So i must store the found lines under the img.draw\_line(l.line(), color = 50) line.  
Then take the mean theta() value of them .

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [November 18, 2022, 2:28pm UTC](https://forums.openmv.io/t/finding-the-angle-between-horizontal-and-vertical-lines/7668/15 "2022-11-18T14:28:26Z")

</div>

This is just pure Python programming.
