Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removal of vertical HoughLines/Detection of Horizontal HoughLines only

I wish to ask if there is a method to detect only the nearly horizontal Hough Lines or ignoring those nearly vertical Hough Lines? My code for the HoughLine now is as shown:

HoughLinesP(imagec, lines, 80, CV_PI/2, CV_THRESH_OTSU|CV_THRESH_BINARY, 25, 7);
for(size_t i = 0; i < lines.size(); i++)
    {
      Vec4i l = lines[i];
      line(imagec, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(255,255,255), 8, 8);
      line(imagelines, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(255,255,255), 8, 8); //draw on black image as well
    }

However in the image, I am seeking only to detect horizontal lines, or at least near horizontal lines like by 2 to 4 cm. I am using CV_PI/2 for the theta parameter in the HoughLineP, hence the vertical lines/ near vertical lines are detected too.

Any suggestions, code samples, etc will be greatly appreciated. Thanks.

like image 974
rockinfresh Avatar asked Feb 03 '14 07:02

rockinfresh


People also ask

How do you get rid of vertical lines in Python?

One approach is to rotate the image 90 deg, then apply your same code, then rotate back 90 deg. Another approach is to change your horizontal kernel to a vertical kernel in your morphology.

How does Hough transform used for detecting straight lines?

The Hough transform takes a binary edge map as input and attempts to locate edges placed as straight lines. The idea of the Hough transform is, that every edge point in the edge map is transformed to all possible lines that could pass through that point.

What's the difference between HoughLines and HoughLinesP?

First of all, let's detect some lines, which is done with the HoughLines and HoughLinesP functions. The only difference between the two functions is that one uses the standard Hough transform, and the second uses the probabilistic Hough transform (hence P in the name).

What does HoughLines return?

HoughLines(). It simply returns an array of ( (\rho, \theta) values. \rho is measured in pixels and \theta is measured in radians. First parameter, Input image should be a binary image, so apply threshold or use canny edge detection before applying hough transform.


1 Answers

Python version

import numpy as np
angle = np.arctan2(y2 - y1, x2 - x1) * 180. / np.pi
like image 197
bl4ckb1rd Avatar answered Sep 26 '22 16:09

bl4ckb1rd