Ask Your Question

# How to calculate slope, length and distance between hough lines?

To detect lines from my image I used problabistic hough transform. I got 15 lines from my image. now I want to calculate slope, length of each line and to calculate distance between nearest lines? Can anyone suggest me ideas or share code? Thanks in advance

edit retag close merge delete

## 1 answer

Sort by » oldest newest most voted

really, this is not so much an opencv problem, but a maths one ..

houghlinesP already gives you the endpoints of the line,

Vec4i line = lines[i];
Point a(line, line);
Point b(line, line);


so

• the slope is dy/dx , or

float(b.y - a.y) / float(b.x - a.x);

• the length is the euclidean distance, or:

norm(a,b);

no idea, what you mean with the distance, try to explain ?

more

## Comments

In my image I got two parallel lines. Now I calculated slope and length of each line respectively. I want to calculate distance between these two parallel lines.

the distance is somewhat tricky. the link, @LBerger sent, assumes infinite lines, this probably won't work here.

by best guess, atm: take the shortest of the 4 point distances: a1,a2 a1,b2 b1,a2 b1,b2

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2017-05-08 06:12:42 -0500

Seen: 4,423 times

Last updated: May 08 '17